X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=scripts%2Fmaketex.py;h=916ce747c404f8b26210078a0e07b7d53f8b5fbf;hb=4db19012183dc1131c1e3bcc88a555132c245cae;hp=04de1d38a57d51cc2e25c2ea16f8e5896481283a;hpb=869a1d1bcdeea9908664d3901b5b6b34634d833b;p=libs%2Fgl.git diff --git a/scripts/maketex.py b/scripts/maketex.py index 04de1d38..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): - import Image +def make_tex(fn, filter="LINEAR", anisotropy=0, wrap=None, srgb=False): + from PIL import Image img = Image.open(fn) @@ -24,19 +24,25 @@ def make_tex(fn, filter="LINEAR", anisotropy=0, wrap=None): elif fmt=="L": fmt = "LUMINANCE" - result = "storage %s %d %d;\n"%(fmt, img.size[0], img.size[1]) - result += "filter %s;\n"%filter + if srgb: + fmt = "S"+fmt + + 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 @@ -50,6 +56,7 @@ if __name__=="__main__": parser.add_argument("-f", "--filter", choices=["NEAREST", "LINEAR", "MIPMAP"], default="LINEAR", help="Filtering mode") parser.add_argument("-a", "--anisotropy", metavar="NUMBER", help="Maximum anisotropy, 0 = disable") parser.add_argument("-w", "--wrap", choices=["REPEAT", "CLAMP_TO_EDGE", "MIRRORED_REPEAT"], help="Wrapping mode") + parser.add_argument("--srgb", action="store_const", const=True, help="Use sRGB color space") parser.add_argument("image") args = parser.parse_args() @@ -61,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.write(make_tex(args.image, filter, args.anisotropy, args.wrap)) + out = open(out_fn, "w") + out.write(make_tex(args.image, filter, args.anisotropy, args.wrap, args.srgb))