1 /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2 /* If you are missing that file, acquire a complete release at teeworlds.com. */
3 #include <base/system.h>
5 #include <engine/external/pnglite/pnglite.h>
9 unsigned char r
, g
, b
, a
;
12 static void Dilate(int w
, int h
, CPixel
*pSrc
, CPixel
*pDest
)
15 const int xo
[] = {0, -1, 1, 0};
16 const int yo
[] = {-1, 0, 0, 1};
19 for(int y
= 0; y
< h
; y
++)
21 for(int x
= 0; x
< w
; x
++, m
++)
27 for(int c
= 0; c
< 4; c
++)
29 ix
= clamp(x
+ xo
[c
], 0, w
-1);
30 iy
= clamp(y
+ yo
[c
], 0, h
-1);
43 static void CopyAlpha(int w
, int h
, CPixel
*pSrc
, CPixel
*pDest
)
46 for(int y
= 0; y
< h
; y
++)
47 for(int x
= 0; x
< w
; x
++, m
++)
48 pDest
[m
].a
= pSrc
[m
].a
;
51 int DilateFile(const char *pFileName
)
54 CPixel
*pBuffer
[3] = {0,0,0};
57 png_open_file(&Png
, pFileName
);
59 if(Png
.color_type
!= PNG_TRUECOLOR_ALPHA
)
61 dbg_msg("dilate", "%s: not an RGBA image", pFileName
);
65 pBuffer
[0] = (CPixel
*)mem_alloc(Png
.width
*Png
.height
*sizeof(CPixel
), 1);
66 pBuffer
[1] = (CPixel
*)mem_alloc(Png
.width
*Png
.height
*sizeof(CPixel
), 1);
67 pBuffer
[2] = (CPixel
*)mem_alloc(Png
.width
*Png
.height
*sizeof(CPixel
), 1);
68 png_get_data(&Png
, (unsigned char *)pBuffer
[0]);
74 Dilate(w
, h
, pBuffer
[0], pBuffer
[1]);
75 for(int i
= 0; i
< 5; i
++)
77 Dilate(w
, h
, pBuffer
[1], pBuffer
[2]);
78 Dilate(w
, h
, pBuffer
[2], pBuffer
[1]);
81 CopyAlpha(w
, h
, pBuffer
[0], pBuffer
[1]);
84 png_open_file_write(&Png
, pFileName
);
85 png_set_data(&Png
, w
, h
, 8, PNG_TRUECOLOR_ALPHA
, (unsigned char *)pBuffer
[1]);
91 int main(int argc
, const char **argv
)
96 dbg_msg("Usage", "%s FILE1 [ FILE2... ]", argv
[0]);
100 for(int i
= 1; i
< argc
; i
++)