Welcome to the Creatures Wiki! Log in and join the community.

Difference between revisions of "BLK files"

From Creatures Wiki
Jump to navigation Jump to search
m
m (try clarifying this a bit)
(One intermediate revision by the same user not shown)
Line 1: Line 1:
[[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.
+
[[BLK files]] are basically [[S16 files]] with a slightly different header, and with slightly incorrect offsets due to the different header. They contain 128x128 [[sprite]]s which are the 'blocks' which make up the background.
  
 
The header is as follows (all values are little-endian):
 
The header is as follows (all values are little-endian):
  
 
<table border="1">
 
<table border="1">
<tr><td>flags</td><td>32-bit integer</td><td>only the first bit is used; if set, the image is in 555 format, if not, the image is in 565 format</td></tr>
+
<tr><td>flags</td><td>32-bit integer</td><td>only the first bit is used; if set, the image is in [[555/565|555]] format, if not, the image is in [[555/565|565]] format</td></tr>
 
<tr><td>backgroundwidth</td><td>16-bit integer</td><td>the width of the background, in blocks (not pixels!)</td></tr>
 
<tr><td>backgroundwidth</td><td>16-bit integer</td><td>the width of the background, in blocks (not pixels!)</td></tr>
 
<tr><td>backgroundheight</td><td>16-bit integer</td><td>the height of the background, in blocks (not pixels!)</td></tr>
 
<tr><td>backgroundheight</td><td>16-bit integer</td><td>the height of the background, in blocks (not pixels!)</td></tr>
Line 18: Line 18:
 
</table>
 
</table>
  
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).  
+
The rest of the file consists of image data at the file offsets defined in the header. Sprites are stored as an array of horizontal scanlines of the sprite. Each pixel is represented as a 16-bit little-endian integer in the format specified in the header.
  
In 555 format, the bits are allocated as follows:
+
The sprites are sorted first horizontally, then vertically (so in an image which was 8 sprites (ie, 8*128 = 1024 pixels) wide and 2 sprites high, you'd get 8 sprites representing the first row, and then 8 sprites representing the second row).
 
 
<pre>
 
0123 4567 0123 4567
 
-rrr rr-- ---- ----
 
---- --gg ggg- ----
 
---- ---- ---b bbbb
 
</pre>
 
 
 
In 565 format, the bits are allocated as follows:
 
 
 
<pre>
 
0123 4567 0123 4567
 
rrrr r--- ---- ----
 
---- -ggg ggg- ----
 
---- ---- ---b bbbb
 
</pre>
 
 
 
The following macros can be used in C or C++ to decode these values to normal 24-bit format:
 
 
 
<pre>
 
 
 
/* Decoding macros by bd_ aka bdonlan. I release these into the public domain. */
 
 
 
#define RGB(r, g, b) ((r) &lt;&lt; 16 | (g) &lt;&lt; 8 | (b))
 
 
 
#define DECODE_555(v)          \
 
(qRgb(                      \
 
  ((uint32_t)(v) & 0x7800) &gt;&gt; 7,  \
 
  ((uint32_t)(v) & 0x03e0) &gt;&gt; 2, \
 
  ((uint32_t)(v) & 0x001f) &lt;&lt; 3  \
 
))
 
 
 
#define DECODE_565(v)          \
 
(qRgb(                      \
 
  ((uint32_t)(v) & 0xf800) &gt;&gt; 8 , \
 
  ((uint32_t)(v) & 0x07e0) &gt;&gt; 3 , \
 
  ((uint32_t)(v) & 0x001f) &lt;&lt; 3  \
 
))
 
 
 
</pre>
 
 
[[Category:File formats]]
 
[[Category:File formats]]

Revision as of 05:35, 19 January 2006

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):

flags32-bit integeronly the first bit is used; if set, the image is in 555 format, if not, the image is in 565 format
backgroundwidth16-bit integerthe width of the background, in blocks (not pixels!)
backgroundheight16-bit integerthe height of the background, in blocks (not pixels!)
numframes16-bit integerthe number of sprites in the file (must always equal backgroundwidth * backgroundheight)

Then, for each sprite:

offset32-bit integeroffset of the sprite data from the start of the file, minus 4.
width16-bit integerwidth of the sprite. must be 128.
height16-bit integerheight of the sprite. must be 128.

The rest of the file consists of image data at the file offsets defined in the header. Sprites are stored as an array of horizontal scanlines of the sprite. Each pixel is represented as a 16-bit little-endian integer in the format specified in the header.

The sprites are sorted first horizontally, then vertically (so in an image which was 8 sprites (ie, 8*128 = 1024 pixels) wide and 2 sprites high, you'd get 8 sprites representing the first row, and then 8 sprites representing the second row).