FileFormats SPR

From Seven Kingdoms
Jump to: navigation, search

All SPR files share the same format. A file is made up of the sprite's frames. Each frame is in this format:

class Frame
    Int32 size;   //in bytes
    Int16 width;  //in pixels
    Int16 height; //in pixels
    byte[] data;  //initialized to byte[this.size]

So, a sprite would simply look like this:

class Sprite
    Frame[] frames;

The data field in Frame is an 8bpp paletted/indexed bitmap stored in a modified version of run-length encoding (RLE) for compression. The modification is in the fact that the only bytes encoded/compressed are transparent pixels, but only when there are 6 or more consecutive transparent pixels. In short, RLE-encoded transparent bytes are identified by the values 0xf8, followed by a byte indicating how many transparent pixels were removed from the data. The other modification is the use of the values 0xf9-0xff instead of "straight" RLE. The bytes are used to indicate how many transparent pixels have been RLE'd by subtracting the value from 255. For example, 6 consecutive transparent pixels would be written out only as 0xf9 instead of the standard RLE of 0xf8 0x6, thereby saving an additional byte every time there are less than 7 transparent bytes in sequence.

There are three color palettes provided with the game but the only one used is pal_std.res. This palette defines transparent as transparent-black (ARGB = 0,0,0,0) instead of the transparent-white (0,255,255,255) that is used in many other places (like .NET's System.Drawing.Color.Transparent).