Image module

decode_jpeg

procedureextensionsince 0.28.0Source

Decodes a baseline, extended sequential or progressive JPEG with 8-bit samples. Grayscale, YCbCr, RGB, CMYK and YCCK images work. Arithmetic coding and 12-bit samples are refused. Damaged data never reads out of bounds; a file cut off inside the pixel data still decodes, with the missing blocks grey.

Example↗
#import "File";

file, found := read_entire_file("photo.jpg");
image, ok, error := decode_jpeg(cast([] u8) file, DEFAULT_MAX_PIXELS);

This one is only checked to compile, not run.

decode_jpeg :: (
    data: [] u8,
    max_pixels: s64
) -> (image: Image, ok: bool, error: string)

Parameters

data: [] u8
max_pixels: s64

Returns

image: Image
ok: bool
error: string

See also