~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/tools/MakeGLStipple.py

  • Committer: Reinhard Tartler
  • Date: 2014-05-31 01:50:05 UTC
  • mfrom: (14.2.27 sid)
  • Revision ID: siretart@tauware.de-20140531015005-ml6druahuj82nsav
mergeĀ fromĀ debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# ##### BEGIN GPL LICENSE BLOCK #####
2
 
#
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.
7
 
#
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.
12
 
#
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.
16
 
#
17
 
# ##### END GPL LICENSE BLOCK #####
18
 
 
19
 
# <pep8-80 compliant>
20
 
 
21
 
# Converts 32x32 XPM images written be the gimp to GL stipples
22
 
# takes XPM files as arguments, prints out C style definitions.
23
 
 
24
 
import sys
25
 
import os
26
 
 
27
 
 
28
 
def main():
29
 
    xpm_ls = [f for f in sys.argv[1:] if f.lower().endswith(".xpm")]
30
 
 
31
 
    print("Converting: " + " ".join(xpm_ls))
32
 
 
33
 
    for xpm in xpm_ls:
34
 
        f = open(xpm, "r")
35
 
        data = f.read()
36
 
        f.close()
37
 
 
38
 
        # all after first {
39
 
        data = data.split("{", 1)[1]
40
 
 
41
 
        # all before first }
42
 
        data = data.rsplit("}", 1)[0]
43
 
 
44
 
        data = data.replace("\n", "")
45
 
 
46
 
        data = data.split(",")
47
 
 
48
 
        w, h, c, dummy = map(int, data[0].strip("\"").split())
49
 
 
50
 
        if w != 32 or h != 32 or c != 2:
51
 
            print("Skipping %r, expected 32x32, monochrome, got %s" %
52
 
                  (xpm, data[0]))
53
 
            continue
54
 
 
55
 
        # col_1 = data[1][1]
56
 
        col_2 = data[2][1]
57
 
 
58
 
        data = [d[1:-1] for d in data[3:]]
59
 
 
60
 
        bits = []
61
 
 
62
 
        for d in data:
63
 
            for i, c in enumerate(d):
64
 
                bits.append('01'[(c == col_2)])
65
 
 
66
 
        if len(bits) != 1024:
67
 
            print("Skipping %r, expected 1024 bits, got %d" %
68
 
                  (xpm, len(bits)))
69
 
            continue
70
 
 
71
 
        bits = "".join(bits)
72
 
 
73
 
        chars = []
74
 
 
75
 
        for i in range(0, len(bits), 8):
76
 
            chars.append("0x%.2x" % int(bits[i:i + 8], 2))
77
 
 
78
 
        fout = sys.stdout
79
 
 
80
 
        var = os.path.basename(xpm)
81
 
        var = os.path.splitext(var)[0]
82
 
 
83
 
        fout.write("GLubyte stipple_%s[128] {\n\t" % var)
84
 
        for i, c in enumerate(chars):
85
 
            if i != 127:
86
 
                fout.write("%s, " % c)
87
 
            else:
88
 
                fout.write("%s" % c)
89
 
 
90
 
            if not ((i + 1) % 8):
91
 
                fout.write("\n\t")
92
 
        fout.write("};\n")
93
 
 
94
 
 
95
 
if __name__ == "__main__":
96
 
    main()