
CHR is a 2-bit graphic format for Famicom and Uxn spritesheets.
The CHR
file contains a series of bits equivalent to pixels in a 8x8 tile. The data for each tile is made up of 128 bits, where the first 64 bits are the first channel, the next 64 bits the second channel, and where the channels overlap result in a total of 4 colors including the background.
ch1 + ch2 | hex | ||||||||
---|---|---|---|---|---|---|---|---|---|
1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | f8 | 00 |
1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | f8 | 00 |
1 | 1 | 3 | 3 | 3 | 2 | 2 | 0 | f8 | 3e |
1 | 1 | 3 | 3 | 3 | 2 | 2 | 0 | f8 | 3e |
1 | 1 | 3 | 3 | 3 | 2 | 2 | 0 | f8 | 3e |
0 | 0 | 2 | 2 | 2 | 2 | 2 | 0 | 00 | 3e |
0 | 0 | 2 | 2 | 2 | 2 | 2 | 0 | 00 | 3e |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 00 | 00 |
This is the standard format for Varvara ecosystem, to view and edit chr files, try Nasu. A toolchain was also created to convert images from the tga format.
Uint8 tile[16] = { 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x00 }; void draw_chr(Uint32 *dst, int x, int y, Uint8 *sprite) { int v, h; for(v = 0; v < 8; v++) for(h = 0; h < 8; h++) { int ch1 = ((sprite[v] >> h) & 0x1); int ch2 = (((sprite[v + 8] >> h) & 0x1) << 1); put_pixel(dst, x + 7 - h, y + v, ch1 + ch2); } }