2 #include "leptonica/allheaders.h"
4 #pragma RcB2 LINK "-llept -lpng -ljpeg -ltiff -lgif -lz"
6 struct palpic
*palpic_from_file(const char *fn
) {
7 FILE *fi
= fopen(fn
, "r");
9 fseek(fi
, 0, SEEK_END
);
10 off_t len
= ftello(fi
);
11 fseek(fi
, 0, SEEK_SET
);
12 struct palpic
* f
= malloc(len
);
13 if(f
) fread(f
, 1, len
, fi
);
15 if(f
) palpic_hostformat(f
);
19 void palpic_to_png(const struct palpic
*f
, const char *fn
) {
20 PIX
* o
= pixCreate(f
->width
, f
->height
, 32);
21 prgb
* palette
= palpic_getpalette(f
);
22 prgb
* bufptr
= (prgb
*) o
->data
;
24 for(i
= 0; i
< f
->spritecount
; i
++) {
26 const uint8_t *source
= palpic_getspritedata(f
, i
);
27 for(y
= 0; y
< palpic_getspriteheight(f
); y
++) {
28 for(x
= 0; x
< palpic_getspritewidth(f
); x
++) {
29 *bufptr
++ = palette
[*source
++];
33 pixWritePng(fn
, o
, 0.0);
43 const struct palpic
* f
= & sprite
.header
;
44 palpic_to_png(f
, "test.png");
50 int main(int argc
, char **argv
) {
52 struct palpic
*f
= palpic_from_file(*argv
);
55 dprintf(2, "%s\n", *argv
);
59 snprintf(buf
, sizeof buf
, "%s.png", *argv
);
60 palpic_to_png(f
, buf
);