11 result += "\\%03o"%ord(c)
16 def make_tex(fn, filter="LINEAR", anisotropy=0, wrap=None, srgb=False):
21 fmt = "".join(img.getbands())
23 fmt = "LUMINANCE_ALPHA"
30 result = "storage %s %d %d;\n"%(fmt, img.size[0], img.size[1])
31 result += "filter %s;\n"%filter
32 if "MIPMAP" in filter:
33 result += "generate_mipmap true;\n"
35 result += "max_anisotropy %d;\n"%anisotropy
37 result += "wrap %s;\n"%wrap
38 result += "raw_data \""
39 data = list(img.getdata())
40 for y in range(img.size[1]):
41 i = (img.size[1]-1-y)*img.size[0]
42 result += escape("".join(["".join([chr(v) for v in p]) for p in data[i:i+img.size[0]]]))
47 if __name__=="__main__":
51 parser = argparse.ArgumentParser()
52 parser.add_argument("-o", "--output", metavar="FILE", help="Output filename")
53 parser.add_argument("-f", "--filter", choices=["NEAREST", "LINEAR", "MIPMAP"], default="LINEAR", help="Filtering mode")
54 parser.add_argument("-a", "--anisotropy", metavar="NUMBER", help="Maximum anisotropy, 0 = disable")
55 parser.add_argument("-w", "--wrap", choices=["REPEAT", "CLAMP_TO_EDGE", "MIRRORED_REPEAT"], help="Wrapping mode")
56 parser.add_argument("--srgb", action="store_const", const=True, help="Use sRGB color space")
57 parser.add_argument("image")
59 args = parser.parse_args()
63 filter = "LINEAR_MIPMAP_LINEAR"
67 out_fn = os.path.splitext(args.image)[0]+".tex2d"
68 out = file(out_fn, "w")
69 out.write(make_tex(args.image, filter, args.anisotropy, args.wrap, args.srgb))