result += c
return result
-def make_tex(fn, filter="LINEAR", anisotropy=0, wrap=None, srgb=False):
+def make_tex(fn, mipmap=False, srgb=False):
from PIL import Image
img = Image.open(fn)
fmt = "".join(img.getbands())
if fmt=="LA":
- fmt = "LUMINANCE_ALPHA"
+ fmt = "LUMINANCE8_ALPHA8"
elif fmt=="L":
- fmt = "LUMINANCE"
+ fmt = "LUMINANCE8"
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:
+ if mipmap:
result += "generate_mipmap true;\n"
- if anisotropy:
- result += "max_anisotropy {};\n".format(anisotropy)
- if 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]
- if fmt=="LUMINANCE" or fmt=="SLUMINANCE":
+ if len(img.getbands())==1:
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]]]))
parser = argparse.ArgumentParser()
parser.add_argument("-o", "--output", metavar="FILE", help="Output filename")
- 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("-m", "--mipmap", action="store_true", help="Enable mipmaps")
parser.add_argument("--srgb", action="store_const", const=True, help="Use sRGB color space")
parser.add_argument("image")
args = parser.parse_args()
- filter = args.filter
- if filter=="MIPMAP":
- filter = "LINEAR_MIPMAP_LINEAR"
-
out_fn = args.output
if not out_fn:
out_fn = os.path.splitext(args.image)[0]+".tex2d"
out = open(out_fn, "w")
- out.write(make_tex(args.image, filter, args.anisotropy, args.wrap, args.srgb))
+ out.write(make_tex(args.image, args.mipmap, args.srgb))