diff options
| -rw-r--r-- | gentpl/Makefile | 4 | ||||
| -rw-r--r-- | gentpl/gentpl.c | 88 | ||||
| -rw-r--r-- | gentpl/test.png | bin | 0 -> 230378 bytes | |||
| -rw-r--r-- | testrlyt.py | 4 |
4 files changed, 94 insertions, 2 deletions
diff --git a/gentpl/Makefile b/gentpl/Makefile new file mode 100644 index 0000000..4d92b53 --- /dev/null +++ b/gentpl/Makefile @@ -0,0 +1,4 @@ +gentpl: gentpl.c + gcc -o gentpl gentpl.c -lgd -std=gnu99 +clean: + rm -f gentpl
\ No newline at end of file diff --git a/gentpl/gentpl.c b/gentpl/gentpl.c new file mode 100644 index 0000000..b0cdfdc --- /dev/null +++ b/gentpl/gentpl.c @@ -0,0 +1,88 @@ +#include <gd.h> +#include <errno.h> +#include <stdlib.h> +#include <string.h> +#include <arpa/inet.h> +struct texthead { + unsigned short height; + unsigned short width; + unsigned int format; + unsigned int offs; + unsigned int wrap_s; + unsigned int wrap_t; + unsigned int min; + unsigned int mag; + float lod_bias; + unsigned char edge_lod; + unsigned char min_lod; + unsigned char max_lod; + unsigned char unpacked; +}; +int main(int argc, char **argv) { + if(argc != 3) { + printf("Usage: gentpl <input.png> <output.tpl>\n"); + exit(1); + } + gdImagePtr im; + FILE *in = fopen(argv[1], "rb"); + if(!in) { + printf("Failed to open %s\n", argv[1]); // why strerror not working? + exit(1); + } + im = gdImageCreateFromPng(in); + fclose(in); + FILE *out = fopen(argv[2], "wb"); + if(!out) { + printf("Failed to open %s\n", argv[2]); // why strerror not working? + exit(1); + } + + if(gdImageSX(im) % 4 != 0 || gdImageSY(im) % 4 != 0) { + printf("Bad dimensions\n"); + exit(1); + } + + char magic[] = {0x00, 0x20, 0xaf, 0x30}; + fwrite(magic, 1, 4, out); + + unsigned int stuff[] = {htonl(1), htonl(0xc), htonl(0x14), 0}; + fwrite(stuff, 4, 4, out); + + struct texthead h; + memset(&h, 0, sizeof(h)); + + h.format = htonl(6); + h.offs = htonl(0x14 + sizeof(h)); + printf("%dx%d\n", gdImageSX(im), gdImageSY(im)); + h.width = htons(gdImageSX(im)); + h.height = htons(gdImageSY(im)); + + fwrite(&h, sizeof(h), 1, out); + + for(int y = 0; y < gdImageSY(im); y += 4) { + for(int x = 0; x < gdImageSX(im); x += 4) { + for(int y1 = y; y1 < y + 4; y1++) { + for(int x1 = x; x1 < x + 4; x1++) { + int p = gdImageGetPixel(im, x1, y1); + unsigned char a = 254 - 2*((unsigned char) gdImageAlpha(im, p)); + if(a == 254) a++; + unsigned char b = (unsigned char) gdImageRed(im, p); + fputc(a, out); + fputc(b, out); } + } + + for(int y1 = y; y1 < y + 4; y1++) { + for(int x1 = x; x1 < x + 4; x1++) { + int p = gdImageGetPixel(im, x1, y1); + unsigned char a = (unsigned char) gdImageGreen(im, p); + unsigned char b = (unsigned char) gdImageBlue(im, p); + fputc(a, out); + fputc(b, out); + } + } + } + } + + fclose(out); + gdImageDestroy(im); +}
\ No newline at end of file diff --git a/gentpl/test.png b/gentpl/test.png Binary files differnew file mode 100644 index 0000000..b1c851a --- /dev/null +++ b/gentpl/test.png diff --git a/testrlyt.py b/testrlyt.py index 1208de9..98ff520 100644 --- a/testrlyt.py +++ b/testrlyt.py @@ -113,8 +113,8 @@ 'angle': 0, 'flags_1': 5, 'flags_2': 4, - 'width': 400, - 'height': 180, + 'width': 608, + 'height': 456, 'name': 'pic', 'x': 0, 'y': 0, |
