code wiki / (root) / ppm_writer.nx

ppm_writer.nx

buildroot/runtime/ppm_writer.nx

5023 B151 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tooltopic ppm
docsdependenciesstructsconstsfunctions

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

syscalls.nx ppm_writer.nx

imports: syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main ppm_write_p6 ppm_write_p6_header pwr_put pwr_put_dec

structs

none

consts

34const PPM_ERR_SHORT: i64 = -1

functions

37func pwr_put(out: *u8, off: i64, b: i64) -> i64 {
44func pwr_put_dec(out: *u8, off: i64, v: i64) -> i64 {
71func ppm_write_p6_header(out: *u8, cap: i64, width: i64, height: i64) -> i64 {
called by 1: ppm_write_p6 calls 2: pwr_putpwr_put_dec
90func ppm_write_p5_header(out: *u8, cap: i64, width: i64, height: i64) -> i64 {
111func ppm_write_p6(out: *u8, cap: i64, width: i64, height: i64,
called by 1: main calls 1: ppm_write_p6_header
127func main() -> i64 {
calls 1: ppm_write_p6