code wiki / _hdl_build / nx_zpng.nx

nx_zpng.nx

buildroot/runtime/_hdl_build/nx_zpng.nx

6110 B113 linesdepth 4pulls 4 transitivereach 2 importersview sourcekind library
docsdependenciesstructsconstsfunctions

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

nx_png.nx nx_syscalls.nx nx_zpng.nx nx_char_scene.nx nx_zpng_test.nx

imports: nx_png.nxnx_syscalls.nx

imported by: nx_char_scene.nxnx_zpng_test.nx

structs

none

consts

8const K_MAGIC_1024: i64 = 1024

functions

11func zp_putbit(z: *u8, st: *i64, b: i64) -> i64
called by 2: zp_lsbzp_huff
16func 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)
called by 2: zp_match1zp_deflate calls 1: zp_putbit
17func 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)
called by 2: zp_symzp_match1 calls 1: zp_putbit
18func 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
21func zp_sym(z: *u8, st: *i64, s: i64) -> i64
called by 2: zp_match1zp_deflate calls 1: zp_huff
29func zp_lencode(len: i64, out: *i64) -> i64
called by 1: zp_match1
39func zp_match1(z: *u8, st: *i64, len: i64, lc: *i64) -> i64
43func zp_deflate(raw: *u8, rawlen: i64, z: *u8, st: *i64) -> i64
63func write_png_z(fb: *i64, w: i64, h: i64, path: *u8) -> i64