]> git.tdb.fi Git - libs/gl.git/blob - maketex.py
Blender exporter:
[libs/gl.git] / maketex.py
1 #!/usr/bin/python
2
3 # $Id$
4
5 import Image
6 import sys
7 import os
8
9 def escape(str):
10         result=""
11         for c in str:
12                 if c=='"':
13                         result+='\\"'
14                 elif c=='\\':
15                         result+='\\\\'
16                 elif ord(c)<0x20:
17                         result+="\\%03o"%ord(c)
18                 else:
19                         result+=c
20         return result;
21
22 img=Image.open(sys.argv[1])
23 out=file(os.path.splitext(sys.argv[1])[0]+".tex", "w")
24 fmt="".join(img.getbands())
25 if fmt=="LA":
26         fmt="LUMINANCE_ALPHA"
27 elif fmt=="L":
28         fmt="LUMINANCE"
29 out.write("storage %s %d %d 0;\n"%(fmt, img.size[0], img.size[1]))
30 out.write("min_filter LINEAR;\n")
31 out.write("raw_data \"")
32 data=list(img.getdata())
33 for y in range(img.size[1]):
34         i=(img.size[1]-1-y)*img.size[0]
35         out.write(escape("".join(["".join([chr(v) for v in p]) for p in data[i:i+img.size[0]]])))
36 out.write("\";\n")