This document defines the exact .csl behavior currently implemented in this repository.
| Offset | Type | Field | Value |
|---|---|---|---|
| 0x00 | u8[3] |
Magic | "CSL" |
| 0x03 | u8 |
Version | 0x20, 0x21, or 0x22 |
| 0x04 | u16 LE |
Width | 1..=65535 |
| 0x06 | u16 LE |
Height | 1..=65535 |
| Offset | Type | Field | Value |
|---|---|---|---|
| 0x00 | u8[3] |
Magic | "CSL" |
| 0x03 | u8 |
Version | 0x23 |
| 0x04 | u16 LE |
Width | 1..=65535 |
| 0x06 | u16 LE |
Height | 1..=65535 |
| 0x08 | u8 |
Flags | See below |
| 0x09 | u32 LE |
CRC32 | IEEE CRC32 of payload |
V2.3 Flags:
- Bit 0 (
0x01): Scanline traversal (1 = scanline, 0 = Morton) - Bit 1 (
0x02): Grayscale mode (1 = grayscale) - Bit 2 (
0x04): YCoCg transform (1 = YCoCg)
Initial state:
x = 0,y = 0current_alpha = 255color_cache = [[0,0,0,0]; 64]
Cache policy:
- 64-slot RGBA hash cache: slot =
(r*3 + g*5 + b*7 + a*11) % 64. - Cache updates on most pixel-drawing opcodes.
The currently active encode/decode paths use:
0x40..=0x7F: cache draw (V2.1+)0x80..=0x9F: cache draw (V2.0)0xA0..=0xBF: short solid RGB run (len=1..32)0xC0..=0xCF: literal RGB run (len=1..16)0xD0..=0xDF: literal RGB run (V2.3)0xE4..=0xEB: literal RGBA run (len=1..8)0xED: residual pixel (Paeth-based)0xF0: extended solid RGB run0xF1: repeat last pixel run0xF2: transparent pixel run (V2.2+)0xF3: LZ back-reference0xF5: transparent rectangle skip (V2.2+)0xFF: alpha setter
Bitstream framing is prefix-based and bit-packed.
Decoding fails on any of:
- Invalid magic or unsupported version byte
- Payload underflow
- Invalid or reserved opcode
- Violated preconditions
- CRC32 checksum mismatch (V2.3 only)
The encoder is lossless and uses a cost-aware greedy pipeline:
- RGBA literal runs for unstable alpha windows.
- Alpha synchronization (
0xFF) for RGB-coded paths. - LZ candidate with rolling hash (constrained to fixed-alpha spans).
- RGB literal runs with short lookahead chooser.
- Solid runs (
0xA0..0xBF,0xF0). - Repeat runs (
0xF1). - Fallback RGB literal or residual path.