nx_ico_header.nx
buildroot/runtime/nx_ico_header.nx
about
ico_header.nx -- parse Windows ICO / CUR icon container headers.
ICO is a container for multiple icon images of different sizes
+ color depths. Every browser needs ICO parsing for favicon.ico.
Every Windows app ships one. Nishi sites need to emit and
detect their own.
Format:
ICONDIR (6 bytes, fixed)
0 2 reserved (0)
2 2 image_type (1 = ICO, 2 = CUR cursor)
4 2 num_images
then num_images × ICONDIRENTRY (16 bytes):
0 1 width (0 means 256)
1 1 height (0 means 256)
2 1 color_count (0 if >= 256 colors)
3 1 reserved (0)
4 2 planes (ICO) / hotspot_x (CUR)
6 2 bpp (ICO) / hotspot_y (CUR)
8 4 data_size
12 4 data_offset
Image payloads are then either:
- BMP without the BITMAPFILEHEADER (just DIB + pixel data),
OR
- complete PNG (detect via PNG signature)
Invariants:
I1 image_type must be 1 (ICO) or 2 (CUR).
I2 num_images >= 1.
I3 Zero-alloc: entries[] passes in by caller; we fill offsets.
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
| 49 | struct IcoEntry |
consts
| 41 | const ICO_MAGIC_1024: i64 = 1024 |
| 43 | const ICO_ERR_FORMAT: i64 = -1 |
| 44 | const ICO_ERR_SHORT: i64 = -2 |
| 46 | const ICO_TYPE_ICON: i64 = 1 |
| 47 | const ICO_TYPE_CURSOR: i64 = 2 |
functions
| 59 | func ico_read_u16(buf: *u8, off: i64) -> i64 called by 1: ico_parse |
| 63 | func ico_read_u32(buf: *u8, off: i64) -> i64 called by 1: ico_parse |
| 73 | func ico_parse(buf: *u8, n: i64, |
| 118 | func ico_is_png_payload(buf: *u8, n: i64, off: i64) -> i64 |
| 126 | func main() -> i64 |