perf(image): VP8L literal symbols inline, cross-colour identity tiles skipped, T / TR / TL predictors and SWAR addPixels; JPEG IDCT 5x5 path, gray / 4:4:4 colour fast paths; QOI index as tables; TGA rows without per-pixel div/mod; BC7 / BC6H bit reads from a word table; bench_image: bcn / exr
This commit is contained in:
1 parent
9855a7edd6
commit
903e239a0e
7 files changed
+293
-121
No files matched your search
@@ -337,6 +337,7 @@ local function decodeData(d: State, data: buffer, w: number, h: number, cacheBit
|
||||
local hmask = if himg then lshift(1, hbits) - 1 else -1
|
||||
local i, col, row = 0, 0, 0
|
||||
local gG, gR, gB, gA, gD = groups[1], groups[2], groups[3], groups[4], groups[5]
|
||||
local tab = d.tab
|
||||
local function setGroup()
|
||||
if himg then
|
||||
local g = readu32(himg, (hxs * rshift(row, hbits) + rshift(col, hbits)) * 4) * 5
|
||||
@@ -347,12 +348,79 @@ local function decodeData(d: State, data: buffer, w: number, h: number, cacheBit
|
||||
if band(col, hmask) == 0 then
|
||||
setGroup()
|
||||
end
|
||||
local code = readSymbol(d, gG)
|
||||
-- readSymbol inlined for the literal path (the bit state in locals, written back before any call)
|
||||
local bb, bc = d.bitbuf, d.bitcnt
|
||||
if bc < MAX_LEN then
|
||||
d.bitbuf, d.bitcnt = bb, bc
|
||||
fill(d)
|
||||
bb, bc = d.bitbuf, d.bitcnt
|
||||
end
|
||||
local ecode = readu32(tab, (gG + band(bb, 255)) * 4)
|
||||
local ncode = band(ecode, 31)
|
||||
if ncode > ROOT_BITS then
|
||||
local idx = gG + band(bb, 255)
|
||||
bb = rshift(bb, ROOT_BITS)
|
||||
bc -= ROOT_BITS
|
||||
ecode = readu32(tab, (idx + rshift(ecode, 5) + band(bb, lshift(1, ncode - ROOT_BITS) - 1)) * 4)
|
||||
ncode = band(ecode, 31)
|
||||
end
|
||||
bb = rshift(bb, ncode)
|
||||
bc -= ncode
|
||||
local code = rshift(ecode, 5)
|
||||
if code < NUM_LITERAL then
|
||||
local r = readSymbol(d, gR)
|
||||
local b = readSymbol(d, gB)
|
||||
local a = readSymbol(d, gA)
|
||||
if d.bitcnt < d.over * 8 then
|
||||
if bc < MAX_LEN then
|
||||
d.bitbuf, d.bitcnt = bb, bc
|
||||
fill(d)
|
||||
bb, bc = d.bitbuf, d.bitcnt
|
||||
end
|
||||
local er = readu32(tab, (gR + band(bb, 255)) * 4)
|
||||
local nr = band(er, 31)
|
||||
if nr > ROOT_BITS then
|
||||
local idx = gR + band(bb, 255)
|
||||
bb = rshift(bb, ROOT_BITS)
|
||||
bc -= ROOT_BITS
|
||||
er = readu32(tab, (idx + rshift(er, 5) + band(bb, lshift(1, nr - ROOT_BITS) - 1)) * 4)
|
||||
nr = band(er, 31)
|
||||
end
|
||||
bb = rshift(bb, nr)
|
||||
bc -= nr
|
||||
local r = rshift(er, 5)
|
||||
if bc < MAX_LEN then
|
||||
d.bitbuf, d.bitcnt = bb, bc
|
||||
fill(d)
|
||||
bb, bc = d.bitbuf, d.bitcnt
|
||||
end
|
||||
local eb = readu32(tab, (gB + band(bb, 255)) * 4)
|
||||
local nb = band(eb, 31)
|
||||
if nb > ROOT_BITS then
|
||||
local idx = gB + band(bb, 255)
|
||||
bb = rshift(bb, ROOT_BITS)
|
||||
bc -= ROOT_BITS
|
||||
eb = readu32(tab, (idx + rshift(eb, 5) + band(bb, lshift(1, nb - ROOT_BITS) - 1)) * 4)
|
||||
nb = band(eb, 31)
|
||||
end
|
||||
bb = rshift(bb, nb)
|
||||
bc -= nb
|
||||
local b = rshift(eb, 5)
|
||||
if bc < MAX_LEN then
|
||||
d.bitbuf, d.bitcnt = bb, bc
|
||||
fill(d)
|
||||
bb, bc = d.bitbuf, d.bitcnt
|
||||
end
|
||||
local ea = readu32(tab, (gA + band(bb, 255)) * 4)
|
||||
local na = band(ea, 31)
|
||||
if na > ROOT_BITS then
|
||||
local idx = gA + band(bb, 255)
|
||||
bb = rshift(bb, ROOT_BITS)
|
||||
bc -= ROOT_BITS
|
||||
ea = readu32(tab, (idx + rshift(ea, 5) + band(bb, lshift(1, na - ROOT_BITS) - 1)) * 4)
|
||||
na = band(ea, 31)
|
||||
end
|
||||
bb = rshift(bb, na)
|
||||
bc -= na
|
||||
local a = rshift(ea, 5)
|
||||
d.bitbuf, d.bitcnt = bb, bc
|
||||
if bc < d.over * 8 then
|
||||
break
|
||||
end
|
||||
local argb = a * 16777216 + r * 65536 + code * 256 + b
|
||||
@@ -367,6 +435,7 @@ local function decodeData(d: State, data: buffer, w: number, h: number, cacheBit
|
||||
row += 1
|
||||
end
|
||||
elseif code < lenLimit then
|
||||
d.bitbuf, d.bitcnt = bb, bc
|
||||
local ls = code - NUM_LITERAL
|
||||
local length
|
||||
if ls < 4 then
|
||||
@@ -422,6 +491,7 @@ local function decodeData(d: State, data: buffer, w: number, h: number, cacheBit
|
||||
setGroup()
|
||||
end
|
||||
elseif code < cacheLimit and cache then
|
||||
d.bitbuf, d.bitcnt = bb, bc
|
||||
if d.bitcnt < d.over * 8 then
|
||||
break
|
||||
end
|
||||
@@ -444,8 +514,9 @@ local function decodeData(d: State, data: buffer, w: number, h: number, cacheBit
|
||||
return true, nil
|
||||
end
|
||||
|
||||
-- per-byte sums mod 256 (the low seven bits added, the top bits xored in)
|
||||
local function addPixels(a: number, b: number): number
|
||||
return band(band(a, 0xff00ff00) + band(b, 0xff00ff00), 0xff00ff00) + band(band(a, 0x00ff00ff) + band(b, 0x00ff00ff), 0x00ff00ff)
|
||||
return bxor(band(a, 0x7f7f7f7f) + band(b, 0x7f7f7f7f), band(bxor(a, b), 0x80808080))
|
||||
end
|
||||
Decode.addPixels = addPixels
|
||||
|
||||
@@ -553,9 +624,11 @@ local function inversePredictor(data: buffer, w: number, h: number, bits: number
|
||||
L = addPixels(readu32(data, (row + k) * 4), L)
|
||||
writeu32(data, (row + k) * 4, L)
|
||||
end
|
||||
elseif mode == 2 then
|
||||
for k = x, xe - 1 do
|
||||
writeu32(data, (row + k) * 4, addPixels(readu32(data, (row + k) * 4), readu32(data, (up + k) * 4)))
|
||||
elseif mode == 2 or mode == 3 or mode == 4 then
|
||||
-- T, TR, TL: the upper row only
|
||||
local d = (up - row + (if mode == 2 then 0 elseif mode == 3 then 1 else -1)) * 4
|
||||
for o = (row + x) * 4, (row + xe - 1) * 4, 4 do
|
||||
writeu32(data, o, addPixels(readu32(data, o), readu32(data, o + d)))
|
||||
end
|
||||
else
|
||||
for k = x, xe - 1 do
|
||||
@@ -584,12 +657,26 @@ local function inverseCrossColor(data: buffer, w: number, h: number, bits: numbe
|
||||
local g2b = sint8(band(rshift(m, 8), 255))
|
||||
local r2b = sint8(band(rshift(m, 16), 255))
|
||||
local xe = math.min(w, lshift(rshift(x, bits) + 1, bits))
|
||||
for k = y * w + x, y * w + xe - 1 do
|
||||
local argb = readu32(data, k * 4)
|
||||
local g = sint8(band(rshift(argb, 8), 255))
|
||||
local r = band(band(rshift(argb, 16), 255) + ((g2r * g) // 32), 255)
|
||||
local b = band(band(argb, 255) + ((g2b * g) // 32) + ((r2b * sint8(r)) // 32), 255)
|
||||
writeu32(data, k * 4, band(argb, 0xff00ff00) + r * 65536 + b)
|
||||
if g2r == 0 and g2b == 0 and r2b == 0 then
|
||||
x = xe -- the identity
|
||||
continue
|
||||
end
|
||||
if r2b == 0 then
|
||||
for o = (y * w + x) * 4, (y * w + xe - 1) * 4, 4 do
|
||||
local argb = readu32(data, o)
|
||||
local g = sint8(band(rshift(argb, 8), 255))
|
||||
local r = band(band(rshift(argb, 16), 255) + ((g2r * g) // 32), 255)
|
||||
local b = band(band(argb, 255) + ((g2b * g) // 32), 255)
|
||||
writeu32(data, o, band(argb, 0xff00ff00) + r * 65536 + b)
|
||||
end
|
||||
else
|
||||
for o = (y * w + x) * 4, (y * w + xe - 1) * 4, 4 do
|
||||
local argb = readu32(data, o)
|
||||
local g = sint8(band(rshift(argb, 8), 255))
|
||||
local r = band(band(rshift(argb, 16), 255) + ((g2r * g) // 32), 255)
|
||||
local b = band(band(argb, 255) + ((g2b * g) // 32) + ((r2b * sint8(r)) // 32), 255)
|
||||
writeu32(data, o, band(argb, 0xff00ff00) + r * 65536 + b)
|
||||
end
|
||||
end
|
||||
x = xe
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user