ppm_writer.nx
buildroot/runtime/ppm_writer.nx
about
ppm_writer.nx -- serialise Netpbm images (PBM / PGM / PPM).
The Netpbm family is the simplest lossless image format alive:
ASCII magic + dimensions + max-value + raw binary pixels. Used
as a debug output target by virtually every graphics engine
during bring-up (ImageMagick, pixman, cairo, mesa) precisely
because you can emit it with printf.
Magic codes:
P1 ASCII PBM 1-bit bitmap (0/1)
P2 ASCII PGM grayscale
P3 ASCII PPM RGB
P4 binary PBM
P5 binary PGM
P6 binary PPM
We emit P5 (binary grayscale) + P6 (binary RGB) -- the two
forms useful for rendering output. ASCII forms are larger and
slower. Binary PBM (P4) packs 8 pixels per byte and is
rarely worth the complexity.
Use cases: Nishi game engine screenshot dump, procgen debug
visualisations, DDS/PNG precursor, comparing frame buffers
byte-exact in regression tests.
Invariants:
P1 Header is plain ASCII, LF-terminated fields.
P2 max_value literal: we hardcode 255 (8-bit per channel).
P3 Binary pixel block: P5 width*height bytes, P6
width*height*3 bytes, row-major, top-to-bottom.
dependencies 1 imports · 0 importers
imports: syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 34 | const PPM_ERR_SHORT: i64 = -1 |
functions
| 37 | func pwr_put(out: *u8, off: i64, b: i64) -> i64 { |
| 44 | func pwr_put_dec(out: *u8, off: i64, v: i64) -> i64 { |
| 71 | func ppm_write_p6_header(out: *u8, cap: i64, width: i64, height: i64) -> i64 { |
| 90 | func ppm_write_p5_header(out: *u8, cap: i64, width: i64, height: i64) -> i64 { |
| 111 | func ppm_write_p6(out: *u8, cap: i64, width: i64, height: i64, |
| 127 | func main() -> i64 {
calls 1: ppm_write_p6 |