Skip to content

std.png

rfc 2083 decode to RGBA8 and encode; all color types, depths, interlace, tRNS

pub PngError :: errors {
not_png,
corrupt,
unsupported,
too_big,
}
  • not_png: no PNG signature
  • corrupt: truncated chunk, bad CRC, or bad image data
  • unsupported: color type, depth or method not in the spec
  • too_big: past 2^28 pixels
pub Image :: struct {
width: u32,
height: u32,
pixels: []u8,
}

width * height RGBA pixels, 4 bytes each, rows top to bottom

pub at :: fn(self: *Self, x: u32, y: u32) -> u32

0,0 is top left; returns r | g << 8 | b << 16 | a << 24

pub image :: fn(a: *Arena, width: u32, height: u32) -> Image

all pixels transparent black; in a

pub decode :: fn(a: *Arena, data: []const u8) -> Image ! PngError

pixels in a

pub encode :: fn(a: *Arena, img: Image, level: u32) -> []const u8

file bytes in a; zlib level 0..9; RGB8 if all opaque, else RGBA8