palpic2png.c: improve, make usable with ppic binary files
[rofl0r-openDOW.git] / utils / wpextract.c
blob124f9fadf3bfbd1505b70a49caa2b7d10a833d19
1 #include <leptonica/allheaders.h>
2 #pragma RcB2 LINK "-llept"
3 #include <stdio.h>
4 #include <assert.h>
6 void copy_rect(int x, int y, int w, int h, void* inbuf, unsigned in_pitch, void* outbuf) {
7 uint32_t*ptr = (uint32_t*) inbuf;
8 uint32_t*out = (uint32_t*) outbuf;
9 int ix, iy;
10 for(iy = y; iy < y+h; iy++) for (ix = x; ix < x+w; ix++) {
11 *out++ = ptr[iy*in_pitch + ix];
15 int main(int argc, char**argv) {
16 if(argc != 3) {
17 dprintf(2, "%s in.png out.png\n", argv[0]);
18 return 1;
20 const char *in = argv[1];
21 const char *out = argv[2];
22 struct Pix* pin = pixRead(in);
23 struct Pix* pin32 = pixConvertTo32(pin);
24 struct Pix* pout = pixCreate(59, 16*30, 32);
26 int xo = 0, yo = 0, i;
27 uint32_t *od = (void*) pout->data;
28 for(i = 0; i < 30; i++) {
29 int xi = 3 + (i % 5) * 64;
30 int yi = 5 + (i / 5) * 23;
31 copy_rect(xi, yi, 59, 16, (void*) pin32->data, pin32->w, od);
32 od += 16*59;
34 pixWritePng(out, pout, 0);
35 return 0;