Image module

decode_image

procedureextensionsince 0.28.0Source

Decodes a PNG, JPEG, QOI, BMP or PNM file into the nearest pixel format to the one it's stored in. Returns the image, whether it worked and, if not, why. Files with more than max_pixels pixels are refused before anything is allocated.

Example↗
qoi := encode_qoi(make_image(4, 4, .RGB8));
defer free(qoi.data);

image, ok, error := decode_image(qoi);
defer deinit(*image);
assert(ok && image.format == .RGB8);

_, ok, error = decode_image(cast([] u8) "not an image");
assert(!ok);
decode_image :: (
    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