X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=scripts%2Fmaketex.py;h=916ce747c404f8b26210078a0e07b7d53f8b5fbf;hb=4db19012183dc1131c1e3bcc88a555132c245cae;hp=4da7866e7593b2f3abdfae7eaaa8e4254cd193f1;hpb=5a93cc603eef43617a10b76bc9c19a3272ac1d49;p=libs%2Fgl.git diff --git a/scripts/maketex.py b/scripts/maketex.py index 4da7866e..916ce747 100755 --- a/scripts/maketex.py +++ b/scripts/maketex.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 def escape(str): result = "" @@ -8,13 +8,13 @@ def escape(str): elif c=='\\': result += '\\\\' elif ord(c)<0x20: - result += "\\%03o"%ord(c) + result += "\\{:03o}".format(ord(c)) else: result += c - return result; + return result def make_tex(fn, filter="LINEAR", anisotropy=0, wrap=None, srgb=False): - import Image + from PIL import Image img = Image.open(fn) @@ -27,19 +27,22 @@ def make_tex(fn, filter="LINEAR", anisotropy=0, wrap=None, srgb=False): if srgb: fmt = "S"+fmt - result = "storage %s %d %d;\n"%(fmt, img.size[0], img.size[1]) - result += "filter %s;\n"%filter + result = "storage {} {} {};\n".format(fmt, img.size[0], img.size[1]) + result += "filter {};\n".format(filter) if "MIPMAP" in filter: result += "generate_mipmap true;\n" if anisotropy: - result += "max_anisotropy %d;\n"%anisotropy + result += "max_anisotropy {};\n".format(anisotropy) if wrap: - result += "wrap %s;\n"%wrap + result += "wrap {};\n".format(wrap) result += "raw_data \"" data = list(img.getdata()) for y in range(img.size[1]): i = (img.size[1]-1-y)*img.size[0] - result += escape("".join(["".join([chr(v) for v in p]) for p in data[i:i+img.size[0]]])) + if fmt=="LUMINANCE" or fmt=="SLUMINANCE": + result += escape("".join([chr(v) for v in data[i:i+img.size[0]]])) + else: + result += escape("".join(["".join([chr(v) for v in p]) for p in data[i:i+img.size[0]]])) result += "\";\n" return result @@ -65,5 +68,5 @@ if __name__=="__main__": out_fn = args.output if not out_fn: out_fn = os.path.splitext(args.image)[0]+".tex2d" - out = file(out_fn, "w") + out = open(out_fn, "w") out.write(make_tex(args.image, filter, args.anisotropy, args.wrap, args.srgb))