archive/wad2, image/lmp, image/spr, data/q3shader, data/q3skin
WAD2 / WAD3 with miptex / qpic / conchars / font / palette images and addImage; Quake .lmp pictures, palette and colormap (palette never embedded); Quake / Half-Life / SPR32 sprites with frame groups; Quake III shader scripts and .skin files. Miptex gains qpic decode / encode and palette mapping; Pixels.keyed keeps the key colour (alpha 0).
This commit is contained in:
1 parent
67e116a6c6
commit
175ca9e823
23 files changed
+5380
-1143
No files matched your search
@@ -0,0 +1,39 @@
|
||||
# image/lmp fixtures (tools/fixtures.py): qpic .lmp pictures, a palette.lmp and a colormap.lmp written from wad.h /
|
||||
# draw.c; reference rgba from Pillow (a "P" image with the palette, index 255 transparent for qpics). The palette is
|
||||
# random: Quake's own is GPL and never committed.
|
||||
# tests/gen/lmp.luau { palette, pics = { { name, data, w, h, crc, crcOpaque } }, colormap = { data, crc }, palcrc }
|
||||
import json, struct, zlib
|
||||
|
||||
CODE = r"""
|
||||
import json, sys, zlib, io
|
||||
from PIL import Image
|
||||
job = json.loads(sys.stdin.read())
|
||||
out = {}
|
||||
pal = bytes.fromhex(job["pal"])
|
||||
for k, (w, h, hexpix, key) in job["imgs"].items():
|
||||
im = Image.frombytes("P", (w, h), bytes.fromhex(hexpix))
|
||||
im.putpalette(pal)
|
||||
if key is not None:
|
||||
im.info["transparency"] = key
|
||||
out[k] = zlib.crc32(im.convert("RGBA").tobytes())
|
||||
print(json.dumps(out))
|
||||
"""
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
rng = ctx.rng(31)
|
||||
pal = bytes(rng.randrange(256) for _ in range(768))
|
||||
imgs, pics = {}, []
|
||||
for name, w, h in (("disc", 24, 24), ("conback", 64, 40), ("num_0", 24, 24), ("wide", 3, 1)):
|
||||
pix = bytes(rng.randrange(256) for _ in range(w * h))
|
||||
imgs[name] = [w, h, pix.hex(), 255]
|
||||
imgs[name + "_o"] = [w, h, pix.hex(), None]
|
||||
pics.append({"name": name, "data": struct.pack("<II", w, h) + pix, "w": w, "h": h})
|
||||
cmap = bytes(rng.randrange(256) for _ in range(64 * 256)) + b"\0"
|
||||
imgs["colormap"] = [256, 64, cmap[:16384].hex(), None]
|
||||
imgs["palette"] = [16, 16, bytes(range(256)).hex(), None]
|
||||
ref = json.loads(ctx.python(["pillow"], CODE, input=json.dumps({"pal": pal.hex(), "imgs": imgs}).encode()))
|
||||
for p in pics:
|
||||
p["crc"] = ref[p["name"]]
|
||||
p["crcOpaque"] = ref[p["name"] + "_o"]
|
||||
ctx.emit("lmp", {"palette": pal, "pics": pics, "colormap": {"data": cmap, "crc": ref["colormap"]}, "palcrc": ref["palette"]})
|
||||
Reference in new issue
Block a user