veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

image/png

lib/image/png.vk

lib/image/png.vk Pure-Veko RFC 2083 Portable Network Graphics (PNG) RGBA32 encoder and decoder. Uses compress/deflate (RFC 1950 zlib) and bits/crc32 with adaptive scanline filtering. Zero capabilities required; works identically on VM, Wasm 3.0, and Native.

PngImage struct
signature
PngImage = struct { width i64, height i64, pixels bytes }

Decoded RGBA32 PNG image surface (width * height * 4 bytes, top-down).

signature
encode-rgba = fn [rgba bytes, w i64, h i64] bytes

Encodes a top-down RGBA32 byte buffer (w * h * 4 bytes) into an RFC 2083 PNG byte stream. Uses adaptive per-row filtering (None, Sub, Up) for compact UI screenshot compression.

Executable Example
veko
use [png = image/png, cv = ui/canvas]
mut c = cv/new-canvas 16 12
cv/clear mut c (cv/rgb 248 250 252)
cv/fill-rect mut c 2 2 8 6 (cv/rgb 2 132 199)
raw_png = png/encode c
dec = png/decode raw_png
p0 = cv/get-pixel dec 0 0
p1 = cv/get-pixel dec 4 4
if dec.width != 16 or dec.height != 12 or p0.r != 248 or p1.b != 199 [ err 'png roundtrip' ] else [ .ok ]
signature
encode = fn [c cv/Canvas] bytes

Encodes a ui/canvas Canvas directly into PNG bytes.

signature
decode-rgba = fn [png_bytes bytes] PngImage

Decodes an RFC 2083 8-bit PNG byte stream (Grayscale, RGB, Grayscale+Alpha, or RGBA; non-interlaced; all 5 scanline filters 0..4) into a top-down RGBA32 PngImage.

signature
decode = fn [png_bytes bytes] cv/Canvas

Decodes a PNG byte stream directly into a ui/canvas Canvas.