Manuscript Documentation
v2026.12.0

@std/image/ppm.ms#

Import each required symbol with import Name from "@std/image/ppm.ms".

decode_ppm Function#

Decodes binary PGM (P5) or PPM (P6) into a gray or RGB raster. A maxval up to 65535 is accepted, and samples are scaled to 8 bits. Malformed data returns EBADMSG, and dimensions past max_pixels or the hard ceiling return EOVERFLOW. Data that does not start with P5 or P6 returns EBADMSG.

Manuscript
fn decode_ppm(data Bytes, max_pixels Int? = null) Result[Raster, Error] { ... }

encode_ppm Function#

Encodes gray or RGB pixels as 8-bit binary P5 or P6. Pixels with alpha (an even channels) return EINVAL.

Manuscript
fn encode_ppm(width Int, height Int, channels Int, pixels List[UInt8]) Result[Bytes, Error] { ... }