code wiki / _hdl_build / nx_zpng.nx
nx_zpng.nx
buildroot/runtime/_hdl_build/nx_zpng.nx
about
nx_zpng.nx -- a COMPRESSING sovereign PNG encoder (the unblocker for shipping generated art at size). Replaces
nx_png's STORED (uncompressed ~3B/px) zlib body with a real DEFLATE: PNG "Sub" row filter (flat horizontal
spans -> 0x00) + fixed-Huffman blocks + LZ77 RLE (dist=1 back-refs collapse the 0-runs). Reuses nx_png's proven
CRC32/Adler32/be32 + PNG framing. Output is standard zlib/DEFLATE -> any browser decodes it. No zlib/libpng.
Our generated images (gradients + flat fills) compress massively. license_tier: ORIGINAL
dependencies 2 imports · 2 importers
imports: nx_png.nxnx_syscalls.nx
imported by: nx_char_scene.nxnx_zpng_test.nx
structs
| none |
consts
| 8 | const K_MAGIC_1024: i64 = 1024 |
functions
| 11 | func zp_putbit(z: *u8, st: *i64, b: i64) -> i64 |
| 16 | func zp_lsb(z: *u8, st: *i64, val: i64, n: i64) -> i64 { var i: i64 = 0; while i < n { zp_putbit(z, st, (val >> i) & 1); i = i + 1 } return 0 } // extra bits / header (LSB first) |
| 17 | func zp_huff(z: *u8, st: *i64, code: i64, n: i64) -> i64 { var i: i64 = n - 1; while i >= 0 { zp_putbit(z, st, (code >> i) & 1); i = i - 1 } return 0 } // Huffman codes (MSB first) |
| 18 | func zp_flush(z: *u8, st: *i64) -> i64 { if st[2] > 0 { z[st[0]] = (st[1] & 255) as u8; st[0] = st[0] + 1; st[1] = 0; st[2] = 0 } return 0 } called by 1: zp_deflate |
| 21 | func zp_sym(z: *u8, st: *i64, s: i64) -> i64 |
| 29 | func zp_lencode(len: i64, out: *i64) -> i64 called by 1: zp_match1 |
| 39 | func zp_match1(z: *u8, st: *i64, len: i64, lc: *i64) -> i64 |
| 43 | func zp_deflate(raw: *u8, rawlen: i64, z: *u8, st: *i64) -> i64 |
| 63 | func write_png_z(fb: *i64, w: i64, h: i64, path: *u8) -> i64 |