tests/image: comments: specs only
This commit is contained in:
1 parent
e306d5c1d7
commit
a80299dce0
27 files changed
+32
-199
No files matched your search
+1
-19
@@ -1,8 +1,4 @@
|
||||
-- image/bmp tests: synthesized BMPs (every header type, bit depth and compression, row order, palettes, masks and alpha
|
||||
-- rules, the RLE escapes, the lenient paths, errors), the BMP Suite against Pillow (g/ must match, q/ and b/ must not
|
||||
-- throw), the encoder byte-exact against Pillow (24 bpp, 8 bpp paletted, 32 bpp BI_RGB) plus the V4 alpha header and
|
||||
-- round trips (the V4 output was also checked by hand: Pillow and ImageMagick read the same RGBA), the api, and the
|
||||
-- fuzz passes. Ported from bmp-luau tests/core.luau + tests/files.luau.
|
||||
-- image/bmp tests: synthesized BMPs, the BMP Suite against Pillow (g/ must match, q/ and b/ must not throw).
|
||||
-- Fixtures: tools/fixtures/bmp.py.
|
||||
local T = require("@tests/T")
|
||||
local BmpF = require("@rosetta/image/bmp")
|
||||
@@ -19,8 +15,6 @@ local function check(cond: any, label: string)
|
||||
t:check(cond, label)
|
||||
end
|
||||
|
||||
-- the bmp-luau API on top of the contract (the ported tests below use it): decode(string | buffer) -> image with the
|
||||
-- old fields | nil, message
|
||||
local Bmp = {}
|
||||
function Bmp.decode(s: any, opts: any?): (any, any)
|
||||
local b = if type(s) == "string" then buffer.fromstring(s) else s
|
||||
@@ -59,8 +53,6 @@ local function i32(v: number): string
|
||||
return le(if v < 0 then v + 4294967296 else v, 4)
|
||||
end
|
||||
|
||||
-- Builds a BMP. o: w, h (negative = top-down), bpp, comp, hs (12, 40, 52, 56, 108, 124), palette ({ {r,g,b} }),
|
||||
-- clrUsed, masks ({r,g,b[,a]}: in the header for hs >= 52, else after it), pixels (string), off / bfSize overrides.
|
||||
local function make(o): string
|
||||
local hs = o.hs or 40
|
||||
local hdr
|
||||
@@ -130,7 +122,6 @@ do
|
||||
check(td.topDown and td.height == 2, "top-down fields")
|
||||
is(td, 0, 0, 255, 0, 0, 255, "top-down first row on top")
|
||||
is(td, 0, 1, 255, 255, 255, 255, "top-down second row")
|
||||
-- string and buffer input are the same
|
||||
local b = Bmp.decode(buffer.fromstring(make({ w = 3, h = 2, bpp = 24, pixels = bottom .. top })))
|
||||
check(b and buffer.tostring(b.pixels) == buffer.tostring(img.pixels), "buffer input")
|
||||
end
|
||||
@@ -210,7 +201,6 @@ do
|
||||
is(img5, 0, 0, 255, 131, 8, 255, "v4 BI_RGB 16 -> 555")
|
||||
end
|
||||
|
||||
-- 32 bpp
|
||||
do
|
||||
-- BI_RGB, alpha bytes all zero -> opaque
|
||||
local img = decode(make({ w = 2, h = 1, bpp = 32, pixels = "\1\2\3\0\4\5\6\0" }), "rgb32 zero alpha")
|
||||
@@ -311,7 +301,6 @@ do
|
||||
is(t2, 3, 3, 0, 0, 0, 255, "no pixel data: index 0")
|
||||
end
|
||||
|
||||
-- info / isBmp
|
||||
do
|
||||
local s = make({ hs = 124, w = 7, h = -5, bpp = 32, comp = 3, masks = { 0xFF0000, 0xFF00, 0xFF, 0xFF000000 }, pixels = "" })
|
||||
local info = Bmp.info(s)
|
||||
@@ -347,7 +336,6 @@ do
|
||||
fails(make({ w = 100, h = 100, bpp = 24, pixels = "" }), "too large", "maxPixels option", { maxPixels = 9999 })
|
||||
end
|
||||
|
||||
-- fuzz: truncations and byte flips of every kind of file above must never throw
|
||||
do
|
||||
local seeds = {
|
||||
make({ w = 3, h = 2, bpp = 24, pixels = string.rep("\1\2\3", 8) }),
|
||||
@@ -387,8 +375,6 @@ do
|
||||
t:note("fuzz: %d decodes, no throw", runs)
|
||||
end
|
||||
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ the BMP Suite
|
||||
do
|
||||
local nMatch, nOther = 0, 0
|
||||
local samples = {}
|
||||
@@ -413,7 +399,6 @@ do
|
||||
end, samples, { mutations = 6 })
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ encoder
|
||||
do
|
||||
for _, c in Enc do
|
||||
local img = Types.Image.new(c.w, c.h)
|
||||
@@ -438,7 +423,6 @@ do
|
||||
end
|
||||
end
|
||||
t:note("encoder: %d files identical to Pillow", #Enc)
|
||||
-- forced depths, dpi, errors
|
||||
local img = Types.Image.new(5, 4)
|
||||
for i = 0, 19 do
|
||||
buffer.writeu32(img.pixels, i * 4, 0xFF000000 + i * 0x010203)
|
||||
@@ -462,14 +446,12 @@ do
|
||||
t:check(e2 and e2.code == Err.ARG, "not an image")
|
||||
local _, e3 = BmpF.encode(img, { bitDepth = 16 } :: any)
|
||||
t:check(e3 and e3.code == Err.ARG, "bitDepth 16")
|
||||
-- the api
|
||||
local c = Enc[1]
|
||||
local loaded = F.image.load(c.bmp)
|
||||
t:check(loaded and loaded.width == c.w and buffer.tostring(loaded.pixels) == c.rgba, "F.image.load")
|
||||
t:eq(F.detect(c.bmp), "bmp", "F.detect")
|
||||
local saved = F.save(loaded, nil, { format = "bmp" })
|
||||
t:check(saved and buffer.tostring(saved) == c.bmp, "F.save bmp")
|
||||
-- a sub-range reader
|
||||
local big = buffer.create(#c.bmp + 5)
|
||||
buffer.writestring(big, 3, c.bmp)
|
||||
local sub = BmpF.decode(Bytes.reader(big, 3, #c.bmp)) :: any
|
||||
|
||||
Reference in new issue
Block a user