From 58b0df8b21c725847b1046de1ae6945b1c86e03d Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 01:49:17 -0500 Subject: [PATCH] tests/layered: comments: specs only --- tests/layered/aseprite.luau | 13 ++----------- tests/layered/ora.luau | 7 ++----- tests/layered/psd.luau | 18 ++++-------------- 3 files changed, 8 insertions(+), 30 deletions(-) diff --git a/tests/layered/aseprite.luau b/tests/layered/aseprite.luau index 27b2014..b816ba2 100644 --- a/tests/layered/aseprite.luau +++ b/tests/layered/aseprite.luau @@ -1,8 +1,5 @@ --- layered/aseprite tests: sprites written by tools/fixtures/aseprite.py (RGBA / grayscale / indexed; raw, zlib and --- linked cels; groups, hidden layers, blend modes, layer and cel opacity; old and new palettes; tags; user data) and --- by LibreSprite (re-saved and from a GIF): every cel's pixels and position, and our flatten of every frame against --- LibreSprite's rendering (PSNR); our encoder's sprite rendered by LibreSprite (tools/fixtures/_ours.luau); round --- trips (linked cels kept), the contract and the fuzz pass. Fixtures: tools/fixtures/aseprite.py. +-- layered/aseprite tests: generated and LibreSprite sprites, flatten against LibreSprite's rendering by PSNR. +-- Fixtures: tools/fixtures/aseprite.py. local T = require("@tests/T") local Ase = require("@rosetta/layered/aseprite") local LayerOps = require("@rosetta/ops/LayerOps") @@ -35,7 +32,6 @@ local function psnr(a: buffer, b: string): number end return 10 * math.log10(255 * 255 / (se / n)) end --- the n-th node (groups included, file order) of a frame's tree local function nodes(layers: { any }, out: { any }?): { any } local o = out or {} for _, l in layers do @@ -63,7 +59,6 @@ for _, c in Fx.cases do t:check(l and l.x == cel.x and l.y == cel.y and l.image.width == cel.w and l.image.height == cel.h, label .. ": position / size") t:eq(Crc32.of(l.image.pixels), cel.crc, label .. ": pixels") end - -- our flatten vs LibreSprite's rendering of each frame for fi, want in c.frames do local img = LayerOps.flatten(doc, { frame = fi }) :: any local p = psnr(img.pixels, want) @@ -75,7 +70,6 @@ for _, c in Fx.cases do table.insert(samples, c.data) end --- the hand-made RGBA sprite's details do local doc = decode(Fx.cases[1].data) local L = doc.layers @@ -101,7 +95,6 @@ do t:eq(#idx.meta.palette, 5, "old palette chunk") t:eq(idx.meta.colorDepth, 8, "indexed") - -- round trips: every frame's nodes and pixels, linked cels stay shared, depth kept for ci, c in Fx.cases do local d = decode(c.data) local out, eerr = Ase.encode(d) @@ -132,7 +125,6 @@ do end table.insert(samples, buffer.tostring(out :: buffer)) end - -- forced depths local _, e = Ase.encode(doc, { depth = 16 }) t:check(e and e.code == Err.ARG, "colour sprite as grayscale: " .. tostring(e)) local g = decode(Fx.cases[2].data) @@ -140,7 +132,6 @@ do t:eq(g32.meta.colorDepth, 32, "grayscale written as RGBA") end --- LibreSprite renders our encoder's sprite like our flatten does t:eq(#Ours.frames, Ours.nframes, "LibreSprite read every frame of our sprite") for fi, want in Ours.frames do local ours = Ours.ours[fi] diff --git a/tests/layered/ora.luau b/tests/layered/ora.luau index c70114b..6bc4c9e 100644 --- a/tests/layered/ora.luau +++ b/tests/layered/ora.luau @@ -1,7 +1,5 @@ --- layered/ora tests: OpenRaster files assembled by the spec (offsets, opacity, hidden, composite-ops, nested isolate / --- auto stacks, no merged image) against the attributes and pixels written there; our encoder's file taken apart by --- python (stored mimetype first, stack.xml, Pillow's read of every PNG); round trips; hooks; errors; the fuzz no-throw --- pass. Fixtures: tools/fixtures/ora.py. +-- layered/ora tests: spec-assembled OpenRaster files; our encoder's output checked by python and Pillow. +-- Fixtures: tools/fixtures/ora.py. local T = require("@tests/T") local Ora = require("@rosetta/layered/ora") local Png = require("@rosetta/image/png") @@ -67,7 +65,6 @@ for _, c in Fx.cases do if c.dpi then t:eq(doc.meta.dpi.x, c.dpi, c.name .. ": dpi") end - -- round trip local enc, eerr = Ora.encode(doc, hooks) t:check(enc, c.name .. ": encode " .. tostring(eerr)) local back = Ora.decode(Bytes.reader(enc :: buffer), hooks) diff --git a/tests/layered/psd.luau b/tests/layered/psd.luau index 5b45cb8..5b3ee11 100644 --- a/tests/layered/psd.luau +++ b/tests/layered/psd.luau @@ -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))