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
@@ -272,6 +272,52 @@ do
|
||||
t:note("%d truncated files, %d decoded partially", count, partial)
|
||||
end
|
||||
|
||||
do
|
||||
-- maxSide picks the smallest scale (up to 8) that fits: the same pixels as djpeg -scale 1/n
|
||||
local checked, yielded = 0, 0
|
||||
for _, c in Dec do
|
||||
if c.refs then
|
||||
local byScale = {}
|
||||
for _, r in c.refs do
|
||||
byScale[r.scale] = r
|
||||
end
|
||||
for _, r in c.refs do
|
||||
local m = math.max(r.width, r.height)
|
||||
local img, err = decode(c.data, { maxSide = m })
|
||||
local s = img and img.meta.source.scale
|
||||
local ref = s and byScale[s]
|
||||
t:check(img and img.width <= m and img.height <= m and s <= r.scale, c.name .. " maxSide " .. m .. ": " .. tostring(err))
|
||||
if ref then
|
||||
t:check(Crc32.of(img.pixels) == ref.crc, c.name .. " maxSide " .. m .. ": pixels match djpeg 1/" .. s)
|
||||
checked += 1
|
||||
end
|
||||
end
|
||||
local r1 = byScale[1]
|
||||
if r1 then
|
||||
-- yield: called, may suspend the coroutine, and the pixels do not change
|
||||
local calls = 0
|
||||
local co = coroutine.wrap(function(): any
|
||||
return decode(c.data, { yield = function()
|
||||
calls += 1
|
||||
coroutine.yield(false)
|
||||
end })
|
||||
end)
|
||||
local img = co()
|
||||
while img == false do
|
||||
img = co()
|
||||
end
|
||||
t:check(img and Crc32.of(img.pixels) == r1.crc and (calls > 0 or r1.height <= 8), c.name .. ": yielding decode")
|
||||
yielded += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
t:note("maxSide: %d decodes bit-exact with djpeg -scale; yield: %d files", checked, yielded)
|
||||
local _, e = decode(file("photo_q90_420"), { maxSide = 0 })
|
||||
t:check(e and e.code == Err.ARG, "maxSide 0")
|
||||
local big = decode(file("photo_q90_420"), { maxSide = 1 })
|
||||
t:check(big and big.meta.source.scale == 8 and big.width == 20, "maxSide below 1/8 stops at 1/8")
|
||||
end
|
||||
|
||||
do
|
||||
local samples = {}
|
||||
for i, c in Dec do
|
||||
@@ -285,6 +331,9 @@ do
|
||||
t:fuzz("decode 1/8", function(b: buffer)
|
||||
return Jpeg.decode(Bytes.reader(b), { scale = 8 })
|
||||
end, samples, { mutations = 2, garbage = 30 })
|
||||
t:fuzz("decode maxSide + yield", function(b: buffer)
|
||||
return Jpeg.decode(Bytes.reader(b), { maxSide = 30, yield = function() end })
|
||||
end, samples, { mutations = 2, keepHeader = 2 })
|
||||
end
|
||||
|
||||
t:done()
|
||||
Reference in new issue
Block a user