png / jpeg: maxSide + yield docs (guide, API) and tested snippet; jpeg destuff calls the yield hook per 64 KB; F.model.loadTextures passes maxSide / yield / yieldRows / maxPixels to the image decoders; bench lines (4096^2 16-bit PNG full vs maxSide 1024, JPEG 1/4); build/ regenerated
init.luau (small, backward compatible): loadTextures forwards those four options to F.load.
This commit is contained in:
1 parent
64a2553c0c
commit
8d7f3e4d34
17 files changed
+2695
-1270
No files matched your search
@@ -170,7 +170,8 @@ function Inflate.raw(src: buffer, start: number, endpos: number, cap: number, ex
|
||||
if op < 0 then
|
||||
return nil, "aborted"
|
||||
end
|
||||
seen, cap = op, blen(out)
|
||||
seen = op
|
||||
cap = blen(out)
|
||||
else
|
||||
out, cap = grow(out, op, op + n)
|
||||
end
|
||||
@@ -359,7 +360,8 @@ function Inflate.raw(src: buffer, start: number, endpos: number, cap: number, ex
|
||||
if op < 0 then
|
||||
return nil, "aborted"
|
||||
end
|
||||
seen, cap = op, blen(out)
|
||||
seen = op
|
||||
cap = blen(out)
|
||||
else
|
||||
out, cap = grow(out, op, op + 1)
|
||||
end
|
||||
@@ -464,7 +466,8 @@ function Inflate.raw(src: buffer, start: number, endpos: number, cap: number, ex
|
||||
if op < 0 then
|
||||
return nil, "aborted"
|
||||
end
|
||||
seen, cap = op, blen(out)
|
||||
seen = op
|
||||
cap = blen(out)
|
||||
else
|
||||
out, cap = grow(out, op, op + len)
|
||||
end
|
||||
|
||||
@@ -510,7 +510,7 @@ function Decode.parse(b: buffer, base: number, n: number, opts: any, headerOnly:
|
||||
clean = buffer.create(n - base + Scan.PAD)
|
||||
end
|
||||
local cb = clean :: buffer
|
||||
local nextPos, cleanLen, nrst = Scan.destuff(b, pos, n, cb, rst)
|
||||
local nextPos, cleanLen, nrst = Scan.destuff(b, pos, n, cb, rst, st.hook)
|
||||
if nextPos >= n then
|
||||
st.truncated = true -- no EOI
|
||||
end
|
||||
|
||||
@@ -100,37 +100,45 @@ function Scan.buildTable(counts: { number }, symbols: { number }): buffer
|
||||
return t
|
||||
end
|
||||
|
||||
function Scan.destuff(src: buffer, pos: number, n: number, dst: buffer, rst: { number }): (number, number, number)
|
||||
function Scan.destuff(src: buffer, pos: number, n: number, dst: buffer, rst: { number }, hook: (() -> ())?): (number, number, number)
|
||||
local o, nr = 0, 0
|
||||
while pos < n do
|
||||
local b = readu8(src, pos)
|
||||
if b ~= 0xFF then
|
||||
writeu8(dst, o, b)
|
||||
o += 1
|
||||
pos += 1
|
||||
else
|
||||
local q = pos + 1
|
||||
while q < n and readu8(src, q) == 0xFF do
|
||||
q += 1
|
||||
end
|
||||
if q >= n then
|
||||
pos = n
|
||||
break
|
||||
end
|
||||
local m = readu8(src, q)
|
||||
if m == 0 then
|
||||
writeu8(dst, o, 0xFF)
|
||||
local done = false
|
||||
while not done and pos < n do
|
||||
local lim = if hook then math.min(n, pos + 65536) else n
|
||||
while pos < lim do
|
||||
local b = readu8(src, pos)
|
||||
if b ~= 0xFF then
|
||||
writeu8(dst, o, b)
|
||||
o += 1
|
||||
pos = q + 1
|
||||
elseif m >= 0xD0 and m <= 0xD7 then
|
||||
nr += 1
|
||||
rst[nr] = o
|
||||
pos = q + 1
|
||||
pos += 1
|
||||
else
|
||||
pos = q - 1
|
||||
break
|
||||
local q = pos + 1
|
||||
while q < n and readu8(src, q) == 0xFF do
|
||||
q += 1
|
||||
end
|
||||
if q >= n then
|
||||
pos = n
|
||||
break
|
||||
end
|
||||
local m = readu8(src, q)
|
||||
if m == 0 then
|
||||
writeu8(dst, o, 0xFF)
|
||||
o += 1
|
||||
pos = q + 1
|
||||
elseif m >= 0xD0 and m <= 0xD7 then
|
||||
nr += 1
|
||||
rst[nr] = o
|
||||
pos = q + 1
|
||||
else
|
||||
pos = q - 1
|
||||
done = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if hook and not done and pos < n then
|
||||
pcall(hook)
|
||||
end
|
||||
end
|
||||
buffer.fill(dst, o, 0, Scan.PAD)
|
||||
return pos, o, nr
|
||||
|
||||
@@ -499,7 +499,7 @@ function Decode.stream(w: number, h: number, depth: number, ct: number, pal: buf
|
||||
y += 1
|
||||
p += stride
|
||||
if hook and y % every == 0 then
|
||||
pcall(hook)
|
||||
pcall(hook :: () -> ())
|
||||
end
|
||||
end
|
||||
pending = if y < h then to - p else 0
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
--!strict
|
||||
-- image/png: PNG (ISO/IEC 15948, W3C PNG 3rd ed.) and APNG 1.0; from png-luau 1.0.0 (same author). Supports: every
|
||||
-- colour type and bit depth, tRNS, Adam7, tEXt, acTL / fcTL / fdAT; writes RGBA / RGB / grey(+alpha) and APNG. Not
|
||||
-- supported: colour management (iCCP kept raw), palette / 16-bit / interlaced output.
|
||||
-- colour type and bit depth, tRNS, Adam7, tEXt, acTL / fcTL / fdAT, row-streaming decode with power-of-two box
|
||||
-- reduction; writes RGBA / RGB / grey(+alpha) and APNG. Not supported: colour management (iCCP kept raw), palette /
|
||||
-- 16-bit / interlaced output.
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ requires
|
||||
local Err = require("@rosetta/core/Err")
|
||||
|
||||
@@ -853,7 +853,7 @@ F.model.loadTextures = function(scene: any, opts: Options?): (any, { [number]: E
|
||||
data = resolve(tex.uri)
|
||||
end
|
||||
if data ~= nil then
|
||||
local img, err = F.load(data, { category = "image", name = tex.uri, data = true })
|
||||
local img, err = F.load(data, { category = "image", name = tex.uri, data = true, maxSide = opts and opts.maxSide, yield = opts and opts.yield, yieldRows = opts and opts.yieldRows, maxPixels = opts and opts.maxPixels })
|
||||
if img then
|
||||
tex.image = img
|
||||
elseif err then
|
||||
|
||||
Reference in new issue
Block a user