2011-03-17 16:38:21 +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>
|
2020-09-20 16:42:17 +00:00
|
|
|
#include <base/system.h>
|
2020-11-18 06:36:19 +00:00
|
|
|
#include <engine/shared/image_manipulation.h>
|
2018-02-12 22:14:14 +00:00
|
|
|
#include <pnglite.h>
|
2011-03-17 16:38:21 +00:00
|
|
|
|
2021-11-05 16:21:41 +00:00
|
|
|
int DilateFile(const char *pFilename)
|
2011-03-17 16:38:21 +00:00
|
|
|
{
|
|
|
|
png_t Png;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-03-17 16:38:21 +00:00
|
|
|
png_init(0, 0);
|
2021-11-05 16:21:41 +00:00
|
|
|
|
|
|
|
IOHANDLE File = io_open(pFilename, IOFLAG_READ);
|
|
|
|
if(!File)
|
|
|
|
{
|
|
|
|
dbg_msg("dilate", "failed to open file. filename='%s'", pFilename);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int Error = png_open_read(&Png, 0, File);
|
2020-09-10 21:25:33 +00:00
|
|
|
if(Error != PNG_NO_ERROR)
|
|
|
|
{
|
2021-11-05 16:21:41 +00:00
|
|
|
dbg_msg("dilate", "failed to open image file. filename='%s', pnglite: %s", pFilename, png_error_string(Error));
|
|
|
|
io_close(File);
|
2020-09-10 21:25:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-03-17 16:38:21 +00:00
|
|
|
if(Png.color_type != PNG_TRUECOLOR_ALPHA)
|
|
|
|
{
|
2021-11-05 16:21:41 +00:00
|
|
|
dbg_msg("dilate", "%s: not an RGBA image", pFilename);
|
2011-07-09 09:45:01 +00:00
|
|
|
return 1;
|
2011-03-17 16:38:21 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2020-10-05 17:03:14 +00:00
|
|
|
unsigned char *pBuffer = (unsigned char *)malloc((size_t)Png.width * Png.height * sizeof(unsigned char) * 4);
|
2020-09-20 16:42:17 +00:00
|
|
|
|
2020-09-30 16:03:06 +00:00
|
|
|
Error = png_get_data(&Png, pBuffer);
|
|
|
|
if(Error != PNG_NO_ERROR)
|
|
|
|
{
|
2021-11-05 16:21:41 +00:00
|
|
|
dbg_msg("map_convert_07", "failed to read image. filename='%s', pnglite: %s", pFilename, png_error_string(Error));
|
2020-09-30 16:03:06 +00:00
|
|
|
free(pBuffer);
|
2021-11-05 16:21:41 +00:00
|
|
|
io_close(File);
|
2020-09-30 16:03:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2021-11-05 16:21:41 +00:00
|
|
|
io_close(File);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-03-17 16:38:21 +00:00
|
|
|
int w = Png.width;
|
|
|
|
int h = Png.height;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2020-09-20 16:42:17 +00:00
|
|
|
DilateImage(pBuffer, w, h, 4);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-03-17 16:38:21 +00:00
|
|
|
// save here
|
2021-11-05 16:21:41 +00:00
|
|
|
File = io_open(pFilename, IOFLAG_WRITE);
|
|
|
|
if(!File)
|
|
|
|
{
|
|
|
|
dbg_msg("dilate", "failed to open file. filename='%s'", pFilename);
|
|
|
|
free(pBuffer);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
Error = png_open_write(&Png, 0, File);
|
|
|
|
if(Error != PNG_NO_ERROR)
|
|
|
|
{
|
|
|
|
dbg_msg("dilate", "failed to open image file. filename='%s', pnglite: %s", pFilename, png_error_string(Error));
|
|
|
|
io_close(File);
|
|
|
|
return 0;
|
|
|
|
}
|
2020-09-20 16:42:17 +00:00
|
|
|
png_set_data(&Png, w, h, 8, PNG_TRUECOLOR_ALPHA, (unsigned char *)pBuffer);
|
2021-11-05 16:21:41 +00:00
|
|
|
io_close(File);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2020-09-20 16:42:17 +00:00
|
|
|
free(pBuffer);
|
|
|
|
|
2011-03-17 16:38:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2011-07-09 09:45:01 +00:00
|
|
|
|
|
|
|
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-07-09 09:45:01 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2011-08-11 08:59:14 +00:00
|
|
|
|
2011-07-11 09:26:41 +00:00
|
|
|
for(int i = 1; i < argc; i++)
|
|
|
|
DilateFile(argv[i]);
|
|
|
|
return 0;
|
2011-07-09 09:45:01 +00:00
|
|
|
}
|