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
@@ -46,6 +46,9 @@ if want("jpeg") then
|
||||
end)
|
||||
end
|
||||
local b0 = buffer.fromstring(JB.files[1].data)
|
||||
bench("jpeg decode 1/4", 3, JB.width * JB.height * 4, function()
|
||||
Jpeg.decode(Bytes.reader(b0), { scale = 4 })
|
||||
end)
|
||||
bench("jpeg decode 1/8 (DC only)", 3, JB.width * JB.height * 4, function()
|
||||
Jpeg.decode(Bytes.reader(b0), { scale = 8 })
|
||||
end)
|
||||
@@ -70,6 +73,62 @@ if want("png", "imageops") then
|
||||
bench("png encode rgba8", 2, img.width * img.height * 4, function()
|
||||
Png.encode(img)
|
||||
end)
|
||||
-- 4096 x 4096 16-bit RGB (a normal-map export): sub / up / Paeth rows in stored deflate blocks, 8 KB IDATs
|
||||
local Adler32 = require("@rosetta/core/Adler32")
|
||||
local W = 4096
|
||||
local stride = W * 6 + 1
|
||||
local raw = buffer.create(stride * W)
|
||||
local seed = 12345
|
||||
for i = 0, stride * 7 - 1 do
|
||||
seed = (seed * 1103515245 + 12345) % 2147483648
|
||||
buffer.writeu8(raw, i, seed // 65536 % 256)
|
||||
end
|
||||
for y = 0, W - 1 do
|
||||
if y >= 7 then
|
||||
buffer.copy(raw, y * stride, raw, (y % 7) * stride, stride)
|
||||
end
|
||||
buffer.writeu8(raw, y * stride, ({ 1, 2, 4, 4 })[y % 4 + 1])
|
||||
end
|
||||
local nraw = buffer.len(raw)
|
||||
local nblocks = (nraw + 65534) // 65535
|
||||
local z = buffer.create(2 + nraw + nblocks * 5 + 4)
|
||||
buffer.writeu8(z, 0, 0x78)
|
||||
buffer.writeu8(z, 1, 0x01)
|
||||
local zo = 2
|
||||
for i = 0, nblocks - 1 do
|
||||
local len = math.min(65535, nraw - i * 65535)
|
||||
buffer.writeu8(z, zo, if i == nblocks - 1 then 1 else 0)
|
||||
buffer.writeu16(z, zo + 1, len)
|
||||
buffer.writeu16(z, zo + 3, 65535 - len)
|
||||
buffer.copy(z, zo + 5, raw, i * 65535, len)
|
||||
zo += 5 + len
|
||||
end
|
||||
buffer.writeu32(z, zo, bit32.byteswap(Adler32.raw(raw, 0, nraw)))
|
||||
raw = nil :: any
|
||||
local nz = buffer.len(z)
|
||||
local nidat = (nz + 8191) // 8192
|
||||
local p16 = buffer.create(33 + nz + nidat * 12 + 12)
|
||||
buffer.writestring(p16, 0, "\137PNG\r\n\26\n\0\0\0\13IHDR")
|
||||
buffer.writeu32(p16, 16, bit32.byteswap(W))
|
||||
buffer.writeu32(p16, 20, bit32.byteswap(W))
|
||||
buffer.writestring(p16, 24, "\16\2\0\0\0")
|
||||
local po = 33
|
||||
for i = 0, nidat - 1 do
|
||||
local len = math.min(8192, nz - i * 8192)
|
||||
buffer.writeu32(p16, po, bit32.byteswap(len))
|
||||
buffer.writestring(p16, po + 4, "IDAT")
|
||||
buffer.copy(p16, po + 8, z, i * 8192, len)
|
||||
po += 12 + len
|
||||
end
|
||||
buffer.writestring(p16, po, "\0\0\0\0IEND")
|
||||
z = nil :: any
|
||||
bench("png decode 4096^2 rgb16", 1, W * W * 4, function()
|
||||
assert(Png.decode(Bytes.reader(p16)))
|
||||
end)
|
||||
bench("png decode 4096^2 rgb16 maxSide 1024", 1, W * W * 4, function()
|
||||
assert(Png.decode(Bytes.reader(p16), { maxSide = 1024 }))
|
||||
end)
|
||||
p16 = nil :: any
|
||||
local Ops = require("@rosetta/ops/ImageOps")
|
||||
local n = img.width * img.height * 4
|
||||
bench("imageops resize 1/2 bilinear", 2, n, function()
|
||||
|
||||
Reference in new issue
Block a user