The idea is that bitplane data is decoded into a value that is an index corresponding to a colour in the associated palette. The SNES palette (CGRAM) is a block of data containing 512 colours. Sprite and background tiles have some extra data that tells the SNES what section of CGRAM to use.
2bpp, 4bpp and 8bpp determine how many bits each decoded value has. For 2 bits, we have a range of 0-3, for 4 bits we have 0-15 and for 8 bits we have 0-255. SNES Sprites are always 4bpp. Background tiles can be 2bpp, 4bpp or 8bpp depending on the background mode. There are a few other background formats but most of them aren't used in the DKC games.
Individual tiles are always 8x8 pixels, so a single tile contains 64 pixels worth of data. Sprites are typically made up of many tiles!
So we have:
· palette data (contains the colours)
· tilemap data (which palette block to use)
· tileset data (bitplane data, which colours to use in the block)
And that's everything needed to decode and construct a tile. (you won't need tilemap data if you know the palette used by a particular tile)
Here is a brief summary for the bitplane format itself:
It's easier to think it through with 2bpp first, as 4bpp and 8bpp are the same but with more blocks of data. The nth 16-bit word contains data for the nth row of pixels. So 1st word contains data for 1st row, 8th word contains data for the 8th row.
Each 16-bit word in the bitplane format consists of 2 bytes containing 2 bits for each pixel in a given row.
- Code: Select all
76543210 - byte #1 in a given word
76543210 - byte #2 in a given word
So if we had a 2bpp bitplane and the first word was C7 34, we could decode that as:
- Code: Select all
C7 = 11000111 (1)
34 = 00110100 (2)
= 11220311
So the 8 pixel values in the nth row would be 1,1,2,2,0,3,1,1. We'd then look those up those in the palette to get the matching colour.
4bpp and 8bpp work the same, they just contain additional blocks of words after the first block of words.
- Code: Select all
2bpp = 1 block of 8 words
4bpp = 2 blocks of 8 words
8bpp = 4 blocks of 8 words
If the data were 4bpp, the only difference from 2bpp would be that there is another block of 8 words
after the first block, so 16 words (32 bytes) altogether.
If the corresponding word in the second block was 56 39, we'd get:
- Code: Select all
C7 = 11000111 (1)
34 = 00110100 (2)
56 = 01010110 (4)
39 = 00111001 (8)
= 15AE8759
So 1,5,10,14,8,7,5,9 as values for each pixel in this row.
It's a finicky thing and it can take a while to click, especially if you're not used to bits and binary logic. Some of the tutorials I went through years ago about this were nothing short of atrocious. There was one that was so bad it felt like I was unlearning all of this by just reading it.
If you don't have the palette data handy, you can scale the decoded values to produce a greyscale image. It wouldn't contain any colour, but it would still be legible.