-
Notifications
You must be signed in to change notification settings - Fork 2
/
genresheader.py
executable file
·41 lines (35 loc) · 1.12 KB
/
genresheader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
import sys
import os
import glob
header = [ "#ifndef WXINCLUDE_IMAGES_H\n",
"#define WXINCLUDE_IMAGES_H\n",
"\n",
"#include <wx/wxprec.h>\n",
"#ifndef WX_PRECOMP\n",
"#include <wx/wx.h>\n",
"#endif\n",
"#include <wx/mstream.h>\n",
"\n",
"#define wxMEMORY_BITMAPEX(name, type) \\\n",
" _wxConvertMemoryToBitmap(name, sizeof(name), type)\n",
"\n",
"inline wxBitmap _wxConvertMemoryToBitmap(const unsigned char* data, int length,\n",
" long type = wxBITMAP_TYPE_ANY) {\n",
" wxMemoryInputStream stream(data, length);\n",
" return wxBitmap(wxImage(stream, type, -1), -1);\n",
"}\n",
"\n" ]
footer = "#endif /* WXINCLUDE_IMAGES_H */\n"
with open(sys.argv[1], "w+") as f:
f.writelines(header)
for png in glob.iglob(os.path.join(sys.argv[2], "*.png")):
name = os.path.splitext(os.path.basename(png))[0]
f.write("static const unsigned char " + name + "[] = {\n")
with open(png, "rb") as image:
data = image.read()
for byte in data:
f.write(hex(ord(byte)))
f.write(",")
f.write("\n};\n\n")
f.write(footer)