merge ws/imgA: jpeg gif tiff tga qoi pnm ico hdr, codecs Dct/Lzw/Quantize, ops/ImageOps, api image hooks
This commit is contained in:
commit
2db77a7db8
55 files changed
+13401
-2
No files matched your search
@@ -230,5 +230,164 @@ do
|
||||
end)
|
||||
bench("yaml encode", 3, #YB.text, function()
|
||||
Yaml.encode(v)
|
||||
-- ------------------------------------------------------------------------------------------------ jpeg (ws-imgA)
|
||||
do
|
||||
local Jpeg = require("@formats/image/jpeg")
|
||||
local Types = require("@formats/Types")
|
||||
local JB = require("@tests/gen/jpeg_bench")
|
||||
for _, c in JB.files do
|
||||
local b = buffer.fromstring(c.data)
|
||||
local img = Jpeg.decode(Bytes.reader(b))
|
||||
assert(img and Crc32.of(img.pixels) == c.crc, "jpeg bench: " .. c.name .. " does not match djpeg")
|
||||
bench("jpeg decode " .. c.name, 3, c.width * c.height * 4, function()
|
||||
Jpeg.decode(Bytes.reader(b))
|
||||
end)
|
||||
end
|
||||
local b0 = buffer.fromstring(JB.files[1].data)
|
||||
bench("jpeg decode 1/8 (DC only)", 3, JB.width * JB.height * 4, function()
|
||||
Jpeg.decode(Bytes.reader(b0), { scale = 8 })
|
||||
end)
|
||||
local src = Types.Image.new(JB.width, JB.height, "rgb8")
|
||||
buffer.writestring(src.pixels, 0, JB.rgb)
|
||||
for _, o in { { label = "baseline 4:2:0 q85", quality = 85 }, { label = "progressive 4:2:0 q85", quality = 85, progressive = true }, { label = "baseline 4:4:4 q85 optimized", quality = 85, subsampling = "444", optimize = true } } do
|
||||
bench("jpeg encode " .. o.label, 2, JB.width * JB.height * 3, function()
|
||||
Jpeg.encode(src, o :: any)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
-- ---------------------------------------------------------------------------------------- ws-imgA: gif + quantize
|
||||
do
|
||||
local Gif = require("@formats/image/gif")
|
||||
local Quantize = require("@formats/codecs/Quantize")
|
||||
local Types = require("@formats/Types")
|
||||
local GB = require("@tests/gen/gif_bench")
|
||||
local still = buffer.fromstring(GB.still)
|
||||
local anim = buffer.fromstring(GB.anim)
|
||||
local simg = assert(Gif.decode(Bytes.reader(still)))
|
||||
local aimg = assert(Gif.decode(Bytes.reader(anim)))
|
||||
local sw, sh = simg.width, simg.height
|
||||
bench("gif decode 512x384", 5, sw * sh * 4, function()
|
||||
Gif.decode(Bytes.reader(still))
|
||||
end)
|
||||
bench("gif decode 40 x 128x128 anim", 3, #(aimg.frames :: any) * 128 * 128 * 4, function()
|
||||
Gif.decode(Bytes.reader(anim))
|
||||
end)
|
||||
bench("gif encode 512x384 (exact pal)", 3, sw * sh * 4, function()
|
||||
Gif.encode(simg)
|
||||
end)
|
||||
local photo = Types.Image.new(sw, sh)
|
||||
for i = 0, sw * sh - 1 do
|
||||
local x, y = i % sw, i // sw
|
||||
buffer.writeu32(photo.pixels, i * 4, (x % 256) + (y % 256) * 256 + ((x * y) % 256) * 65536 + 0xFF000000)
|
||||
end
|
||||
bench("quantize mediancut 256", 3, sw * sh * 4, function()
|
||||
Quantize.palette(photo.pixels, sw, sh, 256)
|
||||
end)
|
||||
bench("quantize octree 256", 3, sw * sh * 4, function()
|
||||
Quantize.palette(photo.pixels, sw, sh, 256, { method = "octree" })
|
||||
end)
|
||||
local pal = Quantize.palette(photo.pixels, sw, sh, 256)
|
||||
bench("quantize map", 3, sw * sh * 4, function()
|
||||
Quantize.map(photo.pixels, sw, sh, pal)
|
||||
end)
|
||||
bench("quantize map + dither", 3, sw * sh * 4, function()
|
||||
Quantize.map(photo.pixels, sw, sh, pal, { dither = true })
|
||||
end)
|
||||
bench("gif encode 512x384 (quantize)", 2, sw * sh * 4, function()
|
||||
Gif.encode(photo)
|
||||
end)
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ ops/ImageOps
|
||||
do
|
||||
local Ops = require("@formats/ops/ImageOps")
|
||||
local img = assert(Png.decode(Bytes.reader(buffer.fromstring(PB[1].data))))
|
||||
local n = img.width * img.height * 4
|
||||
bench("imageops resize 1/2 bilinear", 2, n, function()
|
||||
Ops.resize(img, img.width // 2, img.height // 2, "bilinear")
|
||||
end)
|
||||
bench("imageops resize 1/2 lanczos", 2, n, function()
|
||||
Ops.resize(img, img.width // 2, img.height // 2, "lanczos")
|
||||
end)
|
||||
bench("imageops resize x1.5 bilinear", 1, n, function()
|
||||
Ops.resize(img, img.width * 3 // 2, img.height * 3 // 2, "bilinear")
|
||||
end)
|
||||
bench("imageops rotate 30 (expand)", 1, n, function()
|
||||
Ops.rotate(img, 30)
|
||||
end)
|
||||
bench("imageops rotate90", 3, n, function()
|
||||
Ops.rotate90(img, 1)
|
||||
end)
|
||||
bench("imageops convert rgba8 -> gray8", 3, n, function()
|
||||
Ops.convert(img, "gray8")
|
||||
end)
|
||||
local other = assert(Ops.flip(img, "h"))
|
||||
bench("imageops composite over", 3, n, function()
|
||||
Ops.composite(img, other)
|
||||
end)
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ image/tiff (ws-imgA)
|
||||
do
|
||||
local Tiff = require("@formats/image/tiff")
|
||||
local Types = require("@formats/Types")
|
||||
local src = Types.Image.new(1024, 768)
|
||||
for i = 0, 1024 * 768 - 1 do
|
||||
local x, y = i % 1024, i // 1024
|
||||
buffer.writeu32(src.pixels, i * 4, 0xFF000000 + (x % 256) + ((y % 256) * 256) + (((x + y) // 4 % 256) * 65536))
|
||||
end
|
||||
for _, comp in { "none", "lzw", "deflate" } do
|
||||
local enc = Tiff.encode(src, { compression = comp :: any }) :: buffer
|
||||
bench("tiff decode rgba8 " .. comp, 3, 1024 * 768 * 4, function()
|
||||
Tiff.decode(Bytes.reader(enc))
|
||||
end)
|
||||
bench("tiff encode rgba8 " .. comp, 2, 1024 * 768 * 4, function()
|
||||
Tiff.encode(src, { compression = comp :: any })
|
||||
end)
|
||||
end
|
||||
local enc16 = Tiff.encode(Types.Image.new(1024, 768, "rgba16"), { compression = "lzw" }) :: buffer
|
||||
bench("tiff decode rgba16 lzw -> rgba8", 3, 1024 * 768 * 8, function()
|
||||
Tiff.decode(Bytes.reader(enc16))
|
||||
end)
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ imgA-simple: qoi / tga / pnm / hdr
|
||||
-- fixtures: tools/fixtures/qoi.py (tests/gen/qoi_bench.luau: run python3 -I tools/fixtures.py qoi first)
|
||||
do
|
||||
local Qoi = require("@formats/image/qoi")
|
||||
local Tga = require("@formats/image/tga")
|
||||
local Pnm = require("@formats/image/pnm")
|
||||
local Hdr = require("@formats/image/hdr")
|
||||
local Types = require("@formats/Types")
|
||||
local QB = require("@tests/gen/qoi_bench")
|
||||
local qd = buffer.fromstring(QB.data)
|
||||
local n = QB.width * QB.height * 4
|
||||
bench("qoi decode 1024x768", 5, n, function()
|
||||
Qoi.decode(Bytes.reader(qd))
|
||||
end)
|
||||
local img = Types.Image.new(QB.width, QB.height)
|
||||
img.pixels = buffer.fromstring(QB.pixels)
|
||||
bench("qoi encode 1024x768", 5, n, function()
|
||||
Qoi.encode(img)
|
||||
end)
|
||||
local tr = Tga.encode(img, { rle = true }) :: buffer
|
||||
bench("tga decode rle 1024x768", 3, n, function()
|
||||
Tga.decode(Bytes.reader(tr))
|
||||
end)
|
||||
bench("tga encode rle 1024x768", 3, n, function()
|
||||
Tga.encode(img, { rle = true })
|
||||
end)
|
||||
local pp = Pnm.encode(img, { format = "ppm" }) :: buffer
|
||||
bench("ppm decode 1024x768", 3, n, function()
|
||||
Pnm.decode(Bytes.reader(pp))
|
||||
end)
|
||||
local f = Hdr.decode(Bytes.reader(Hdr.encode(img) :: buffer), { native = true }) :: Types.Image
|
||||
local hb = Hdr.encode(f) :: buffer
|
||||
bench("hdr decode rle 1024x768 (rgbaf32)", 3, n, function()
|
||||
Hdr.decode(Bytes.reader(hb), { native = true })
|
||||
end)
|
||||
bench("hdr encode rle 1024x768", 3, n, function()
|
||||
Hdr.encode(f)
|
||||
end)
|
||||
end
|
||||
Reference in new issue
Block a user