local libpng = require'libpng'
A ffi binding of the ubiquitous libpng.
libpng.load(t) -> image
Read and decode a PNG image.
t
is a table specifying:
path
: read data from a file given its filenamestring
: read data from a stringcdata
, size
: read data from a buffer of specified sizestream
: read data from an opened FILE *
streamread
: read data from a reader function of form:read(needed_size) -> cdata, size | string | nil
needed_size
is informative, the function can return however many bytes it wants, as long as it returns at least 1 byte.accept
: if present, it is a table specifying conversion options. libpng implements many of the pixel conversions itself, while other conversions are supported through [bmpconv bmpconv.convert_best()]. If no accept
option is given, the image is returned in a normalize 8 bit per channel, top down, palette expanded, 'g', 'rgb', 'rgba' or 'ga' format.[pixel_format] = true
- specify one or more accepted pixel formats (they are all implicitly 8 bit per channel since that is the only supported bit depth):
[orientation] = true
- specify one or more accepted orientations:
padded
: true/false (default is false) - specify that the row stride should be a multiple of 4header_only
: do not decompress the image; return only the image header fields.sparkle
: true/false (default is false) - alternative render mode for interlaced images.warning
: a function to be called as warning(msg)
on non-fatal errors.render_scan
: a function to be called as render_scan(image, is_last_scan, scan_number)
for each pass of an interlaced PNG. It can be used to implement progressive display of images.render_scan(nil, true, scan_number, error)
, where scan_number
is the scan number that was supposed to be rendering next and error
the error message.For more info on decoding process and options, read the libpng doc (have coffee/ibuprofen ready).
The returned image object is a table with the fields: * pixel
, orientation
, stride
, data
, size
, w
, h
: image format and dimensions and pixel data. * file.pixel
, file.paletted
, file.bit_depth
, file.interlaced
, file.w
, file.h
: format of the original image before conversion.