]> git.tdb.fi Git - libs/gl.git/blobdiff - maketex.py
Make the use of DevIL optional
[libs/gl.git] / maketex.py
diff --git a/maketex.py b/maketex.py
new file mode 100755 (executable)
index 0000000..17012c8
--- /dev/null
@@ -0,0 +1,36 @@
+#!/usr/bin/python
+
+# $Id$
+
+import Image
+import sys
+import os
+
+def escape(str):
+       result=""
+       for c in str:
+               if c=='"':
+                       result+='\\"'
+               elif c=='\\':
+                       result+='\\\\'
+               elif ord(c)<0x20:
+                       result+="\\%03o"%ord(c)
+               else:
+                       result+=c
+       return result;
+
+img=Image.open(sys.argv[1])
+out=file(os.path.splitext(sys.argv[1])[0]+".tex", "w")
+fmt="".join(img.getbands())
+if fmt=="LA":
+       fmt="LUMINANCE_ALPHA"
+elif fmt=="L":
+       fmt="LUMINANCE"
+out.write("storage %s %d %d 0;\n"%(fmt, img.size[0], img.size[1]))
+out.write("min_filter LINEAR;\n")
+out.write("raw_data \"")
+data=list(img.getdata())
+for y in range(img.size[1]):
+       i=(img.size[1]-1-y)*img.size[0]
+       out.write(escape("".join(["".join([chr(v) for v in p]) for p in data[i:i+img.size[0]]])))
+out.write("\";\n")