2011-11-22 17:54:53 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
|
|
|
#include <base/math.h>
|
|
|
|
#include <base/system.h>
|
|
|
|
#include <engine/external/pnglite/pnglite.h>
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
unsigned char r, g, b, a;
|
|
|
|
} CPixel;
|
|
|
|
|
2011-11-26 19:19:57 +00:00
|
|
|
static void TilesetBorderrem(int w, int h, CPixel *pSrc, CPixel *pDest)
|
2011-11-22 17:54:53 +00:00
|
|
|
{
|
|
|
|
int TileW = w/16;
|
|
|
|
int TileH = h/16;
|
|
|
|
|
|
|
|
for(int tx = 0; tx < 16; tx++)
|
|
|
|
{
|
|
|
|
for(int ty = 0; ty < 16; ty++)
|
|
|
|
{
|
2011-11-26 19:19:57 +00:00
|
|
|
for(int x = 0; x < TileW - 4; x++)
|
2011-11-22 17:54:53 +00:00
|
|
|
{
|
2011-11-26 19:19:57 +00:00
|
|
|
for(int y = 0; y < TileH - 4; y++)
|
2011-11-22 17:54:53 +00:00
|
|
|
{
|
2011-11-26 19:19:57 +00:00
|
|
|
int SourceX = tx * TileW + x + 2;
|
|
|
|
int SourceY = ty * TileH + y + 2;
|
|
|
|
int DestX = tx * (TileW - 4) + x;
|
|
|
|
int DestY = ty * (TileH - 4) + y;
|
|
|
|
|
|
|
|
int SourceI = SourceY * w + SourceX;
|
|
|
|
int DestI = DestY * (w - 16 * 4) + DestX;
|
|
|
|
|
|
|
|
pDest[DestI] = pSrc[SourceI];
|
|
|
|
|
2011-11-22 17:54:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int FixFile(const char *pFileName)
|
|
|
|
{
|
|
|
|
png_t Png;
|
|
|
|
CPixel *pBuffer[2] = {0,0};
|
|
|
|
|
|
|
|
png_init(0, 0);
|
|
|
|
png_open_file(&Png, pFileName);
|
|
|
|
|
|
|
|
if(Png.color_type != PNG_TRUECOLOR_ALPHA)
|
|
|
|
{
|
2011-11-26 19:19:57 +00:00
|
|
|
dbg_msg("tileset_borderrem", "%s: not an RGBA image", pFileName);
|
2011-11-22 17:54:53 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int w = Png.width;
|
|
|
|
int h = Png.height;
|
|
|
|
|
|
|
|
pBuffer[0] = (CPixel*)mem_alloc(w*h*sizeof(CPixel), 1);
|
2011-11-26 19:19:57 +00:00
|
|
|
pBuffer[1] = (CPixel*)mem_alloc((w-16*4)*(h-16*4)*sizeof(CPixel), 1);
|
2011-11-22 17:54:53 +00:00
|
|
|
png_get_data(&Png, (unsigned char *)pBuffer[0]);
|
|
|
|
png_close_file(&Png);
|
|
|
|
|
2011-11-26 19:19:57 +00:00
|
|
|
TilesetBorderrem(w, h, pBuffer[0], pBuffer[1]);
|
2011-11-22 17:54:53 +00:00
|
|
|
|
|
|
|
// save here
|
|
|
|
png_open_file_write(&Png, pFileName);
|
2011-11-26 19:19:57 +00:00
|
|
|
png_set_data(&Png, w - 16 * 4, h - 16 * 4, 8, PNG_TRUECOLOR_ALPHA, (unsigned char *)pBuffer[1]);
|
2011-11-22 17:54:53 +00:00
|
|
|
png_close_file(&Png);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, const char **argv)
|
|
|
|
{
|
|
|
|
dbg_logger_stdout();
|
|
|
|
if(argc == 1)
|
|
|
|
{
|
2016-05-02 19:35:32 +00:00
|
|
|
dbg_msg("usage", "%s FILE1 [ FILE2... ]", argv[0]);
|
2011-11-22 17:54:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 1; i < argc; i++)
|
|
|
|
FixFile(argv[i]);
|
|
|
|
return 0;
|
|
|
|
}
|