Skip to content

HG‐2 Image

Robert Jordan edited this page May 19, 2021 · 7 revisions

All values and versions are known, with exception to the 8 bytes before compressed length. The same as with HG-3 Image's img#### tag.

The file structure and image encoding for HG-2 Images is over 20 years old now, as they existed in the original CatSystem (1) engine in the late 1990's. And the image encoding is identified as the same encoding from a patent filed in 1988.

NOTE: Although HG-2 shares the same set of 6 fields with HG-3 for its native image encoding, these fields are ignored by CatSystem 2 (and presumably 1) in assembly. Thus HG-2 images do not support multiple slices for a single image.

File Structure

This header uses the same structure as HG-3 Image's header.

Data Type Value Description
char[4] "HG-2" File Signature
uint32 HeaderSize Size of this header, always 12
uint32 Version HG-2 version number: 0x10, 0x20, or 0x25
Frame[>] Frames A find-by-offset set of frames for this image

Note: Version is read as a uint16

About Version

The Version field is likely formatted as hex digits, but represented as a decimal version number.

Hex Dec Includes
0x10 v1.0 Single frame, no ID
0x20 v2.0 Multiple frames, ID, Total Size, Offset XY, Transparent fields
0x25 v2.5 Base XY fields

StartPosition = stream.Position

Frame Structure

Version 0x10 HG-2 images have only one frame, and no ID. These have never been seen in the wild, but discovered in the assembly instructions for reading HG-2 images.

Position = StartPosition + Frame.OffsetNext
StartPosition = stream.Position
do while Frame.OffsetNext != 0

Version 0x10

Note: BitDepth is read as a uint16 - Looking at GARbo's implementation, they list the fiend as u16 BPP followed by u16 Depth. But use of this has not yet been observed in assembly. If it does have significance, then it may be similar to the 'Planes' field used by bitmaps, or unlikely but may be used for actual slice implementation.

Data Type Value Description
uint32 Width Condensed width of the image (without transparency)
uint32 Height Condensed height of the image (without transparency)
uint32 BitDepth Number of bits per pixel, 24 or 32
uint32 Reversed1 Unused, not supported (would be the slice index)
uint32 Reserved2 Unused, not supported (would be the slice length)
uint32 CompressedDataLength Compressed length of Zero Run-length copy data
uint32 DecompressedDataLength Decompressed length of Zero Run-length copy data
uint32 CompressedCmdLength Compressed length of Zero Run-length copy command bits
uint32 DecompressedCmdLength Decompressed length of Zero Run-length copy command bits

Version 0x20

Frame versions 0x20 and up include Version 0x10 data for every frame in the HG-2 image.

Data Type Value Description
Info 0x10^ FrameInfo 1.0 HG-2 version 0x10 frame info
uint32 OffsetData Offset from start of Version 0x20 to Image Data
Can also be additional length of Frame structure
Always >= 0x20
uint32 ID Identifier for the frame used in game
uint32 TotalWidth Total width of the image with OffsetX applied
uint32 TotalHeight Total height of the image with OffsetY applied
int32 OffsetX Horizontal offset of the image from the left
int32 OffsetY Vertical offset of the image from the top
bool32 IsTransparent True if transparency is used in the image
uint32 OffsetNext Offset from start of Version 0x10 to next frame
Value is 0 if no more frames

The IsTransparent field is referred to as a Transparency Specifier in 1990's/2000's standard image formats (like TIFF)

Version 0x25

Data Type Value Description
Info 0x20^ FrameInfo 2.0 HG-2 version 0x10+0x20 frame info
int32 BaseX Horizontal center of the image, used for drawing in-game
int32 BaseY Vertical center of the image, used for drawing in-game

Image Data

This always immediately follows the Frame Info for Version == 0x10, otherwise it has an additional offset of Frame.OffsetData.

Position = StartPosition + 0x24 + Frame.OffsetData

Data Type Value Description
byte[CompressedDataLength] RleData Compressed Zero Run-length copy data
byte[CompressedCmdLength] RleCmd Compressed Zero Run-length copy command bits

See HG‐X ProcessImage for how standard HG-2 and HG-3 image data is made readable.

Clone this wiki locally