IMAG / GAMI — bitmap images
IMAG / GAMI — bitmap images
Section titled “IMAG / GAMI — bitmap images”Backgrounds, sprites, portraits, maps and UI art in all five games are
IMAG resources (Amiga, big-endian) or GAMI (DOS and Apple IIGS,
little-endian — the same FourCC byte-reversed). They live inside a
resource fork.
Read the codec from the resource map, and detect the header. For WIME, Spirit and Vengeance the
attributesbyte names the codec (bit 0 RLE, bit 7 LZSS, neither raw, with no size prefix); guessing it from the output picks wrong at least once. In front of the pixels sits a 28-, 27- or 6-byte header depending on the game. The pixels are Amiga interleaved bitplanes everywhere except the IIGS and DOS EGA ports, which store the same 16-colour art as packed nibbles.
Container
Section titled “Container”+0x00 u32 decompressedSize native endianness+0x04 ... compressedStream to the end of the resourceThe codec is chosen per resource by the resource-map attributes
byte, exactly as the Excal-family loader _LoadResource does
(Excal.asm:50645-50647, 50721-50739; Vengeance’s ExcalII.asm carries
the same routines):
attributes |
Codec | Payload |
|---|---|---|
| bit 0 set | RLE (_RLDecode, PackBits below) |
u32 size prefix + stream |
| bit 7 set, bit 0 clear | LZSS (_LZSSDecode) |
u32 size prefix + stream |
| neither | stored raw | the bare payload, no size prefix |
This project’s decoders take the byte (decompressByAttributes,
src/assets/formats/res-codec.ts) for War in Middle Earth, Spirit and
Vengeance. Checked on every resource of every platform present (WIME
Amiga, DOS VGA, DOS EGA, IIGS; Spirit Amiga, CDTV, DOS; Vengeance Amiga
and DOS VGA): the set bit always names the one codec whose output equals
the size prefix, and no resource sets both. Conan and Warriors of Legend
are not on this path: their attribute bytes have not been audited, so
they keep the older heuristic below.
Correction (2026-11-30). This page used to say the decoder “tries PackBits first and falls back to LZSS when the output doesn’t match the declared size”. That heuristic was a stand-in for the attribute rule, and it is now only the Conan/Legend fallback. Forcing the other codec still reproduces the declared size on 1 of 4,593 compressed IMAG/FRML/MMAP/CHAR resources (Vengeance
RES16/INTF16.RESGAMI #833, 342 bytes), where the old heuristic picked the wrong codec: its pixel mask agrees with theRES32sibling’s on 377 of 630 pixels against 630 of 630 for the attribute codec (null control 272 of 630). A regression over 4,238 image and 474 animation decodes changed 2 images and 0 animations, and fixed 13 terrain grids (MMAP/PAMM) that had been decoded with PackBits over an LZSS stream. The Spirit/VengeanceMMAPis LZSS, not PackBits.
PackBits (the game’s _RLDecode), Apple’s run-length scheme with one
difference:
Control byte n |
Meaning |
|---|---|
0x00–0x7F |
Copy the next n + 1 bytes literally |
0x80 |
Repeat the next byte 129 times |
0x81–0xFF |
Repeat the next byte 257 − n times (2–128 reps) |
Correction:
0x80was listed here as a no-op, as in classic PackBits. In_RLDecodeit repeats the next byte 129 times: the routine’sNEG.Bgives 128 and itsDBFloop runs once more (Excal.asm:50942). No Spirit or Vengeance stream contains0x80, so this is taken from the code, not observed in data.
LZSS (_LZSSDecode): byte-aligned, with 8-bit flag bytes (LSB first).
A 1 flag bit means “copy the next literal byte”; a 0 means a 2-byte
little-endian match token whose top 10 bits are the back-reference offset
and whose bottom 6 bits plus 3 are the match length. A token with offset
0 ends the decode (Excal.asm:53315).
Correction: offset 0 was described here as “a special case that outputs nothing”, after which decoding carried on. The game’s routine returns at once.
In the Excal-family games LZSS dominates: Spirit’s Amiga images are 14 RLE, 403 LZSS and 2 raw, not the “roughly 322 LZSS to 9 PackBits” this page used to give.
Text uses the same rule. Compressed CSTR/RTSC strings (attribute
bit 0 or 7) are RLE or LZSS streams behind the same size prefix and read as
noise if exported raw: 2 such resources per WIME platform, 37 in Spirit’s
Amiga release and 57 in Vengeance’s. See the
Spirit and Vengeance pages for the text-export
counts.
Pixel data: interleaved bitplanes
Section titled “Pixel data: interleaved bitplanes”bytesPerRow = ceil(width / 16) × 2 (word-aligned)total = bytesPerRow × height × depthEach scanline stores all depth bitplanes consecutively:
Row 0: [plane0 row0] [plane1 row0] … [planeN row0]Row 1: [plane0 row1] [plane1 row1] … [planeN row1]Recovering a pixel’s colour index:
rowOffset = y × (bytesPerRow × depth)for plane p in 0 … depth-1: bit = pixelData[rowOffset + p × bytesPerRow + (x >> 3)] >> (7 - (x & 7)) & 1 colorIndex |= bit << pThe palette is not in the resource. Each game supplies its own — see that game’s section.
Header variants
Section titled “Header variants”WIME Amiga — 28 bytes
Section titled “WIME Amiga — 28 bytes”+0x00 1 format 0x02 standard, 0x05 variant+0x01 1 reserved always 0x00+0x02 1 priority z-order, written at runtime by the loader+0x03 2 reserved+0x05 1 depth bitplane count (4 = 16 colours, 5 = 32)+0x06 14 reserved zeroed runtime fields for the display engine+0x14 2 width u16 BE+0x16 2 height u16 BE+0x18 4 reservedSize check: decompressedSize == 28 + ceil(width/16) × 2 × height × depth.
Holds for all 113 standard-format resources.
WIME Apple IIGS — 27 bytes
Section titled “WIME Apple IIGS — 27 bytes”One fewer reserved byte at +0x06 (13 rather than 14) shifts width and
height back to the odd-aligned offsets +0x13 and +0x15, stored
little-endian, with the outer container’s size prefix also LE. The IIGS port
is always depth 4 — never 5.
Correction (2026-11-13 audit): IIGS (and DOS EGA) pixel data is packed-nibble (two 4-bit pixels per byte, high nibble first), not 4-plane planar; the size invariant cannot tell the two apart. Against the Amiga art, 196 IIGS
LMRFframes agree on 99.87% of silhouette edges read as nibbles and 57.0% read as planes. DOS EGAGAMIuses this same 27-byte little-endian header. The decoder was already right; only the docs said planar.
Spirit / Vengeance / Conan / Legend — 6 bytes
Section titled “Spirit / Vengeance / Conan / Legend — 6 bytes”+0x00 2 height u16 BE+0x02 2 width u16 BE+0x04 1 padding always 0x00+0x05 1 depth 4 or 5Correction (2026-11-13 audit, applied 2026-11-18): this header was shown as a
0x00“marker” byte then a u8 height. The “marker” is just the high byte of a big-endian u16 height (0x01means 256-511 rows), and the old “marker0x01” variant read width and height swapped; it only ever fired on Spirit’s 256×256 atlas, IMAG #500, so the swap stayed hidden. Verified on all 972 Spirit IMAGs (Amiga and CDTV): exact length match, all depth 5, none with height 0._OpenImagagrees, reading width from the original+2. Warriors of Legend’s 256×256 atlases read01 00 01 00 00 05the same way (from the audit report, not re-run on every GAMI).
Pixel data starts at offset 6. When height is 0 (never observed on
Spirit, unverified elsewhere) the decoder derives it:
height = (payloadSize − 6) / (ceil(width/16) × 2 × depth).
Detection: check byte0 == 0x00 and byte4 == 0x00, then validate
width <= 1024 and depth in 1–8. On a match, use the 6-byte layout;
otherwise fall through to the 27/28-byte ones.
The uncompressed variant
Section titled “The uncompressed variant”A minority of 6-byte-header resources have no compression wrapper at all
— the header sits at byte 0 of the resource. The check is an exact match of
6 + ceil(width/16) × 2 × height × depth against the resource’s total
length, confirmed byte-exact against 12 real Warriors of Legend GAMI
resources.
These previously failed for a reason worth knowing: the resource-fork
parser’s LE fix-up unconditionally byte-swapped the first 4 bytes of every
GAMI/LMRF resource, assuming they were always a size prefix. In the
uncompressed variant those 4 bytes are the header, and swapping them
corrupted it before the image decoder ever saw it. Fixed by checking the
exact-length invariant against the pre-swap bytes.
Decode status
Section titled “Decode status”| Game / platform | Total | Decoded | Notes |
|---|---|---|---|
| WIME Amiga | 115 | 115 | 2 needed the uncompressed-payload path and still show unexplained pixel noise |
| WIME Apple IIGS | 110 | 108 | Corrected (2026-11-13 audit): the 2 failures are WORLD.RES #313, a truncated stream (6,123 of 7,611 bytes; DOS EGA has a complete one), and #314, zero-length. They are not “uninitialised placeholder data”, and the total is 110, not 84 |
| Spirit of Excalibur | 333 | 330 | 3 genuinely corrupt — implausible decompressed sizes, ~458 K–589 K |
| Vengeance of Excalibur | 496 | 496 | Was 476/496; 18 fixed by the uncompressed-header path, the last 2 by the too-small-guard fix below |
| Conan the Cimmerian | 401 (336 .res + 65 .L32) |
65 .L32 |
The 336 .res IMAGs are not yet run through the repo’s 6-byte path; the 2026-11-13 audit’s independent decoders found all of them satisfy the exact-length invariant |
| Warriors of Legend | 1,070 | 1,070 | 12 recovered by the uncompressed-header path, 1 by the too-small-guard fix |
The too-small guard was measuring the wrong thing
Section titled “The too-small guard was measuring the wrong thing”decodeIMAG() used to reject any resource shorter than 27 bytes — the IIGS
header size, a threshold with nothing to do with a compressed resource’s
on-disk length. A well-compressed tiny image can be under 27 bytes raw and
still decompress to a valid payload. Confirmed on Vengeance’s TITLE32A.RES
#110 and #112 (26 bytes raw) and Legend’s res32/object.res #7049 (22
bytes): all three decompress to their declared size exactly. The guard now
requires only the 4 bytes needed to read the size prefix, and the real
too-small check happens downstream on the decompressed payload.
The Excal family’s runtime header
Section titled “The Excal family’s runtime header”The Excal engine doesn’t read the 6-byte header directly. _OpenImag loads
the resource and calls _AddHeaderBytes(8) to prepend 8 bytes; all rendering
then works against a 14-byte in-memory bitmap header whose bytesPerRow is
computed as ((width − 1) >> 4 + 1) << 1 and whose height, width and depth
are copied straight through from the on-disk header. The engine never
recomputes them.
Resources holding multiple sub-images carry a frame table immediately after
that 14-byte header: a 4-byte { u16 frameCount, u16 flags } head, then one
6-byte entry per sub-image giving a packed pixel offset, a flags/plane-count
byte, a sub-image index, and the sub-image’s own width and height. _DrawPrim
reads per-frame dimensions from these entries, not from the 6-byte IMAG
header.
See them rendered
Section titled “See them rendered”- WIME — Icon Gallery, Buildings & Scenery and the item icons on Items.
- Composited scenes built from
IMAGobjects: WIME, Spirit of Excalibur and Vengeance of Excalibur. - Conan — Image Gallery.
Where the full evidence lives
Section titled “Where the full evidence lives”docs/formats/imag.md in the main repository (not part of this site), plus
the per-game palette and catalogue notes it links: WIME’s
amiga/imag-catalog.md and amiga/palettes.md, the DOS/IIGS specifics in
wime/dosvga/gami-format.md, and each Excal game’s own engine.md.
Undecoded header variants are tracked separately in
docs/reference/eliminated/imag-frml-open-variants.md.