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. */
|
2022-04-22 23:04:48 +00:00
|
|
|
#include <base/logger.h>
|
2020-09-20 16:42:17 +00:00
|
|
|
#include <base/system.h>
|
2022-06-21 13:26:23 +00:00
|
|
|
#include <engine/gfx/image_loader.h>
|
|
|
|
#include <engine/gfx/image_manipulation.h>
|
2022-06-11 07:09:42 +00:00
|
|
|
#include <engine/graphics.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
|
|
|
{
|
2021-11-05 16:21:41 +00:00
|
|
|
IOHANDLE File = io_open(pFilename, IOFLAG_READ);
|
2022-06-11 07:09:42 +00:00
|
|
|
if(File)
|
2021-11-05 16:21:41 +00:00
|
|
|
{
|
2022-06-11 07:09:42 +00:00
|
|
|
io_seek(File, 0, IOSEEK_END);
|
|
|
|
unsigned int FileSize = io_tell(File);
|
|
|
|
io_seek(File, 0, IOSEEK_START);
|
|
|
|
TImageByteBuffer ByteBuffer;
|
|
|
|
SImageByteBuffer ImageByteBuffer(&ByteBuffer);
|
|
|
|
|
|
|
|
ByteBuffer.resize(FileSize);
|
|
|
|
io_read(File, &ByteBuffer.front(), FileSize);
|
2022-06-01 11:43:33 +00:00
|
|
|
|
2021-11-05 16:21:41 +00:00
|
|
|
io_close(File);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2022-06-11 07:09:42 +00:00
|
|
|
CImageInfo Img;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2022-06-11 07:09:42 +00:00
|
|
|
uint8_t *pImgBuffer = NULL;
|
|
|
|
EImageFormat ImageFormat;
|
2022-06-27 14:57:23 +00:00
|
|
|
int PngliteIncompatible;
|
|
|
|
if(LoadPNG(ImageByteBuffer, pFilename, PngliteIncompatible, Img.m_Width, Img.m_Height, pImgBuffer, ImageFormat))
|
2022-06-11 07:09:42 +00:00
|
|
|
{
|
|
|
|
if(ImageFormat != IMAGE_FORMAT_RGBA)
|
|
|
|
{
|
|
|
|
free(pImgBuffer);
|
|
|
|
dbg_msg("dilate", "%s: not an RGBA image", pFilename);
|
|
|
|
return -1;
|
|
|
|
}
|
2020-09-20 16:42:17 +00:00
|
|
|
|
2022-06-11 07:09:42 +00:00
|
|
|
Img.m_pData = pImgBuffer;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2022-06-11 07:09:42 +00:00
|
|
|
unsigned char *pBuffer = (unsigned char *)Img.m_pData;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2022-06-11 07:09:42 +00:00
|
|
|
int w = Img.m_Width;
|
|
|
|
int h = Img.m_Height;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2022-06-11 07:09:42 +00:00
|
|
|
DilateImage(pBuffer, w, h, 4);
|
|
|
|
|
|
|
|
// save here
|
|
|
|
IOHANDLE SaveFile = io_open(pFilename, IOFLAG_WRITE);
|
|
|
|
if(SaveFile)
|
|
|
|
{
|
|
|
|
TImageByteBuffer ByteBuffer2;
|
|
|
|
SImageByteBuffer ImageByteBuffer2(&ByteBuffer2);
|
|
|
|
|
|
|
|
if(SavePNG(IMAGE_FORMAT_RGBA, (const uint8_t *)pBuffer, ImageByteBuffer2, w, h))
|
|
|
|
io_write(SaveFile, &ByteBuffer2.front(), ByteBuffer2.size());
|
|
|
|
io_close(SaveFile);
|
|
|
|
|
|
|
|
free(pBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dbg_msg("dilate", "failed unknown image format: %s", pFilename);
|
|
|
|
return -1;
|
|
|
|
}
|
2021-11-05 16:21:41 +00:00
|
|
|
}
|
2022-06-11 07:09:42 +00:00
|
|
|
else
|
2021-11-05 16:21:41 +00:00
|
|
|
{
|
2022-06-11 07:09:42 +00:00
|
|
|
dbg_msg("dilate", "failed to open image file. filename='%s'", pFilename);
|
|
|
|
return -1;
|
2021-11-05 16:21:41 +00:00
|
|
|
}
|
2020-09-20 16:42:17 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2022-06-13 16:07:29 +00:00
|
|
|
CCmdlineFix CmdlineFix(&argc, &argv);
|
2022-04-22 23:04:48 +00:00
|
|
|
log_set_global_logger_default();
|
2011-07-09 09:45:01 +00:00
|
|
|
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]);
|
2022-06-05 14:43:00 +00:00
|
|
|
|
2011-07-11 09:26:41 +00:00
|
|
|
return 0;
|
2011-07-09 09:45:01 +00:00
|
|
|
}
|