1
# ##### BEGIN GPL LICENSE BLOCK #####
3
# This program is free software; you can redistribute it and/or
4
# modify it under the terms of the GNU General Public License
5
# as published by the Free Software Foundation; either version 2
6
# of the License, or (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software Foundation,
15
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
# ##### END GPL LICENSE BLOCK #####
21
# Converts 32x32 XPM images written be the gimp to GL stipples
22
# takes XPM files as arguments, prints out C style definitions.
29
xpm_ls = [f for f in sys.argv[1:] if f.lower().endswith(".xpm")]
31
print("Converting: " + " ".join(xpm_ls))
39
data = data.split("{", 1)[1]
42
data = data.rsplit("}", 1)[0]
44
data = data.replace("\n", "")
46
data = data.split(",")
48
w, h, c, dummy = map(int, data[0].strip("\"").split())
50
if w != 32 or h != 32 or c != 2:
51
print("Skipping %r, expected 32x32, monochrome, got %s" %
58
data = [d[1:-1] for d in data[3:]]
63
for i, c in enumerate(d):
64
bits.append('01'[(c == col_2)])
67
print("Skipping %r, expected 1024 bits, got %d" %
75
for i in range(0, len(bits), 8):
76
chars.append("0x%.2x" % int(bits[i:i + 8], 2))
80
var = os.path.basename(xpm)
81
var = os.path.splitext(var)[0]
83
fout.write("GLubyte stipple_%s[128] {\n\t" % var)
84
for i, c in enumerate(chars):
86
fout.write("%s, " % c)
95
if __name__ == "__main__":