1
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
3
#include "../engine/external/pnglite/pnglite.c"
7
unsigned char r, g, b, a;
10
static pixel sample(int x, int y, int w, int h, pixel *data, int pitch, float u, float v)
14
return data[y*pitch+x];
17
static void tilemap_borderfix(int w, int h, pixel *src, pixel *dst)
26
memset(dst, 0, sizeof(pixel)*w*h);
28
for(ty = 0; ty < 16; ty++)
29
for(tx = 0; tx < 16; tx++)
31
for(y = 0; y < tileh-2; y++)
32
for(x = 0; x < tilew-2; x++)
34
u = 0.5f/tilew + x/(float)(tilew-2);
35
v = 0.5f/tileh + y/(float)(tileh-2);
36
k = (ty*tileh+1+y)*w + tx*tilew+x+1;
37
dst[k] = sample(tx*tilew, ty*tileh, tilew, tileh, src, w, u, v);
39
if(x == 0) dst[k-1] = dst[k];
40
if(x == tilew-2-1) dst[k+1] = dst[k];
41
if(y == 0) dst[k-w] = dst[k];
42
if(y == tileh-2-1) dst[k+w] = dst[k];
44
if(x == 0 && y == 0) dst[k-w-1] = dst[k];
45
if(x == tilew-2-1 && y == 0) dst[k-w+1] = dst[k];
46
if(x == 0 && y == tileh-2-1) dst[k+w-1] = dst[k];
47
if(x == tilew-2-1 && y == tileh-2-1) dst[k+w+1] = dst[k];
53
int main(int argc, char **argv)
56
pixel *buffer[2] = {0,0};
60
png_open_file(&png, argv[1]);
62
if(png.color_type != PNG_TRUECOLOR_ALPHA)
64
printf("not an RGBA image\n");
71
buffer[0] = (pixel*)malloc(w*h*sizeof(pixel));
72
buffer[1] = (pixel*)malloc(w*h*sizeof(pixel));
73
png_get_data(&png, (unsigned char *)buffer[0]);
76
tilemap_borderfix(w, h, buffer[0], buffer[1]);
79
png_open_file_write(&png, argv[1]);
80
png_set_data(&png, w, h, 8, PNG_TRUECOLOR_ALPHA, (unsigned char *)buffer[1]);