codecs/model/Brush, codecs/model/Patch, codecs/image/Miptex; Pixels palette helpers
Brush: plane brushes -> polygons (qbsp-style clipping), Quake standard / Valve 220 / brush-primitive projection, optional coplanar merge and CSG hull; tested against ericw-tools qbsp -nofill (area per plane, texels per corner). Patch: Bezier control grids moved out of model/bsp/Quake3, per-axis subdivisions (patchDef2 / patchDef3), normals. Miptex: Quake / GoldSrc miptex decode / encode and the WAD2 / WAD3 directory (model/bsp uses it now). Pixels: grey, keyed, colorList, colormap, paletteBytes. STYLE: layout block and 2a table list the new modules.
This commit is contained in:
1 parent
01c044805f
commit
5ad934565d
19 files changed
+4520
-923
No files matched your search
@@ -1,8 +1,9 @@
|
||||
--!strict
|
||||
--!native
|
||||
--!optimize 2
|
||||
-- codecs/image/Pixels: row loops between packed pixel layouts and rgba8 for BMP / DIB.
|
||||
-- Indexed, BGR(A), 5-5-5, bit masks, RLE4 / RLE8. From bmp-luau b86aed6 (same author); the encoder loops are new.
|
||||
-- codecs/image/Pixels: row loops between packed pixel layouts and rgba8 for BMP / DIB, and palette helpers.
|
||||
-- Indexed, BGR(A), 5-5-5, bit masks, RLE4 / RLE8; palettes: keyed index (Quake 255), grey ramp, Quake colormap light
|
||||
-- levels. From bmp-luau b86aed6 (same author); the encoder loops and palette helpers are new.
|
||||
local readu8, readu16, readu32, writeu32, writeu8 = buffer.readu8, buffer.readu16, buffer.readu32, buffer.writeu32, buffer.writeu8
|
||||
local band, rshift, bor, lshift = bit32.band, bit32.rshift, bit32.bor, bit32.lshift
|
||||
|
||||
@@ -259,4 +260,59 @@ function Pixels.colours(src: buffer, n: number, max: number): ({ number }, boole
|
||||
return list, alpha
|
||||
end
|
||||
|
||||
-- a 256-entry rgba8 palette (u32 LE per entry) with entry i = { i, i, i, 255 }
|
||||
function Pixels.grey(): buffer
|
||||
local pal = buffer.create(1024)
|
||||
for i = 0, 255 do
|
||||
writeu32(pal, i * 4, 0xFF000000 + i * 0x10101)
|
||||
end
|
||||
return pal
|
||||
end
|
||||
|
||||
-- a copy of a 1024-byte palette with entry index fully transparent (Quake / GoldSrc: index 255 of sprites, qpics and
|
||||
-- '{' textures)
|
||||
function Pixels.keyed(pal: buffer, index: number): buffer
|
||||
local out = buffer.create(1024)
|
||||
buffer.copy(out, 0, pal, 0, math.min(buffer.len(pal), 1024))
|
||||
if index >= 0 and index < 256 then
|
||||
writeu32(out, index * 4, 0)
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
-- palette (1024 bytes) -> { { r, g, b, a } } for codecs/image/Quantize
|
||||
function Pixels.colorList(pal: buffer, n: number?): { { number } }
|
||||
local out: { { number } } = {}
|
||||
for i = 0, math.clamp(n or 256, 0, buffer.len(pal) // 4) - 1 do
|
||||
out[i + 1] = { readu8(pal, i * 4), readu8(pal, i * 4 + 1), readu8(pal, i * 4 + 2), readu8(pal, i * 4 + 3) }
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
-- Quake colormap.lmp: rows of 256 palette indices, row 0 brightest .. 63 darkest (32 = unlit); the palette for one
|
||||
-- light level, or nil past the end of the map
|
||||
function Pixels.colormap(pal: buffer, cmap: buffer, base: number, row: number): buffer?
|
||||
local o = base + row * 256
|
||||
if row < 0 or base < 0 or o + 256 > buffer.len(cmap) then
|
||||
return nil
|
||||
end
|
||||
local out = buffer.create(1024)
|
||||
for i = 0, 255 do
|
||||
writeu32(out, i * 4, readu32(pal, readu8(cmap, o + i) * 4))
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
-- rgba8 palette (1024 bytes) -> 3 * n bytes R, G, B (the Quake / GoldSrc palette layout)
|
||||
function Pixels.paletteBytes(pal: buffer, n: number?): buffer
|
||||
local m = math.clamp(n or 256, 0, 256)
|
||||
local out = buffer.create(m * 3)
|
||||
for i = 0, m - 1 do
|
||||
writeu8(out, i * 3, readu8(pal, i * 4))
|
||||
writeu8(out, i * 3 + 1, readu8(pal, i * 4 + 1))
|
||||
writeu8(out, i * 3 + 2, readu8(pal, i * 4 + 2))
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
return Pixels
|
||||
Reference in new issue
Block a user