nx_galx_thumb.nx
buildroot/runtime/nx_galx_thumb.nx
about
nx_galx_thumb.nx -- SOVEREIGN gallery THUMBNAIL generator. Composes the existing sovereign codecs
(nx_png_decoder = RFC2083 decode, nx_png = RGB8 encode) with an integer box-average downscale -- NO
ffmpeg / PIL / libpng. Produces a small thumbnail PNG (max dimension TH_MAX px) so the gallery grid
loads ~KB thumbs instead of ~MB full-res images. Output is CID-addressed under knowledge/store/galx-thumb/
so the daemon serves it at GET /thumb/<CID>.
MEMORY DISCIPLINE: nx_png_decode mmaps a 64MiB IDAT buffer per call and the toolchain has no sys_munmap,
so a single process MUST NOT decode many images. The batch mode therefore FORKS one child per image --
the kernel reclaims every mmap on child exit, bounding RSS regardless of corpus size (same sovereign
pattern as nx_galx_fill / nx_torrent_get).
modes:
nx_galx_thumb one <src.png> <out.png> -- thumbnail a single image (the gate path)
nx_galx_thumb batch <start> <count> -- walk knowledge/status/galx_cid_paths.tsv [start,start+count),
thumbnail each to galx-thumb/<CID>.png, idempotent (skip if present)
license_tier: ORIGINAL
dependencies 3 imports · 0 importers
imports: nx_syscalls.nxnx_png_decoder.nxnx_png.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 20 | const TH_MAGIC_65536: i64 = 65536 |
| 21 | const TH_MAGIC_1000000000: i64 = 1000000000 |
| 22 | const TH_MAGIC_1024: i64 = 1024 |
| 24 | const TH_MAX: i64 = 256 // max thumbnail dimension in px (data-driven cap, rule 11) |
| 25 | const TH_DIR: *u8 = "knowledge/store/galx-thumb" as *u8 |
functions
| 27 | func th_p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 28 | func th_n(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1}; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1}; var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1}; sys_write(1,b,k); return 0 } |
| 29 | func th_atoi(s: *u8) -> i64 { var v: i64=0; var i: i64=0; while s[i]!=(0 as u8){ if s[i]>=(48 as u8){ if s[i]<=(57 as u8){ v=v*10+((s[i]-(48 as u8)) as i64) } } i=i+1 } return v } called by 1: main |
| 30 | func th_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){dst[off+i]=s[i];i=i+1} return off+i } called by 1: main |
| 32 | func th_mkdir(path: *u8) -> i64 { return __syscall(258, 0-100, path as i64, 0x1ed, 0, 0, 0) } called by 1: main |
| 36 | func th_one(src: *u8, out: *u8) -> i64 |
| 112 | func th_exists(path: *u8) -> i64 |
| 119 | func main(argc: i64, argv: *i64) -> i64 |