code wiki / (root) / nx_ppm_writer.nx

nx_ppm_writer.nx

buildroot/runtime/nx_ppm_writer.nx

5126 B157 linesdepth 2pulls 2 transitivereach 9 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 · 3 importers

nx_syscalls.nx nx_ppm_writer.nx nx_scene_render.nx nx_swapchain.nx nx_x11_screenshot.nx

imports: nx_syscalls.nx

imported by: nx_scene_render.nxnx_swapchain.nxnx_x11_screenshot.nx

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

main sys_mmap ppm_write_p6 ppm_write_p6_header pwr_put pwr_put_dec sys_mmap ↻

structs

none

consts

40const PPM_ERR_SHORT: i64 = -1

functions

43func pwr_put(out: *u8, off: i64, b: i64) -> i64
50func pwr_put_dec(out: *u8, off: i64, v: i64) -> i64
77func 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
96func ppm_write_p5_header(out: *u8, cap: i64, width: i64, height: i64) -> i64
117func ppm_write_p6(out: *u8, cap: i64, width: i64, height: i64,
133func main() -> i64