code wiki / (root) / nx_png.nx

nx_png.nx

buildroot/runtime/nx_png.nx

16678 B340 linesdepth 3pulls 3 transitivereach 269 importersview sourcekind librarytopic png
docsdependenciesstructsconstsfunctions

about

nx_png.nx -- SOVEREIGN PNG (RGB8) encoder in NishiLang. No zlib/libpng/python: adaptive per-scanline FILTERING (None/Sub/Up/Avg/Paeth, min-abs-sum heuristic) + REAL DEFLATE compression (nx_deflate_enc, LZ77 + fixed Huffman) -- so renders ship compact + full-resolution. CRC32 (chunk) + Adler32 (zlib) pure integer. Upgraded 2026-07-04 from stored (uncompressed) blocks; same write_png() contract, valid PNG out, much smaller. license_tier: ORIGINAL

dependencies 2 imports · 190 importers

nx_syscalls.nx nx_deflate_enc.nx nx_png.nx _imgscramble.nx nx_aa_gate.nx nx_adnet_banner_gen.nx nx_anat_rig.nx nx_anat_sov.nx nx_anat_sov_clean.nx nx_anatstack_gate.nx nx_apng_decode.nx nx_arcade_hud_gate.nx nx_arcade_render.nx

diagram shows first 10 each side; +0 more imports, +180 more importers in the complete lists below.

imports: nx_syscalls.nxnx_deflate_enc.nx

imported by: _imgscramble.nxnx_aa_gate.nxnx_adnet_banner_gen.nxnx_anat_rig.nxnx_anat_sov.nxnx_anat_sov_clean.nxnx_anatstack_gate.nxnx_apng_decode.nxnx_arcade_hud_gate.nxnx_arcade_render.nxnx_articulate_gate.nxnx_assetvariant_gate.nxnx_authorgen_gate.nxnx_authorworld_gate.nxnx_avatar_splat.nxnx_ballistics_gate.nxnx_being_showcase.nxnx_body_figure_gate.nxnx_bodyatlas_explorer.nxnx_bodyatlas_gate.nxnx_bodyatlas_mesh_gate.nxnx_bodybind_gate.nxnx_boxtex_gate.nxnx_bunny_gate.nxnx_camera_anim_gate.nxnx_cast_gen.nxnx_cdmap_raster_lib.nxnx_chaos_gate.nxnx_char_custom_gate.nxnx_char_gen.nxnx_char_groom_gate.nxnx_char_layers_gate.nxnx_char_scene.nxnx_cornell_dyn_gate.nxnx_cornell_gate.nxnx_creaturegen_gate.nxnx_diversity_gate.nxnx_diversity_veg_gate.nxnx_donor_native.nxnx_eco_graph_forest.nxnx_eco_graph_png.nxnx_engine_lod_gate.nxnx_engine_phys_gate.nxnx_engine_scene_gate.nxnx_engine_stream_gate.nxnx_entity_gate.nxnx_face_carve_gate.nxnx_face_expr_gate.nxnx_face_project_gate.nxnx_face_r2.nxnx_face_style_gate.nxnx_face_support_capture_t239.nxnx_faceanat_gate.nxnx_faceanat_morph_gate.nxnx_faceanat_neutral_capture_t239.nxnx_faceanat_stereo_gate.nxnx_fbx_texm.nxnx_fluid_gate.nxnx_footplant_gate.nxnx_fpga_cpu_dc_gate.nxnx_fpga_dc_gate.nxnx_fpsworld_gate.nxnx_galx_thumb.nxnx_galx_upscale.nxnx_game_adventure_gate.nxnx_game_audio_gate.nxnx_game_city_gate.nxnx_game_display_gate.nxnx_game_loop_gate.nxnx_game_pong_gate.nxnx_game_racing_gate.nxnx_game_rts_gate.nxnx_game_sandbox_gate.nxnx_game_scaffold.nxnx_game_scaffold_gate.nxnx_game_shmup_gate.nxnx_game_tbs_gate.nxnx_game_td_gate.nxnx_game_thirdperson_gate.nxnx_game_tycoon_gate.nxnx_gassim_gate.nxnx_gen_explorer.nxnx_gen_gate.nxnx_genloop_gate.nxnx_gfx_bloom_gate.nxnx_gfx_iso_scene_gate.nxnx_gfx_scene_tex_gate.nxnx_gfx_tex_gate.nxnx_gi_gate.nxnx_gltf_load_gate.nxnx_gop_efi_gate.nxnx_gop_present_gate.nxnx_gsplat4d_gate.nxnx_gsplat_aniso_gate.nxnx_gsplat_elara_gate.nxnx_gsplat_face_gate.nxnx_gsplat_gate.nxnx_gsplat_optimize_gate.nxnx_gsplat_photofit_gate.nxnx_gsplat_showcase.nx +90 more (shown cap 100 declared)

structs

none

consts

8const PNG_ZLIB_HDR_BYTES: i64 = 2 // 0x78 0x01
9const PNG_ADLER_BYTES: i64 = 4 // adler32 trailer of the zlib stream
10const K_MAGIC_65521: i64 = 65521
11const K_MAGIC_65536: i64 = 65536
16const PNG_DEFLATE_RESERVE_BYTES: i64 = 128
17const PNG_DEFLATE_EXPAND_DIV: i64 = 2 // + rawlen/2 headroom for an incompressible worst case
216const PNG_MODE_0644: i64 = 0x1a4
219const PNG_ANN_FD: i64 = 1
221const PNG_I64_MAX_DIGITS: i64 = 19
223const PNG_SIG_BYTES: i64 = 8 // 137 P N G CR LF SUB LF
224const PNG_IHDR_CHUNK_BYTES: i64 = 25 // 4 length + 4 type + 13 data + 4 crc
225const PNG_CHUNK_FRAME_BYTES: i64 = 12 // 4 length + 4 type + 4 crc -- once for IDAT, once for IEND
228const PNG_ERR_SHORT_WRITE: i64 = 1001
229const PNG_ERR_NOT_ON_DISK: i64 = 1002

functions

19func png_crc32(buf: *u8, off: i64, len: i64) -> i64
34func png_adler32(buf: *u8, off: i64, len: i64) -> i64
45func png_be32(b: *u8, o: i64, v: i64) -> i64
52func png_paeth(a: i64, b: i64, c: i64) -> i64 { // a=left b=up c=upleft
64func png_sabs(v: i64) -> i64 { var x: i64 = v & 0xff; if x > 127 { x = 256 - x } return x }
65func png_g(img: *u8, w3: i64, r: i64, j: i64) -> i64 { // safe fetch, 0 outside bounds
74func png_chunk_length_valid(n:i64)->i64 { return n>=0 && n<=2147483647 }
76func write_png_buf_checked(fb: *i64, fb_pixels:i64, w: i64, h: i64, out: *u8, capacity:i64) -> i64
177func write_png_buf(fb:*i64,w:i64,h:i64,out:*u8)->i64
231func pngw_emit(s: *u8) -> i64
called by 1: png_publish calls 1: sys_write
237func pngw_num(v: i64) -> i64
called by 1: png_publish calls 2: sys_mmapsys_write
255func png_buf_cap(w:i64,h:i64)->i64
271func png_publish(fb: *i64, w: i64, h: i64, path: *u8, ann: i64) -> i64
329func png_publish_announced(fb: *i64, w: i64, h: i64, path: *u8) -> i64
called by 1: main calls 1: png_publish
336func write_png(fb: *i64, w: i64, h: i64, path: *u8) -> i64
called by 144: mainmainabg_emitmainmainmain+138 calls 1: png_publish