NVGIF v5 Specification

1. Header Layout

Each NVGIF v5 file begins with a fixed header:

Field Size (bytes) Description
Magic 3 ASCII "NVG"
Version 1 Format version (0x05 for v5)
Compression 1 Bitfield of compression flags
Alpha 1 0 = disabled, 1 = enabled
Width 2 Image width (big‑endian)
Height 2 Image height (big‑endian)
Reserved 1 Always 0
Payload variable Encoded pixel data

2. Compression Flags

The Compression byte is a bitmask:

Flag Value Meaning
None 0 No compression
RLE 1 Run‑length encoding
Zlib 2 zlib compression
RGB565 4 Lossy RGB565 encoding (no alpha)

Multiple flags may be combined using bitwise or (e.g. RLE | Zlib).


3. Payload Encoding

3.1 Raw RGB/RGBA

3.2 RGB565 (Lossy)

3.3 RLE

3.4 ZLIB


4. Decoding Order

  1. Read header.
  2. If ZLIB flag set → decompress payload.
  3. If RLE flag set → expand payload.
  4. Parse rows:
    • If RGB565 flag set → decode 16‑bit pixels.
    • Else → read raw RGB/RGBA rows.
  5. Construct image with dimensions and alpha mode.

5. Notes


6. Example

Encoding a 2×2 RGBA image with RLE+ZLIB:

 Header: 4E 56 47 05 03 01 00 02 02 00 
Payload: [zlib-compressed RLE stream of row data]