Image module

decode_png

procedureextensionsince 0.28.0Source

Decodes a PNG to GRAY8, GRAY_ALPHA8, RGB8 or RGBA8. Palettes are expanded, transparency is kept as alpha, and 16-bit samples keep their high byte. Interlaced files work; gamma and colour profiles are ignored; of an animated PNG only the first image is read.

Example↗
png := encode_png(make_image(5, 3, .GRAY_ALPHA8));
defer free(png.data);

image, ok, error := decode_png(png);
defer deinit(*image);
assert(ok && image.format == .GRAY_ALPHA8 && image.height == 3);
decode_png :: (
    data: [] u8,
    max_pixels: s64 = DEFAULT_MAX_PIXELS
) -> (image: Image, ok: bool, error: string)

Parameters

data: [] u8
max_pixels: s64 = DEFAULT_MAX_PIXELS

Returns

image: Image
ok: bool
error: string

See also