tests/layered: comments: specs only
This commit is contained in:
1 parent
a07d4065a6
commit
58b0df8b21
3 files changed
+8
-30
No files matched your search
+4
-14
@@ -1,8 +1,5 @@
|
||||
-- layered/psd tests: PSD / PSB files of every colour mode and depth, compression, groups, pass-through, clipping,
|
||||
-- masks, fill opacity and blend mode (written by tools/fixtures/psd.py) plus an ImageMagick PSD, against psd-tools:
|
||||
-- the merged image and every layer's pixels exact (8-bit; 16 / 32-bit within rounding), our flatten (ops/LayerOps)
|
||||
-- against psd-tools' composite by PSNR; our encoder's PSD read back by psd-tools (tools/fixtures/_ours.luau), round
|
||||
-- trips, the contract and the fuzz pass. Fixtures: tools/fixtures/psd.py.
|
||||
-- layered/psd tests: PSD / PSB files against psd-tools (layers exact, flatten by PSNR).
|
||||
-- Fixtures: tools/fixtures/psd.py.
|
||||
local T = require("@tests/T")
|
||||
local Psd = require("@rosetta/layered/psd")
|
||||
local LayerOps = require("@rosetta/ops/LayerOps")
|
||||
@@ -18,8 +15,7 @@ local function decode(s: string | buffer, opts: any?): (any, any)
|
||||
local b = if type(s) == "string" then buffer.fromstring(s) else s
|
||||
return Psd.decode(Bytes.reader(b), opts)
|
||||
end
|
||||
-- PSNR of two rgba8 buffers, colours premultiplied by alpha (the colour of a transparent pixel does not matter);
|
||||
-- identical -> 99
|
||||
-- colours premultiplied by alpha: the colour of a transparent pixel does not matter
|
||||
local function psnr(a: buffer, b: string, opaque: boolean?): number
|
||||
local n = math.min(buffer.len(a), #b)
|
||||
local se = 0
|
||||
@@ -51,8 +47,7 @@ t:eq(Psd.name, "psd", "name")
|
||||
t:eq(Psd.category, "layered", "category")
|
||||
t:check(Psd.caps.decode and Psd.caps.encode, "caps")
|
||||
|
||||
-- PSNR floors for our flatten vs psd-tools' composite: blend modes where psd-tools' formulas differ from the W3C ones
|
||||
-- (Photoshop's own differ from both) get a lower bar
|
||||
-- psd-tools' blend formulas differ from the W3C ones (Photoshop's differ from both): lower floors for those
|
||||
local LOW = { ["blend-diss"] = 8, ["blend-hMix"] = 15, ["blend-sLit"] = 30, ["blend-vLit"] = 25, ["blend-lLit"] = 30, ["blend-pLit"] = 30, ["blend-div"] = 30, ["blend-idiv"] = 30, ["blend-fdiv"] = 25, ["blend-hue"] = 25, ["blend-sat"] = 25, ["blend-colr"] = 25, ["blend-lum"] = 25 }
|
||||
local samples = {}
|
||||
for _, c in Fx.cases do
|
||||
@@ -75,7 +70,6 @@ for _, c in Fx.cases do
|
||||
t:note("%s: merged image vs psd-tools %.1f dB", c.name, p)
|
||||
end
|
||||
end
|
||||
-- layers, in order, against psd-tools
|
||||
local ours = leaves(doc.layers)
|
||||
local ref = {}
|
||||
for _, l in c.layers do
|
||||
@@ -94,7 +88,6 @@ for _, c in Fx.cases do
|
||||
t:eq(Crc32.of(l.image.pixels), r.crc, c.name .. ": " .. r.name .. ": pixels")
|
||||
end
|
||||
end
|
||||
-- our flatten vs psd-tools' composite
|
||||
if c.flat and #ours > 0 then
|
||||
local flat = LayerOps.flatten(doc) :: any
|
||||
local p = psnr(flat.pixels, c.flat)
|
||||
@@ -109,7 +102,6 @@ for _, c in Fx.cases do
|
||||
end
|
||||
end
|
||||
|
||||
-- the full document's structure
|
||||
do
|
||||
local doc
|
||||
for _, c in Fx.cases do
|
||||
@@ -133,7 +125,6 @@ do
|
||||
local only = decode(Fx.cases[1].data, { layers = false })
|
||||
t:check(only and #only.layers == 0 and only.meta.composite, "layers = false: merged image only")
|
||||
|
||||
-- round trip: our PSD of the decoded document decodes to the same layers, and its merged image is our flatten
|
||||
local out, eerr = Psd.encode(doc)
|
||||
t:check(out, "encode: " .. tostring(eerr))
|
||||
local back = decode(out :: buffer)
|
||||
@@ -164,7 +155,6 @@ for _, c in Ours.checks do
|
||||
end
|
||||
t:note("psd-tools agrees with our PSD on %d facts", #Ours.checks)
|
||||
|
||||
-- errors
|
||||
do
|
||||
local _, e = decode("8BPS\0\1\0\0\0\0\0\0\0\3\0\0\0\10\0\0\0\10\0\8\0\3")
|
||||
t:check(e and e.code == Err.TRUNCATED, "truncated after the header: " .. tostring(e))
|
||||
|
||||
Reference in new issue
Block a user