"""A coloured Freelancer interface image (.3db) from a PNG -- for pictures in the REM windows (statistics medals, banners, portraits), shown with a StaticControl like the inventory's item icons. Unlike make_icon_3db.py the colours stay and the quad keeps the picture's aspect. python tools/make_image_3db.py [--size 256] [--nocrop] [--crop x0,y0,x1,y1] The transparent border is cut off (unless --nocrop), the picture is stretched into a square texture of --size pixels (three mips) and drawn on a quad of the picture's aspect, the longer side as long as the retail icon quad. --crop cuts that pixel rectangle out first (a banner strip from a square picture). gives the material "UI_REMIMG_", the texture "REMIMG_.tga" and the mesh library "rem_img_.lod0.vms". """ import os import struct import sys sys.path.insert(0, os.path.dirname(__file__)) import flcrc # noqa: E402 import make_icon_3db as icon # noqa: E402 import utf # noqa: E402 HALF = icon.QUAD_HALF Z = icon.QUAD_Z INDICES = [0, 1, 2, 1, 3, 2] def crop(w, h, rows): xs = [x for line in rows for x, p in enumerate(line) if p[3] > 8] ys = [y for y, line in enumerate(rows) if any(p[3] > 8 for p in line)] if not xs: return w, h, rows x0, x1, y0, y1 = min(xs), max(xs) + 1, min(ys), max(ys) + 1 return x1 - x0, y1 - y0, [line[x0:x1] for line in rows[y0:y1]] def make(png, out, name, size=256, do_crop=True, rect=None): w, h, rows = icon.read_png(png) if rect is not None: x0, y0, x1, y1 = rect w, h, rows = x1 - x0, y1 - y0, [line[x0:x1] for line in rows[y0:y1]] if do_crop: w, h, rows = crop(w, h, rows) hx, hy = (HALF, HALF * h / w) if w >= h else (HALF * w / h, HALF) quad = [(-hx, hy, Z, 0.0, 1.0), (-hx, -hy, Z, 0.0, 0.0), (hx, hy, Z, 1.0, 1.0), (hx, -hy, Z, 1.0, 0.0)] mips = [] s = size for _ in range(3): mips.append(icon.tga(icon.resample(w, h, rows, s))) s = max(4, s // 2) material = 'UI_REMIMG_' + name texture = 'REMIMG_' + name + '.tga' library = 'rem_img_' + name.lower() + '.lod0.vms' data = struct.pack('