XSprite
Navigation

News About Downloads Information Links

This page contains technical information about the XSprite format. Unless you are interested in helping with the XSprite project, the information below is probably only of academic value.

Header Data

The first section of any XSprite, as with most file formats, is the header. Due to the nature of some sections of the XSprite header, the size is dynamic, and could range up to in excess of 60KB.

The first section of the header is a 4 byte code, to ensure that the file is, infact, an XSprite file. The first byte should be randomly generated by the program that created the file, and the the following 3 bytes follow a mathmatical formula based on the previous number.
The formula for calculating a number in the sequence is (X * (3.1 * X)) % 256, where X is the previous byte.

The next two bytes specify the total size of the 'meta-block'. The meta-block is a section of the header used to store non-technical information about the file, such as the artists name, or copyright details. Although the system is designed for strings, other data could be stored, although as the size is only specified with 2 bytes, the total size of all the data cannot exceed about 63KB.

Each section of the meta-block is stored like this:
1 byte - size of the section name in bytes
X bytes - section name as an ASCII string
2 bytes - size of section data in bytes
X bytes - section data

After the meta-block, technical information about the file is stored.
The next 2 bytes store the number of frames that the file contains. This number should be assumed to be correct AT ALL TIMES. Any difference between this number and the amount of data in the file should be treated as serious errors, and reported to the user as a corrupt or incomplete file.

The next 4 bytes store the width and height of each frame respectively, using 2 bytes each. It is these values, along with the number of frames, that will be used to calculate how big the file should be.

The final byte of the header stored the number of masks that will be 'active' in the XSprite. This number should be between 0 and 4, if it exceeds 4, then the file should be treated as corrupt, and the program reading the file should proceed with caution, if at all. Masks that are not active should be left as 0 for all pixels, although this is not required, and should not be treated as an error if it isn't so, unless the program is expecting the strictest of file specification.

Pixel Data

After the header data, follows the pixel data. The data is stored from top left to bottom right of the image, each frame after the other, with no breaks in the file.

Each pixel consists of 3 bytes, divided into 'blocks' of bits to store the different values required.
The first block in each pixel is the red intensity, taking up 5 bits. This will be a number between 0 and 31 which, when multiplide by 8 will give us a number between 0 and 248, a fair range to work with. The binary AND mask to gain this data would be 111110000000000000000000, and this stored as hex is 0xF80000.
The second block of each pixel is the green intensity, again 5 bits. The binary AND mask to gain this data would be 000001111100000000000000, and this stored as hex is 0x07C000.
The third block of each pixel is the blue intensity, again 5 bits. The binary AND mask to gain this data would be 000000000011111000000000, and this stored as hex is 0x003E00.
The fourth block of each pixel is the alpha value, again 5 bits. The binary AND mask to gain this data would be 000000000000000111110000, and this stored as hex is 0x0001F0.
The fifth block of each pixel is the 1st of the masks, this is 1 bit. The binary AND mask to gain this data would be 000000000000000000001000, and this stored as hex is 0x000008.
The sixth block of each pixel is the 2nd of the masks, this is also 1 bit. The binary AND mask to gain this data would be 000000000000000000000100, and this stored as hex is 0x000004.
The seventh block of each pixel is the 3rd of the masks, this is also 1 bit. The binary AND mask to gain this data would be 000000000000000000000010, and this stored as hex is 0x000002.
The eighth block of each pixel is the 4th of the masks, this is also 1 bit. The binary AND mask to gain this data would be 000000000000000000000001, and this stored as hex is 0x000001.
That is all the data stored for one pixel.


Valid XHTML 1.0 Transitional Valid CSS!

SourceForge.net Logo