palpic2png.c: improve, make usable with ppic binary files
[rofl0r-openDOW.git] / utils / bitplaneconv.c
blob2024a80188fab58640c80dca9a0b6cf9c1b66c96
1 #include "../palpic.h"
2 #include "../temp.c"
3 #include "leptonica/allheaders.h"
4 #include <string.h>
5 #pragma RcB2 LINK "-llept"
7 #define BITPLANES 4
8 #define sprite temp
10 int main() {
11 const prgb color_tab[] = {
12 PRGB(0, 0, 0),
13 PRGB(0xff, 0xdd, 0x55), //yellow
14 PRGB(0xbb, 0xbb, 0xbb), // light gray
15 PRGB(0x11, 0x33, 0x33), // dark gray
16 PRGB(0x22, 0x22, 0x22), // dummy2
17 PRGB(0x33, 0x33, 0x33), // dummy3
18 PRGB(0xbb, 0x55, 0x11), // orange
19 PRGB(0x66, 0x66, 0x66), // dummy6
20 PRGB(0xff, 0xff, 0xdd), // white
21 PRGB(0x11, 0x11, 0x11), // dummy1
22 PRGB(0xbb, 0x77, 0x55), // light orange
23 PRGB(0x77, 0x55, 0x11), // brown,
24 PRGB(0x44, 0x44, 0x44), // dummy4
25 PRGB(0x55, 0x55, 0x55), // dummy5
26 PRGB(0x77, 0x77, 0x77), // dummy7
27 PRGB(0xbb, 0x99, 0x55), // light brown
29 const struct palpic* f = &sprite.header;
30 PIX* o = pixCreate(f->width, f->height / BITPLANES, 32);
31 int w = palpic_getspritewidth(f);
32 int h = palpic_getspriteheight(f);
33 size_t i = 0;
34 uint8_t plane[h][w];
35 prgb* bufptr = (prgb*) o->data;
36 for(i = 0; i+(BITPLANES-1) < f->spritecount; i+=BITPLANES) {
37 memset(plane, 0, sizeof plane);
38 int x;
39 int y;
40 size_t j;
41 for(j = 0; j < BITPLANES; j++) {
42 const uint8_t *source = palpic_getspritedata(f, i + j);
43 for(y = 0; y < h; y++) {
44 for(x = 0; x < w; x++) {
45 if(*source) plane[y][x] |= 1 << j;
46 source++;
50 for(j = 0; j < sizeof plane; j++) {
51 *bufptr++ = color_tab[((uint8_t*)plane)[j]];
54 pixWritePng("test.png", o, 0.0);
55 return 0;