png_header.nx
buildroot/runtime/png_header.nx
about
png_header.nx -- parse PNG signature + IHDR + chunk stream.
PNG (W3C PNG 2nd ed / ISO 15948):
- 8-byte signature: 0x89 'P' 'N' 'G' 0x0D 0x0A 0x1A 0x0A
- Series of chunks, each:
4-byte big-endian length
4-byte type tag (ASCII, case encodes flags)
<length> bytes data
4-byte CRC-32 over (type || data)
- First chunk must be IHDR (13-byte data payload).
- Must end with IEND (0-byte data).
IHDR layout:
width u32 BE
height u32 BE
bit_depth u8 (1/2/4/8/16)
color_type u8 (0 gray, 2 rgb, 3 indexed, 4 gray+alpha, 6 rgba)
compression u8 must be 0
filter u8 must be 0
interlace u8 0=none, 1=Adam7
Module does: sig-check, IHDR parse, chunk-walker (type tag +
offsets) without CRC validation. Callers handle CRC verification
once deflate.nx lands and full decode is viable.
Invariants:
P1 Signature bytes are exact.
P2 IHDR must be first; length must equal 13.
P3 Color-type + bit-depth combinations per W3C PNG table 5.12
are NOT validated here; caller decides.
dependencies 1 imports · 0 importers
imports: syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 38 | struct PngIhdr { |
consts
| 34 | const PNG_ERR_FORMAT: i64 = -1 |
| 35 | const PNG_ERR_SHORT: i64 = -2 |
| 36 | const PNG_ERR_IHDR: i64 = -3 |
functions
| 49 | func png_read_u32_be(buf: *u8, off: i64) -> i64 { |
| 58 | func png_check_sig(buf: *u8, n: i64) -> i64 {
called by 1: main |
| 73 | func png_parse_ihdr(buf: *u8, n: i64, out: *PngIhdr) -> i64 { |
| 98 | func png_next_chunk(buf: *u8, n: i64, cur_off: i64) -> i64 {
calls 1: png_read_u32_be |
| 107 | func png_chunk_type(buf: *u8, n: i64, off: i64, out: *u8) -> i64 { |
| 118 | func png_chunk_is(buf: *u8, n: i64, off: i64, |
| 129 | func main() -> i64 { |