Difference between revisions of "BLK files"
(More detailed BLK docs) |
(fix stray <) |
||
Line 40: | Line 40: | ||
The following macros can be used in C or C++ to decode these images to normal 32-bit format: | The following macros can be used in C or C++ to decode these images to normal 32-bit format: | ||
− | <pre> | + | <pre> |
#define RGB(r, g, b) ((r) << 16 | (g) << 8 | (b)) | #define RGB(r, g, b) ((r) << 16 | (g) << 8 | (b)) | ||
Revision as of 04:55, 11 February 2005
BLK files are basically S16 files with a slightly different header, and with slightly incorrect offsets due to the different header. They contain 128x128 sprites which are the 'blocks' which make up the background.
The header is as follows (all values are little-endian):
flags | 32-bit integer | only the first bit is used; if set, the image is in 555 format, if not, the image is in 565 format |
backgroundwidth | 16-bit integer | the width of the background, in blocks (not pixels!) |
backgroundheight | 16-bit integer | the height of the background, in blocks (not pixels!) |
numframes | 16-bit integer | the number of sprites in the file (must always equal backgroundwidth * backgroundheight) |
Then, for each sprite:
offset | 32-bit integer | offset of the sprite data from the start of the file, minus 4. |
width | 16-bit integer | width of the sprite. must be 128. |
height | 16-bit integer | height of the sprite. must be 128. |
The rest of the file consists of image data at the file offsets defined in the header. Images are stored as an array of horizontal scanlines. Each pixel is represented as a 16-bit little-endian integer. The breakdown of the integer into red, green, and blue components depends on the format (555 or 565).
In 555 format, the bits are allocated as follows:
0123 4567 0123 4567 -rrr rr-- ---- ---- ---- --gg ggg- ---- ---- ---- ---b bbbb
In 565 format, the bits are allocated as follows:
0123 4567 0123 4567 rrrr r--- ---- ---- ---- -ggg ggg- ---- ---- ---- ---b bbbb
The following macros can be used in C or C++ to decode these images to normal 32-bit format:
#define RGB(r, g, b) ((r) << 16 | (g) << 8 | (b)) #define DECODE_555(v) \ (qRgb( \ ((uint32_t)(v) & 0x7800) >> 7, \ ((uint32_t)(v) & 0x03e0) >> 2, \ ((uint32_t)(v) & 0x001f) << 3 \ )) #define DECODE_565(v) \ (qRgb( \ ((uint32_t)(v) & 0xf800) >> 8 , \ ((uint32_t)(v) & 0x07e0) >> 3 , \ ((uint32_t)(v) & 0x001f) << 3 \ ))