merge ws/arch2: cpio ar/deb rpm .Z lz4 iso lha arj zoo cab, uu/yenc/binhex/macbinary/applesingle, d64 adf fat, bdf pcf psf fon type1 eot hershey
This commit is contained in:
commit
b5cdd77a5b
115 files changed
+17373
-29
No files matched your search
@@ -0,0 +1,73 @@
|
||||
-- codecs/font/Bitmap tests: 1-bit row pack / unpack round trips (MSB- and LSB-first, padded strides), the Font over a
|
||||
-- strike (glyphIndex / advance / rasterize / default glyph), Bitmap.strike of a bitmap font and of the first outline
|
||||
-- font from tools/fixtures/fonts.py (thresholded rasterization), and argument errors.
|
||||
local T = require("@tests/T")
|
||||
local Bitmap = require("@formats/codecs/font/Bitmap")
|
||||
local Ttf = require("@formats/font/ttf")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Fx = require("@tests/gen/fonts")
|
||||
|
||||
local t = T.suite("bitmap")
|
||||
|
||||
local rand = T.rng(3)
|
||||
for k = 1, 30 do
|
||||
local w, h = rand(40), rand(20)
|
||||
local px = buffer.create(w * h)
|
||||
for i = 0, w * h - 1 do
|
||||
if rand(2) == 1 then
|
||||
buffer.writeu8(px, i, 255)
|
||||
end
|
||||
end
|
||||
local stride = math.ceil(w / 8) + (k % 3)
|
||||
local lsb = k % 2 == 0
|
||||
local packed = Bitmap.pack(px, w, h, stride, lsb)
|
||||
t:eq(buffer.len(packed), stride * h, "pack size " .. k)
|
||||
t:eq(buffer.tostring(Bitmap.unpack(packed, 0, w, h, stride, lsb)), buffer.tostring(px), "round trip " .. k)
|
||||
end
|
||||
-- 0x81 = left and right pixel on (MSB first)
|
||||
t:eq(buffer.tostring(Bitmap.unpack(T.bytes({ 0x81 }), 0, 8, 1, 1)), "\255\0\0\0\0\0\0\255", "msb order")
|
||||
t:eq(buffer.tostring(Bitmap.unpack(T.bytes({ 0x01 }), 0, 2, 1, 1, true)), "\255\0", "lsb order")
|
||||
t:eq(buffer.tostring(Bitmap.unpack(T.bytes({ 0xFF }), 0, 8, 2, 1)), string.rep("\255", 8) .. string.rep("\0", 8), "past the end reads 0")
|
||||
|
||||
local A = { codepoint = 65, width = 2, height = 2, left = 1, top = 7, advance = 4, pixels = T.bytes({ 255, 0, 0, 255 }) }
|
||||
local strike = { size = 8, ascent = 7, descent = 1, glyphs = { { width = 0, height = 0, left = 0, top = 0, advance = 3, pixels = buffer.create(0) }, A }, default = 0 }
|
||||
local font = Bitmap.font(strike, { family = "Test" })
|
||||
t:eq(font.kind, "font", "kind")
|
||||
t:eq(font.unitsPerEm, 8, "unitsPerEm")
|
||||
t:eq(font.descent, -1, "descent")
|
||||
t:eq(font:glyphIndex(65), 1, "glyphIndex")
|
||||
t:eq(font:glyphIndex(66), 0, "default glyph")
|
||||
t:eq(font:advance(1), 4, "advance")
|
||||
t:eq(font:outline(1), nil, "no outline")
|
||||
local img = font:rasterize(1, 16)
|
||||
t:check(img and img.format == "alpha8" and img.width == 2 and buffer.tostring(img.pixels) == "\255\0\0\255", "rasterize")
|
||||
t:eq(img and img.meta.top, 7, "rasterize top")
|
||||
t:eq(img and img.meta.scale, 2, "rasterize scale")
|
||||
t:eq(font:rasterize(9, 8), nil, "rasterize out of range")
|
||||
t:eq(Bitmap.strike(font), strike, "strike of a bitmap font")
|
||||
|
||||
local s1, e1 = Bitmap.strike({})
|
||||
t:check(s1 == nil and e1 and e1.code == Err.ARG, "strike of a non-font")
|
||||
if Fx.fonts[1] then
|
||||
local ttf = Ttf.decode(Bytes.reader(buffer.fromstring(Fx.fonts[1].data)))
|
||||
local s, err = Bitmap.strike(ttf, { px = 16, chars = "AB" })
|
||||
t:check(s, "strike of " .. Fx.fonts[1].name .. ": " .. tostring(err))
|
||||
if s then
|
||||
t:eq(#s.glyphs, 3, "strike glyphs")
|
||||
local g = s.glyphs[2]
|
||||
t:eq(g.codepoint, 65, "strike codepoint")
|
||||
t:check(g.width > 4 and g.height > 6 and g.top > 6 and g.advance > 4, "strike A metrics")
|
||||
local on = 0
|
||||
for i = 0, buffer.len(g.pixels) - 1 do
|
||||
local v = buffer.readu8(g.pixels, i)
|
||||
t:check(v == 0 or v == 255, "binary pixels")
|
||||
if v == 255 then
|
||||
on += 1
|
||||
end
|
||||
end
|
||||
t:check(on > 10, "A has ink")
|
||||
end
|
||||
t:check(select(2, Bitmap.strike(ttf, { px = 0 })) ~= nil, "px 0 refused")
|
||||
end
|
||||
t:done()
|
||||
@@ -0,0 +1,75 @@
|
||||
-- codecs/compress/UnixCompress tests: ncompress 5.0 files (widths 10..16, block mode, CLEAR codes after the ratio
|
||||
-- check, empty / one-byte / random inputs) decode to their inputs; compress() gives ncompress's bytes for the same input
|
||||
-- and width; non-block-mode streams; errors; the fuzz pass. Fixtures: tools/fixtures/z.py.
|
||||
local T = require("@tests/T")
|
||||
local UnixCompress = require("@formats/codecs/compress/UnixCompress")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Fx = require("@tests/gen/z")
|
||||
|
||||
local t = T.suite("unixcompress")
|
||||
|
||||
for _, c in Fx.cases do
|
||||
local out, err = UnixCompress.decompress(c.z)
|
||||
t:check(out, c.name .. ": decompress: " .. tostring(err))
|
||||
t:eq(buffer.len(out), #c.input, c.name .. ": size")
|
||||
t:eq(Crc32.of(out), Crc32.of(buffer.fromstring(c.input)), c.name .. ": data")
|
||||
local z, zerr = UnixCompress.compress(c.input, nil, nil, { maxBits = c.bits })
|
||||
t:check(z, c.name .. ": compress: " .. tostring(zerr))
|
||||
t:eq(buffer.len(z), #c.z, c.name .. ": compressed size = ncompress")
|
||||
t:check(buffer.tostring(z) == c.z, c.name .. ": bytes identical to ncompress -b " .. c.bits)
|
||||
t:note("%-12s %7d -> %7d bytes (-b %d)", c.name, #c.input, #c.z, c.bits)
|
||||
end
|
||||
|
||||
-- 9-bit codes, LSB first, after a .Z header with the given flags byte
|
||||
local function pack(flags: number, codes: { number }): buffer
|
||||
local acc, nb, bytes = 0, 0, { 0x1F, 0x9D, flags }
|
||||
for _, c in codes do
|
||||
acc += c * 2 ^ nb
|
||||
nb += 9
|
||||
while nb >= 8 do
|
||||
table.insert(bytes, acc % 256)
|
||||
acc = acc // 256
|
||||
nb -= 8
|
||||
end
|
||||
end
|
||||
if nb > 0 then
|
||||
table.insert(bytes, acc)
|
||||
end
|
||||
return T.bytes(bytes)
|
||||
end
|
||||
|
||||
-- a non-block-mode stream (no CLEAR code; 256 is the first table entry): "ABABABA"
|
||||
do
|
||||
local out = UnixCompress.decompress(pack(0x10, { 65, 66, 256, 258 }))
|
||||
t:eq(out and buffer.tostring(out), "ABABABA", "non-block mode")
|
||||
end
|
||||
|
||||
-- errors
|
||||
do
|
||||
local _, e1 = UnixCompress.decompress("\31\157")
|
||||
t:check(e1 and e1.code == Err.TRUNCATED, "short header")
|
||||
local _, e2 = UnixCompress.decompress("\31\158\144")
|
||||
t:check(e2 and e2.code == Err.CORRUPT, "bad magic")
|
||||
local _, e3 = UnixCompress.decompress("\31\157\145")
|
||||
t:check(e3 and e3.code == Err.UNSUPPORTED, "17-bit codes")
|
||||
local _, e4 = UnixCompress.decompress(pack(0x90, { 65, 400 }))
|
||||
t:check(e4 and e4.code == Err.CORRUPT, "a code past the table: " .. tostring(e4))
|
||||
local _, e5 = UnixCompress.decompress(Fx.cases[5].z, nil, nil, { maxBytes = 1000 })
|
||||
t:check(e5 and e5.code == Err.LIMIT, "maxBytes")
|
||||
local _, e6 = UnixCompress.compress("x", nil, nil, { maxBits = 17 })
|
||||
t:check(e6 and e6.code == Err.ARG, "maxBits 17")
|
||||
end
|
||||
|
||||
local samples = {}
|
||||
for _, c in Fx.cases do
|
||||
if #c.z < 4000 and #c.z > 3 then
|
||||
table.insert(samples, c.z)
|
||||
end
|
||||
end
|
||||
table.insert(samples, string.sub(Fx.cases[#Fx.cases].z, 1, 3000))
|
||||
t:fuzz("decompress", function(b: buffer)
|
||||
return UnixCompress.decompress(b, nil, nil, { maxBytes = 2 ^ 22 })
|
||||
end, samples, { mutations = 40, keepHeader = 3 })
|
||||
|
||||
t:done()
|
||||
Reference in new issue
Block a user