nx_bmp_header.nx
buildroot/runtime/nx_bmp_header.nx
about
bmp_header.nx -- parse Windows BMP/DIB image headers.
BMP is two concatenated structures:
1. BITMAPFILEHEADER (14 bytes, fixed):
0 2 bfType "BM" = 0x42 0x4D
2 4 bfSize total file size LE
6 2 bfReserved1
8 2 bfReserved2
10 4 bfOffBits offset of pixel data from file start
2. DIB header; the first u32 LE is its size, which discriminates:
12 = BITMAPCOREHEADER (OS/2 1.x)
40 = BITMAPINFOHEADER (Windows 3.0+, the common case)
52 = BITMAPV2INFOHEADER
56 = BITMAPV3INFOHEADER
108 = BITMAPV4HEADER
124 = BITMAPV5HEADER
We parse the BMP file header and the first two u32s of the DIB
(its size + width), plus the canonical BITMAPINFOHEADER fields
when size >= 40. Later DIB-version extensions are surfaced
only by their presence (size value).
Invariants:
B1 Magic "BM" (0x4D42 LE) required.
B2 dib_size must be one of the canonical sizes.
B3 Height may be negative in BITMAPINFOHEADER -- means top-down.
We surface raw signed value; caller picks orientation.
dependencies 1 imports · 0 importers
imports: nx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 42 | struct BmpHeader |
consts
| 38 | const BMP_ERR_FORMAT: i64 = -1 |
| 39 | const BMP_ERR_SHORT: i64 = -2 |
| 40 | const BMP_ERR_DIB: i64 = -3 |
functions
| 54 | func bmp_read_u16(buf: *u8, off: i64) -> i64 called by 1: bmp_parse_header |
| 58 | func bmp_read_u32(buf: *u8, off: i64) -> i64 |
| 67 | func bmp_read_i32(buf: *u8, off: i64) -> i64 |
| 76 | func bmp_dib_known(size: i64) -> i64 called by 1: bmp_parse_header |
| 86 | func bmp_parse_header(buf: *u8, n: i64, h: *BmpHeader) -> i64 |
| 118 | func main() -> i64 |