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,82 @@
|
||||
# image/spr fixtures (tools/fixtures.py): sprites written from spritegn.h (Quake IDSP 1: two single frames and a
|
||||
# group of three; Half-Life IDSP 2 with its palette, alpha test and index alpha; DarkPlaces SPR32); expected frame
|
||||
# pixels (rgba CRCs), canvas positions from the frame origins, and group delays from the cumulative intervals.
|
||||
# tests/gen/spr.luau { palette, sprites = { { name, data, version, w, h, origin, frames = { { x, y, w, h, crc, delay } } } } }
|
||||
import struct, zlib
|
||||
|
||||
|
||||
def frame_bytes(rng, w, h, bpp):
|
||||
return bytes(rng.randrange(256) for _ in range(w * h * bpp))
|
||||
|
||||
|
||||
def rgba(pix, pal, key=None, mode=None):
|
||||
out = bytearray()
|
||||
for i in pix:
|
||||
if mode == "indexalpha":
|
||||
out += pal[255 * 3:255 * 3 + 3] + bytes([i])
|
||||
elif key is not None and i == key:
|
||||
out += pal[i * 3:i * 3 + 3] + b"\0"
|
||||
else:
|
||||
out += pal[i * 3:i * 3 + 3] + b"\xff"
|
||||
return zlib.crc32(bytes(out))
|
||||
|
||||
|
||||
def sprite(rng, version, layout, pal, tex=3):
|
||||
# layout: list of ("single", (ox, oy, w, h)) or ("group", [intervals], [(ox, oy, w, h)])
|
||||
singles = []
|
||||
body = b""
|
||||
frames = []
|
||||
for item in layout:
|
||||
if item[0] == "single":
|
||||
body += struct.pack("<i", 0)
|
||||
entries = [(item[1], 0.1)]
|
||||
else:
|
||||
ivs = item[1]
|
||||
body += struct.pack("<ii", 1, len(ivs)) + b"".join(struct.pack("<f", v) for v in ivs)
|
||||
entries = [(f, ivs[k] - (ivs[k - 1] if k else 0)) for k, f in enumerate(item[2])]
|
||||
for (ox, oy, w, h), delay in entries:
|
||||
pix = frame_bytes(rng, w, h, 4 if version == 32 else 1)
|
||||
body += struct.pack("<iiii", ox, oy, w, h) + pix
|
||||
if version == 32:
|
||||
crc = zlib.crc32(pix)
|
||||
elif version == 2 and tex == 2:
|
||||
crc = rgba(pix, pal, mode="indexalpha")
|
||||
elif version == 2 and tex != 3:
|
||||
crc = rgba(pix, pal)
|
||||
else:
|
||||
crc = rgba(pix, pal, 255)
|
||||
frames.append({"ox": ox, "oy": oy, "w": w, "h": h, "crc": crc, "delay": struct.unpack("<f", struct.pack("<f", delay))[0]})
|
||||
n = len(layout)
|
||||
mw = max(f["w"] for f in frames)
|
||||
mh = max(f["h"] for f in frames)
|
||||
if version == 2:
|
||||
head = b"IDSP" + struct.pack("<iiifiiifi", 2, 2, tex, 16.0, mw, mh, n, 0.0, 0) + struct.pack("<H", 256) + pal
|
||||
else:
|
||||
head = b"IDSP" + struct.pack("<iifiiifi", version, 2, 16.0, mw, mh, n, 0.0, 0)
|
||||
minx = min(f["ox"] for f in frames)
|
||||
maxy = max(f["oy"] for f in frames)
|
||||
for f in frames:
|
||||
f["x"], f["y"] = f["ox"] - minx, maxy - f["oy"]
|
||||
w = max(f["ox"] + f["w"] for f in frames) - minx
|
||||
h = maxy - min(f["oy"] - f["h"] for f in frames)
|
||||
return {"data": head + body, "version": version, "w": w, "h": h, "origin": [-minx, maxy], "frames": frames}
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
rng = ctx.rng(64)
|
||||
pal = bytes(rng.randrange(256) for _ in range(768))
|
||||
hlpal = bytes(rng.randrange(256) for _ in range(768))
|
||||
sprites = []
|
||||
q = sprite(rng, 1, [("single", (-8, 8, 16, 16)), ("single", (-12, 20, 24, 28)),
|
||||
("group", [0.1, 0.25, 0.5], [(-4, 4, 8, 8), (-6, 6, 12, 12), (-8, 10, 16, 20)])], pal)
|
||||
q["name"] = "quake"
|
||||
sprites.append(q)
|
||||
for tex, name in ((3, "hl_alphatest"), (2, "hl_indexalpha"), (0, "hl_normal")):
|
||||
s = sprite(rng, 2, [("single", (-16, 16, 32, 32)), ("single", (-10, 12, 20, 24))], hlpal, tex)
|
||||
s["name"] = name
|
||||
s["tex"] = tex
|
||||
sprites.append(s)
|
||||
s32 = sprite(rng, 32, [("single", (-5, 5, 10, 10)), ("group", [0.2, 0.4], [(-5, 5, 10, 10), (-3, 9, 6, 12)])], pal)
|
||||
s32["name"] = "spr32"
|
||||
sprites.append(s32)
|
||||
ctx.emit("spr", {"palette": pal, "hlpalette": hlpal, "sprites": sprites})
|
||||
Reference in new issue
Block a user