📄 NVGIFv4 Specification
← Back to Specifications
| Offset (bytes) |
Length (bytes) |
Field |
Description |
| 0 |
3 |
Magic |
ASCII "NVG" |
| 3 |
1 |
Version |
0x04 for NVGIFv4 |
| 4 |
1 |
Compression |
Compression type (see below) |
| 5 |
1 |
Alpha |
0 = off (RGB), 1 = on (RGBA) |
| 6 |
2 |
Width |
Unsigned big-endian 16-bit integer |
| 8 |
2 |
Height |
Unsigned big-endian 16-bit integer |
| 10 |
1 |
Reserved |
Always 0x00 in v4 |
💾 Compression Types (byte 4)
| Value |
Name |
Description |
| 0 |
None |
Raw row data, length-prefixed per row |
| 1 |
RLE |
Run-Length Encoded rows, each prefixed with 2-byte length |
| 2 |
Zlib |
Entire image buffer compressed with zlib.compress() |
| 3 |
RLE+Zlib |
Each row RLE-encoded and length-prefixed, then full buffer zlib-compressed |
🎨 Pixel Data
- If alpha flag =
0, pixels are RGB (3 bytes)
- If alpha flag =
1, pixels are RGBA (4 bytes)
🧱 Payload Encoding
Compression 0 (None)
- For each row:
- 2-byte big-endian length
- Raw RGB(A) pixel data
Compression 1 (RLE)
- For each row:
- 2-byte big-endian length
- RLE-encoded
[count][pixel] sequences
Compression 2 (Zlib)
- One
zlib block covering entire image
- Must decompress to
width × height × bytes_per_pixel
Compression 3 (RLE + Zlib)
- Each row:
- Apply RLE → prefix with 2-byte length
- Concatenate all rows
- Compress entire buffer with
zlib.compress()
🔄 Decoding Logic (Summary)
- Read and validate magic bytes and version
- Parse compression, alpha, dimensions
- Decompress payload based on
compression
- Build final buffer (RGB or RGBA)
- Return usable image (e.g. via Pillow)
🚀 Notes
- Reserved byte may be used in NVGIFv5+ (e.g. for metadata blocks, frame counts)
- All values use big-endian encoding
- Row-level structure ensures decode resilience and streaming potential
- Zlib-RLE offers compact storage with efficient decode speed
4E 56 47 04 03 00 00 C8 00 C8 00
"NVG" (4E 56 47)
- version 04
- compression =
03 (RLE+Zlib)
- alpha =
00 (RGB)
- width =
200 (00 C8), height = 200 (00 C8)
- reserved =
0
🧃 This Spec Supports
- Transparent images (alpha channel)
- Choice of compression tradeoffs
- Resilience to partial corruption (per-row formats)
- Competitive size vs. PNG with
rlezlib mode