code wiki / (root) / nx_pcx_decode.nx

nx_pcx_decode.nx

buildroot/runtime/nx_pcx_decode.nx

4725 B132 linesdepth 2pulls 2 transitivereach 37 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_pcx_decode.nx -- ZSoft PCX reader (PC Paintbrush; the DOS-era standard). THE RLE IS PER-SCANLINE, NOT PER-IMAGE. A run may not cross a scanline boundary, and a decoder that treats the stream as one flat run-length sequence will still produce a plausible image on most files and shear on the ones that pad. We decode exactly nplanes*bytes_per_line per row and stop, which is also what makes a malformed row detectable. PLANES ARE SEPARATE, NOT INTERLEAVED. 24-bit PCX stores a whole row of R, then a whole row of G, then B -- not RGB triples. The same row buffer is therefore indexed plane*bytes_per_line + x, which is the one addressing mistake that yields a recognisable-but-colour-smeared image. 8-bit palette lives at the END of the file: the last 769 bytes, introduced by a 0x0C marker byte. Its absence on a 1-plane 8-bit file is a refusal, not a reason to invent a grayscale ramp. genealogy_id: zsoft_pcx_5 lineage_id: nx_pcx_v1 license_tier: ORIGINAL

dependencies 1 imports · 2 importers

nx_syscalls.nx nx_pcx_decode.nx nx_img_bytes_to_rgb.nx nx_legacy_codec_gate.nx

imports: nx_syscalls.nx

imported by: nx_img_bytes_to_rgb.nxnx_legacy_codec_gate.nx

structs

none

consts

24const NX_PCX_HDR: i64 = 128
25const NX_PCX_PAL: i64 = 769

functions

27func pcx_b(d: *u8, o: i64) -> i64 { return (d[o] as i64) & 255 }
28func pcx_u16(d: *u8, o: i64) -> i64 { return pcx_b(d,o) | (pcx_b(d,o+1) << 8) }
called by 1: pcx_decode_rgb calls 1: pcx_b
32func pcx_row(raw: *u8, n: i64, sp0: i64, total: i64, row: *u8) -> i64
called by 1: pcx_decode_rgb calls 1: pcx_b
56func pcx_decode_rgb(raw: *u8, n: i64, out_wh: *i64) -> *u8