nx_pcx_decode.nx
buildroot/runtime/nx_pcx_decode.nx
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
imports: nx_syscalls.nx
imported by: nx_img_bytes_to_rgb.nxnx_legacy_codec_gate.nx
structs
| none |
consts
| 24 | const NX_PCX_HDR: i64 = 128 |
| 25 | const NX_PCX_PAL: i64 = 769 |
functions
| 27 | func pcx_b(d: *u8, o: i64) -> i64 { return (d[o] as i64) & 255 } |
| 28 | func pcx_u16(d: *u8, o: i64) -> i64 { return pcx_b(d,o) | (pcx_b(d,o+1) << 8) } |
| 32 | func pcx_row(raw: *u8, n: i64, sp0: i64, total: i64, row: *u8) -> i64 |
| 56 | func pcx_decode_rgb(raw: *u8, n: i64, out_wh: *i64) -> *u8 |