code wiki / (root) / jpeg_header.nx

jpeg_header.nx

buildroot/runtime/jpeg_header.nx

5570 B156 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tooltopic jpeg
docsdependenciesstructsconstsfunctions

about

jpeg_header.nx -- parse JPEG JFIF markers enough to extract width + height + component count without decoding the scan. JPEG streams are a sequence of markers, each: - 0xFF prefix byte (occasionally padded with more 0xFFs) - 1 marker byte - For most markers: 2-byte big-endian length (includes its own 2 bytes) + (length-2) bytes of data. - SOI (0xD8) and EOI (0xD9) and RSTn have no length. The markers we care about: 0xD8 SOI start of image (must be first) 0xE0 APP0 JFIF identifier, density info 0xE1 APP1 often EXIF 0xC0..0xCF SOF start of frame -- contains width + height + component count. 0xC4 is DHT, 0xC8 is reserved, 0xCC is DAC -- these are NOT SOF even though they're in the range; we skip. 0xDA SOS start of scan -- data follows; we stop here. 0xD9 EOI end of image. SOF data layout: 1 byte precision (bits per sample, typically 8) 2 bytes height (BE) 2 bytes width (BE) 1 byte num_components (1 grayscale, 3 YCbCr, 4 CMYK) Invariants: J1 First two bytes must be 0xFF 0xD8 (SOI). J2 Parser advances until it finds a SOF marker; returns its decoded dims. If SOS is hit first we return ERR_NOSOF (malformed file / truncated header). J3 We ignore restart markers (0xD0..0xD7) which have no length field.

dependencies 1 imports · 0 importers

syscalls.nx jpeg_header.nx

imports: syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main jpeg_parse_header jpeg_no_length jpeg_read_u16_be jpeg_is_sof

structs

42struct JpegInfo {

consts

38const JPEG_ERR_FORMAT: i64 = -1
39const JPEG_ERR_SHORT: i64 = -2
40const JPEG_ERR_NOSOF: i64 = -3

functions

49func jpeg_read_u16_be(buf: *u8, off: i64) -> i64 {
called by 1: jpeg_parse_header
55func jpeg_is_sof(m: i64) -> i64 {
called by 1: jpeg_parse_header
65func jpeg_no_length(m: i64) -> i64 {
called by 1: jpeg_parse_header
76func jpeg_parse_header(buf: *u8, n: i64, info: *JpegInfo) -> i64 {
125func main() -> i64 {