ws-cleanup-types: archive, audio, data, font, image, layered, music, playlist, subtitle, vector, video: annotations, casts, one value per re-assignment where the solver loses the type
This commit is contained in:
1 parent
dc98aec2ec
commit
f459b2dcdf
44 files changed
+172
-119
No files matched your search
@@ -177,7 +177,8 @@ local function folder(r: Bytes.Reader): Folder
|
|||||||
check(r)
|
check(r)
|
||||||
local nin, nout = 1, 1
|
local nin, nout = 1, 1
|
||||||
if bit32.band(flags, 0x10) ~= 0 then
|
if bit32.band(flags, 0x10) ~= 0 then
|
||||||
nin, nout = number(r), number(r)
|
nin = number(r)
|
||||||
|
nout = number(r)
|
||||||
if nin > 64 or nout > 64 then
|
if nin > 64 or nout > 64 then
|
||||||
bad(r, "bad coder stream count")
|
bad(r, "bad coder stream count")
|
||||||
end
|
end
|
||||||
@@ -416,11 +417,11 @@ local function filesInfo(r: Bytes.Reader): { File }
|
|||||||
if n > 1000000 then
|
if n > 1000000 then
|
||||||
bad(r, "too many files", Err.LIMIT)
|
bad(r, "too many files", Err.LIMIT)
|
||||||
end
|
end
|
||||||
local files: { File } = table.create(n)
|
local files: { File } = table.create(n) :: { File }
|
||||||
for i = 1, n do
|
for i = 1, n do
|
||||||
files[i] = { name = "", emptyStream = false, emptyFile = false, anti = false }
|
files[i] = { name = "", emptyStream = false, emptyFile = false, anti = false }
|
||||||
end
|
end
|
||||||
local empties = {}
|
local empties: { number } = {}
|
||||||
while true do
|
while true do
|
||||||
local t = byte(r)
|
local t = byte(r)
|
||||||
if t == K.End then
|
if t == K.End then
|
||||||
|
|||||||
@@ -144,7 +144,9 @@ local function decodeFolder(ctx: Ctx, s: Header.Streams, f: Header.Folder): (buf
|
|||||||
if not b then
|
if not b then
|
||||||
return nil, e
|
return nil, e
|
||||||
end
|
end
|
||||||
src, so, sl = b, 0, buffer.len(b)
|
src = b
|
||||||
|
so = 0
|
||||||
|
sl = buffer.len(b)
|
||||||
else
|
else
|
||||||
local k = table.find(f.packed, inIdx)
|
local k = table.find(f.packed, inIdx)
|
||||||
if not k then
|
if not k then
|
||||||
@@ -162,7 +164,7 @@ local function decodeFolder(ctx: Ctx, s: Header.Streams, f: Header.Folder): (buf
|
|||||||
src = ctx.buf
|
src = ctx.buf
|
||||||
end
|
end
|
||||||
local id = c.id
|
local id = c.id
|
||||||
local opts = { maxBytes = ctx.maxBytes }
|
local opts: { maxBytes: number?, verify: boolean? } = { maxBytes = ctx.maxBytes }
|
||||||
if id == "\0" then
|
if id == "\0" then
|
||||||
if sl < size then
|
if sl < size then
|
||||||
return nil, Err.new(Err.TRUNCATED, "short stored stream")
|
return nil, Err.new(Err.TRUNCATED, "short stored stream")
|
||||||
@@ -226,7 +228,7 @@ local function folderMethod(f: Header.Folder): string
|
|||||||
end
|
end
|
||||||
|
|
||||||
function SevenZip.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Archive?, Err.Err?)
|
function SevenZip.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Archive?, Err.Err?)
|
||||||
local o = opts or {}
|
local o: DecodeOptions = opts or {}
|
||||||
local maxBytes = if type(o.maxBytes) == "number" then o.maxBytes else 2 ^ 30
|
local maxBytes = if type(o.maxBytes) == "number" then o.maxBytes else 2 ^ 30
|
||||||
local checkCrc = o.checkCrc ~= false
|
local checkCrc = o.checkCrc ~= false
|
||||||
local b, base, limit = r.buf, r.base, r.limit
|
local b, base, limit = r.buf, r.base, r.limit
|
||||||
@@ -280,17 +282,19 @@ function SevenZip.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Archive?
|
|||||||
if f.crc and Crc32.raw(hb, 0, buffer.len(hb)) ~= f.crc then
|
if f.crc and Crc32.raw(hb, 0, buffer.len(hb)) ~= f.crc then
|
||||||
return nil, Err.new(Err.CHECKSUM, "encoded header CRC-32 mismatch")
|
return nil, Err.new(Err.CHECKSUM, "encoded header CRC-32 mismatch")
|
||||||
end
|
end
|
||||||
hbuf, hoff, hlen = hb, 0, buffer.len(hb)
|
hbuf = hb
|
||||||
|
hoff = 0
|
||||||
|
hlen = buffer.len(hb)
|
||||||
end
|
end
|
||||||
if not parsed then
|
if not parsed then
|
||||||
return nil, Err.new(Err.CORRUPT, "nested encoded headers")
|
return nil, Err.new(Err.CORRUPT, "nested encoded headers")
|
||||||
end
|
end
|
||||||
local s = parsed.streams or { packPos = 0, packSizes = {}, folders = {}, subSizes = {}, subCrcs = {} }
|
local s: Header.Streams = parsed.streams or { packPos = 0, packSizes = {}, folders = {}, subSizes = {}, subCrcs = {} }
|
||||||
a.meta.folders = #s.folders
|
a.meta.folders = #s.folders
|
||||||
a.meta.solid = false
|
a.meta.solid = false
|
||||||
-- folder caches and the substream -> folder map
|
-- folder caches and the substream -> folder map
|
||||||
local cache: { [number]: buffer } = {}
|
local cache: { [number]: buffer } = {}
|
||||||
local subFolder, subOffset = {}, {}
|
local subFolder: { number }, subOffset: { number } = {}, {}
|
||||||
do
|
do
|
||||||
local si = 1
|
local si = 1
|
||||||
for fi, f in s.folders do
|
for fi, f in s.folders do
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ local function header(b: buffer, o: number, e: number): { [string]: any }
|
|||||||
if bit32.band(flg, 4) ~= 0 and q + 2 <= e then
|
if bit32.band(flg, 4) ~= 0 and q + 2 <= e then
|
||||||
q += 2 + buffer.readu16(b, q)
|
q += 2 + buffer.readu16(b, q)
|
||||||
end
|
end
|
||||||
for _, f in { { 8, "name" }, { 16, "comment" } } do
|
for _, f in { { 8, "name" }, { 16, "comment" } } :: { { any } } do
|
||||||
if bit32.band(flg, f[1]) ~= 0 then
|
if bit32.band(flg, f[1]) ~= 0 then
|
||||||
local s = q
|
local s = q
|
||||||
while q < e and buffer.readu8(b, q) ~= 0 do
|
while q < e and buffer.readu8(b, q) ~= 0 do
|
||||||
@@ -85,7 +85,7 @@ function Gzip.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?)
|
|||||||
size = buffer.len(out),
|
size = buffer.len(out),
|
||||||
compressedSize = r.limit - r.base,
|
compressedSize = r.limit - r.base,
|
||||||
method = "deflate",
|
method = "deflate",
|
||||||
mtime = if h.mtime and h.mtime > 0 then h.mtime else nil,
|
mtime = if h.mtime and h.mtime > 0 then h.mtime :: number else nil,
|
||||||
dir = false,
|
dir = false,
|
||||||
data = out,
|
data = out,
|
||||||
})
|
})
|
||||||
@@ -94,7 +94,7 @@ end
|
|||||||
|
|
||||||
-- ------------------------------------------------------------------------------------------------ encode
|
-- ------------------------------------------------------------------------------------------------ encode
|
||||||
function Gzip.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
|
function Gzip.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
|
||||||
local o = opts or {}
|
local o: EncodeOptions = opts or {}
|
||||||
local level = if o.level == nil then 6 else o.level
|
local level = if o.level == nil then 6 else o.level
|
||||||
if type(level) ~= "number" or level < 0 or level > 9 or level % 1 ~= 0 then
|
if type(level) ~= "number" or level < 0 or level > 9 or level % 1 ~= 0 then
|
||||||
return nil, Err.new(Err.ARG, "level must be 0..9")
|
return nil, Err.new(Err.ARG, "level must be 0..9")
|
||||||
@@ -111,7 +111,7 @@ function Gzip.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
|
|||||||
if not items then
|
if not items then
|
||||||
return nil, Err.new(Err.ARG, "expected an Archive, a buffer or a string")
|
return nil, Err.new(Err.ARG, "expected an Archive, a buffer or a string")
|
||||||
end
|
end
|
||||||
local files = {}
|
local files: typeof(items) = {}
|
||||||
for _, it in items do
|
for _, it in items do
|
||||||
if not it.entry.dir then
|
if not it.entry.dir then
|
||||||
table.insert(files, it)
|
table.insert(files, it)
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ end
|
|||||||
|
|
||||||
-- ------------------------------------------------------------------------------------------------ decode
|
-- ------------------------------------------------------------------------------------------------ decode
|
||||||
function Xz.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Archive?, Err.Err?)
|
function Xz.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Archive?, Err.Err?)
|
||||||
local o = opts or {}
|
local o: DecodeOptions = opts or {}
|
||||||
local n = r.limit - r.base
|
local n = r.limit - r.base
|
||||||
local out, res
|
local out, res
|
||||||
local method
|
local method
|
||||||
|
|||||||
@@ -350,7 +350,7 @@ local function source(r: Bytes.Reader, p: Parsed): (Source?, Err.Err?)
|
|||||||
return nil, Err.new(Err.CORRUPT, "compressed CAF without a packet table")
|
return nil, Err.new(Err.CORRUPT, "compressed CAF without a packet table")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local offsets = table.create(#sizes, 0)
|
local offsets = table.create(#(sizes :: { number }), 0)
|
||||||
local o = p.dataStart
|
local o = p.dataStart
|
||||||
for i, s in sizes :: { number } do
|
for i, s in sizes :: { number } do
|
||||||
offsets[i] = o
|
offsets[i] = o
|
||||||
@@ -585,7 +585,7 @@ end
|
|||||||
|
|
||||||
-- encode(audio | decoder, opts?) -> buffer | nil, Err
|
-- encode(audio | decoder, opts?) -> buffer | nil, Err
|
||||||
function Caf.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
|
function Caf.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
|
||||||
local o = opts or {}
|
local o: EncodeOptions = opts or {}
|
||||||
if type(value) ~= "table" or type(value.sampleRate) ~= "number" or type(value.channels) ~= "number" then
|
if type(value) ~= "table" or type(value.sampleRate) ~= "number" or type(value.channels) ~= "number" then
|
||||||
return nil, Err.new(Err.ARG, "expected an Audio or a Decoder")
|
return nil, Err.new(Err.ARG, "expected an Audio or a Decoder")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ end
|
|||||||
|
|
||||||
-- open(r, opts?) -> Types.Decoder | nil, Err
|
-- open(r, opts?) -> Types.Decoder | nil, Err
|
||||||
function M4a.open(r: Bytes.Reader, opts: DecodeOptions?): (Types.Decoder?, Err.Err?)
|
function M4a.open(r: Bytes.Reader, opts: DecodeOptions?): (Types.Decoder?, Err.Err?)
|
||||||
local o = opts or {}
|
local o: DecodeOptions = opts or {}
|
||||||
local movie, err = IsoBmff.parse(r, { maxSamples = o.maxSamples })
|
local movie, err = IsoBmff.parse(r, { maxSamples = o.maxSamples })
|
||||||
if not movie then
|
if not movie then
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -169,9 +169,9 @@ function M4a.open(r: Bytes.Reader, opts: DecodeOptions?): (Types.Decoder?, Err.E
|
|||||||
-- iTunes gapless info (fdkaac, iTunes) when there is no edit list: " 0 <priming> <padding> <samples> ..." (hex)
|
-- iTunes gapless info (fdkaac, iTunes) when there is no edit list: " 0 <priming> <padding> <samples> ..." (hex)
|
||||||
local smpb = tags.iTunSMPB
|
local smpb = tags.iTunSMPB
|
||||||
if gapless and not t.edits and smpb then
|
if gapless and not t.edits and smpb then
|
||||||
local f = {}
|
local f: { number } = {}
|
||||||
for w in string.gmatch(smpb, "%x+") do
|
for w in string.gmatch(smpb, "%x+") do
|
||||||
table.insert(f, tonumber(w, 16))
|
table.insert(f, tonumber(w, 16) :: number)
|
||||||
end
|
end
|
||||||
if #f >= 4 and f[2] and f[4] and f[4] > 0 and f[2] + f[4] <= total then
|
if #f >= 4 and f[2] and f[4] and f[4] > 0 and f[2] + f[4] <= total then
|
||||||
skip = f[2]
|
skip = f[2]
|
||||||
@@ -337,7 +337,7 @@ end
|
|||||||
-- ------------------------------------------------------------------------------------------------ encode
|
-- ------------------------------------------------------------------------------------------------ encode
|
||||||
-- encode(audio | decoder, opts?) -> buffer | nil, Err: an ALAC M4A
|
-- encode(audio | decoder, opts?) -> buffer | nil, Err: an ALAC M4A
|
||||||
function M4a.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
|
function M4a.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
|
||||||
local o = opts or {}
|
local o: EncodeOptions = opts or {}
|
||||||
if type(value) ~= "table" or type(value.sampleRate) ~= "number" or type(value.channels) ~= "number" then
|
if type(value) ~= "table" or type(value.sampleRate) ~= "number" or type(value.channels) ~= "number" then
|
||||||
return nil, Err.new(Err.ARG, "expected an Audio or a Decoder")
|
return nil, Err.new(Err.ARG, "expected an Audio or a Decoder")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -561,7 +561,8 @@ local function intensityStereo(h1: number, h3: number, gr: number)
|
|||||||
kr = 1
|
kr = 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
kl, kr = f32(kl * s), f32(kr * s)
|
kl = f32(kl * s)
|
||||||
|
kr = f32(kr * s)
|
||||||
for k = left * 4, (left + n - 1) * 4, 4 do
|
for k = left * 4, (left + n - 1) * 4, 4 do
|
||||||
local v = rf(GRBUF, k)
|
local v = rf(GRBUF, k)
|
||||||
wf(GRBUF, k + 2304, v * kr)
|
wf(GRBUF, k + 2304, v * kr)
|
||||||
@@ -1183,8 +1184,14 @@ local function synth(xl: number, dstl: number, nch: number, lins: number)
|
|||||||
a3 += z3 * w0 - y3 * w1
|
a3 += z3 * w0 - y3 * w1
|
||||||
vz -= 256
|
vz -= 256
|
||||||
vy += 256
|
vy += 256
|
||||||
z0, z1, z2, z3 = rf(SYN, vz), rf(SYN, vz + 4), rf(SYN, vz + 8), rf(SYN, vz + 12)
|
z0 = rf(SYN, vz)
|
||||||
y0, y1, y2, y3 = rf(SYN, vy), rf(SYN, vy + 4), rf(SYN, vy + 8), rf(SYN, vy + 12)
|
z1 = rf(SYN, vz + 4)
|
||||||
|
z2 = rf(SYN, vz + 8)
|
||||||
|
z3 = rf(SYN, vz + 12)
|
||||||
|
y0 = rf(SYN, vy)
|
||||||
|
y1 = rf(SYN, vy + 4)
|
||||||
|
y2 = rf(SYN, vy + 8)
|
||||||
|
y3 = rf(SYN, vy + 12)
|
||||||
b0 += z0 * w3 + y0 * w2
|
b0 += z0 * w3 + y0 * w2
|
||||||
b1 += z1 * w3 + y1 * w2
|
b1 += z1 * w3 + y1 * w2
|
||||||
b2 += z2 * w3 + y2 * w2
|
b2 += z2 * w3 + y2 * w2
|
||||||
@@ -1212,8 +1219,10 @@ local function synth(xl: number, dstl: number, nch: number, lins: number)
|
|||||||
a2 += z2 * w0 - y2 * w1
|
a2 += z2 * w0 - y2 * w1
|
||||||
vz -= 256
|
vz -= 256
|
||||||
vy += 256
|
vy += 256
|
||||||
z0, z2 = rf(SYN, vz), rf(SYN, vz + 8)
|
z0 = rf(SYN, vz)
|
||||||
y0, y2 = rf(SYN, vy), rf(SYN, vy + 8)
|
z2 = rf(SYN, vz + 8)
|
||||||
|
y0 = rf(SYN, vy)
|
||||||
|
y2 = rf(SYN, vy + 8)
|
||||||
b0 += z0 * w3 + y0 * w2
|
b0 += z0 * w3 + y0 * w2
|
||||||
b2 += z2 * w3 + y2 * w2
|
b2 += z2 * w3 + y2 * w2
|
||||||
a0 += y0 * w3 - z0 * w2
|
a0 += y0 * w3 - z0 * w2
|
||||||
|
|||||||
@@ -375,7 +375,9 @@ function Encode2.encode(src: Source, opts: Options): (buffer?, string?)
|
|||||||
local q = floor((x * inv + 1) * L / 2)
|
local q = floor((x * inv + 1) * L / 2)
|
||||||
return if q < 0 then 0 elseif q > L - 1 then L - 1 else q
|
return if q < 0 then 0 elseif q > L - 1 then L - 1 else q
|
||||||
end
|
end
|
||||||
q0, q1, q2 = quant(sb[o + 1]), quant(sb[o + 2]), quant(sb[o + 3])
|
q0 = quant(sb[o + 1])
|
||||||
|
q1 = quant(sb[o + 2])
|
||||||
|
q2 = quant(sb[o + 3])
|
||||||
end
|
end
|
||||||
if ba >= 17 then
|
if ba >= 17 then
|
||||||
put(w, q0 + L * (q1 + L * q2), tripleBits(ba))
|
put(w, q0 + L * (q1 + L * q2), tripleBits(ba))
|
||||||
|
|||||||
@@ -179,7 +179,8 @@ local function parseV2(b: buffer, o: number, size: number, tags: any)
|
|||||||
local p, e = o + 10, bodyEnd
|
local p, e = o + 10, bodyEnd
|
||||||
if band(flags, 0x80) ~= 0 and ver < 4 then
|
if band(flags, 0x80) ~= 0 and ver < 4 then
|
||||||
body = deunsync(b, p, e)
|
body = deunsync(b, p, e)
|
||||||
p, e = 0, buffer.len(body)
|
p = 0
|
||||||
|
e = buffer.len(body)
|
||||||
end
|
end
|
||||||
if band(flags, 0x40) ~= 0 and ver >= 3 and p + 4 <= e then
|
if band(flags, 0x40) ~= 0 and ver >= 3 and p + 4 <= e then
|
||||||
-- extended header: v2.3 size excludes its own 4 bytes, v2.4 includes them (syncsafe)
|
-- extended header: v2.3 size excludes its own 4 bytes, v2.4 includes them (syncsafe)
|
||||||
@@ -216,7 +217,8 @@ local function parseV2(b: buffer, o: number, size: number, tags: any)
|
|||||||
end
|
end
|
||||||
if not skip and band(fflags, 0x0002) ~= 0 and fs < fe then
|
if not skip and band(fflags, 0x0002) ~= 0 and fs < fe then
|
||||||
fb = deunsync(body, fs, fe)
|
fb = deunsync(body, fs, fe)
|
||||||
fs, fe = 0, buffer.len(fb)
|
fs = 0
|
||||||
|
fe = buffer.len(fb)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not skip and fs < fe then
|
if not skip and fs < fe then
|
||||||
@@ -273,7 +275,7 @@ function Tags.parse(b: buffer): (any, number, number)
|
|||||||
if size >= 128 and buffer.readstring(b, start + size - 128, 3) == "TAG" then
|
if size >= 128 and buffer.readstring(b, start + size - 128, 3) == "TAG" then
|
||||||
local o = start + size - 128
|
local o = start + size - 128
|
||||||
tags.id3v1 = true
|
tags.id3v1 = true
|
||||||
local v1 = {
|
local v1: { [string]: any } = {
|
||||||
title = v1String(b, o + 3, 30),
|
title = v1String(b, o + 3, 30),
|
||||||
artist = v1String(b, o + 33, 30),
|
artist = v1String(b, o + 33, 30),
|
||||||
album = v1String(b, o + 63, 30),
|
album = v1String(b, o + 63, 30),
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ local function bigText(s: string): string
|
|||||||
end
|
end
|
||||||
-- text + 1 for a decimal string
|
-- text + 1 for a decimal string
|
||||||
local function incText(s: string): string
|
local function incText(s: string): string
|
||||||
local digits = table.create(#s)
|
local digits: { number } = table.create(#s) :: { number }
|
||||||
for i = 1, #s do
|
for i = 1, #s do
|
||||||
digits[i] = string.byte(s, i) - 48
|
digits[i] = string.byte(s, i) - 48
|
||||||
end
|
end
|
||||||
@@ -73,7 +73,7 @@ local function incText(s: string): string
|
|||||||
digits[i] = 0
|
digits[i] = 0
|
||||||
i -= 1
|
i -= 1
|
||||||
end
|
end
|
||||||
local out = table.create(#digits)
|
local out: { string } = table.create(#digits) :: { string }
|
||||||
for k, d in digits do
|
for k, d in digits do
|
||||||
out[k] = string.char(48 + d)
|
out[k] = string.char(48 + d)
|
||||||
end
|
end
|
||||||
@@ -296,11 +296,11 @@ function item(st: St, depth: number): (any, string?)
|
|||||||
table.insert(t, v)
|
table.insert(t, v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if n > r:remaining() then
|
if (n :: number) > r:remaining() then
|
||||||
return nil, "array count past the end"
|
return nil, "array count past the end"
|
||||||
end
|
end
|
||||||
local t = table.create(n)
|
local t = table.create(n :: number)
|
||||||
for k = 1, n do
|
for k = 1, n :: number do
|
||||||
local v, ve = item(st, depth + 1)
|
local v, ve = item(st, depth + 1)
|
||||||
if ve then
|
if ve then
|
||||||
return nil, ve
|
return nil, ve
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ function Csv.sniff(r: Bytes.Reader): number
|
|||||||
end
|
end
|
||||||
for _, d in { ",", "\t", ";" } do
|
for _, d in { ",", "\t", ";" } do
|
||||||
local _, c1 = gsub(l1, d, "")
|
local _, c1 = gsub(l1, d, "")
|
||||||
local _, c2 = gsub(l2, d, "")
|
local _, c2 = gsub(l2 :: string, d, "")
|
||||||
if c1 > 0 and c1 == c2 then
|
if c1 > 0 and c1 == c2 then
|
||||||
return 0.15
|
return 0.15
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -137,11 +137,11 @@ function Ini.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?)
|
|||||||
seenKeys[cur] = seen
|
seenKeys[cur] = seen
|
||||||
end
|
end
|
||||||
if seen[key :: string] and o.strict then
|
if seen[key :: string] and o.strict then
|
||||||
return nil, Err.new(Err.CORRUPT, "duplicate key " .. key, lineStart)
|
return nil, Err.new(Err.CORRUPT, "duplicate key " .. (key :: string), lineStart)
|
||||||
end
|
end
|
||||||
seen[key :: string] = true
|
seen[key :: string] = true
|
||||||
if cur == root and type(root[key]) == "table" then
|
if cur == root and type(root[key]) == "table" then
|
||||||
return nil, Err.new(Err.CORRUPT, "top-level key " .. key .. " has the name of a section", lineStart)
|
return nil, Err.new(Err.CORRUPT, "top-level key " .. (key :: string) .. " has the name of a section", lineStart)
|
||||||
end
|
end
|
||||||
Types.set(cur, key, value)
|
Types.set(cur, key, value)
|
||||||
lastKey, lastIndent, lastTable = key, indent, cur
|
lastKey, lastIndent, lastTable = key, indent, cur
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ function Decode.decode(s: string, opts: Options?): (any, any, number?)
|
|||||||
|
|
||||||
-- a (dotted) key: { parts }, next | nil
|
-- a (dotted) key: { parts }, next | nil
|
||||||
local function key(i: number): ({ string }?, number)
|
local function key(i: number): ({ string }?, number)
|
||||||
local keys = {}
|
local keys: { string } = {}
|
||||||
while true do
|
while true do
|
||||||
i = ws(i)
|
i = ws(i)
|
||||||
local c = byte(s, i)
|
local c = byte(s, i)
|
||||||
@@ -240,7 +240,7 @@ function Decode.decode(s: string, opts: Options?): (any, any, number?)
|
|||||||
if k == nil then
|
if k == nil then
|
||||||
return nil, 0
|
return nil, 0
|
||||||
end
|
end
|
||||||
table.insert(keys, k)
|
table.insert(keys, k :: string)
|
||||||
i = ws(i)
|
i = ws(i)
|
||||||
if byte(s, i) == 46 then
|
if byte(s, i) == 46 then
|
||||||
i += 1
|
i += 1
|
||||||
@@ -313,7 +313,7 @@ function Decode.decode(s: string, opts: Options?): (any, any, number?)
|
|||||||
end
|
end
|
||||||
return if sign == "-" then -v else v, nexti
|
return if sign == "-" then -v else v, nexti
|
||||||
end
|
end
|
||||||
local text = sign .. digits
|
local text: string = (sign :: string) .. digits
|
||||||
local frac, r2 = match(rest :: string, "^%.([%d_]*)(.*)$")
|
local frac, r2 = match(rest :: string, "^%.([%d_]*)(.*)$")
|
||||||
if frac then
|
if frac then
|
||||||
if not digitsOk(frac, "%d") then
|
if not digitsOk(frac, "%d") then
|
||||||
@@ -324,10 +324,10 @@ function Decode.decode(s: string, opts: Options?): (any, any, number?)
|
|||||||
end
|
end
|
||||||
if rest ~= "" then
|
if rest ~= "" then
|
||||||
local es, ed = match(rest :: string, "^[eE]([%+%-]?)([%d_]*)$")
|
local es, ed = match(rest :: string, "^[eE]([%+%-]?)([%d_]*)$")
|
||||||
if not es or not digitsOk(ed, "%d") then
|
if not es or not digitsOk(ed :: string, "%d") then
|
||||||
return fail("bad float", i), 0
|
return fail("bad float", i), 0
|
||||||
end
|
end
|
||||||
text ..= "e" .. es .. gsub(ed, "_", "")
|
text ..= "e" .. es .. gsub(ed :: string, "_", "")
|
||||||
end
|
end
|
||||||
local v = tonumber(text)
|
local v = tonumber(text)
|
||||||
if v == nil then
|
if v == nil then
|
||||||
|
|||||||
@@ -107,13 +107,13 @@ function Parse.text(s: string): (Desc?, string?)
|
|||||||
local a: { [string]: string } = {}
|
local a: { [string]: string } = {}
|
||||||
-- key=value, key="quoted value"
|
-- key=value, key="quoted value"
|
||||||
local i = 1
|
local i = 1
|
||||||
while i <= #rest do
|
while i <= #(rest :: string) do
|
||||||
local k, q, e = string.match(rest, '^%s*([%w_]+)="([^"]*)"()', i)
|
local k, q, e = string.match(rest :: string, '^%s*([%w_]+)="([^"]*)"()', i)
|
||||||
if k then
|
if k then
|
||||||
a[k] = q
|
a[k] = q
|
||||||
i = e
|
i = e
|
||||||
else
|
else
|
||||||
local k2, v2, e2 = string.match(rest, "^%s*([%w_]+)=(%S*)()", i)
|
local k2, v2, e2 = string.match(rest :: string, "^%s*([%w_]+)=(%S*)()", i)
|
||||||
if not k2 then
|
if not k2 then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@@ -135,7 +135,7 @@ function Parse.text(s: string): (Desc?, string?)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- ------------------------------------------------------------------------------------------------ XML
|
-- ------------------------------------------------------------------------------------------------ XML
|
||||||
local ENTITIES = { quot = '"', amp = "&", lt = "<", gt = ">", apos = "'" }
|
local ENTITIES: { [string]: string } = { quot = '"', amp = "&", lt = "<", gt = ">", apos = "'" }
|
||||||
local function unescape(s: string): string
|
local function unescape(s: string): string
|
||||||
return (
|
return (
|
||||||
string.gsub(s, "&(#?x?%w+);", function(e: string): string?
|
string.gsub(s, "&(#?x?%w+);", function(e: string): string?
|
||||||
@@ -159,8 +159,8 @@ function Parse.xml(s: string): (Desc?, string?)
|
|||||||
seenFont = true
|
seenFont = true
|
||||||
end
|
end
|
||||||
local a: { [string]: string } = {}
|
local a: { [string]: string } = {}
|
||||||
for k, q, v in string.gmatch(attrs, "([%w_]+)%s*=%s*([\"'])(.-)%2") do
|
for k, q, v in string.gmatch(attrs :: string, "([%w_]+)%s*=%s*([\"'])(.-)%2") do
|
||||||
a[k] = unescape(v)
|
a[k] = unescape(v :: string)
|
||||||
local _ = q
|
local _ = q
|
||||||
end
|
end
|
||||||
local err = apply(d, tag, a)
|
local err = apply(d, tag, a)
|
||||||
|
|||||||
@@ -287,26 +287,28 @@ function Bmfont.bake(font: any, opts: BakeOptions?): (any, Err.Err?)
|
|||||||
if type(font) ~= "table" or type(font.rasterize) ~= "function" or type(font.glyphIndex) ~= "function" then
|
if type(font) ~= "table" or type(font.rasterize) ~= "function" or type(font.glyphIndex) ~= "function" then
|
||||||
return nil, Err.new(Err.ARG, "bake: expected an outline Font")
|
return nil, Err.new(Err.ARG, "bake: expected an outline Font")
|
||||||
end
|
end
|
||||||
local o = opts or {}
|
local o: BakeOptions = opts or {}
|
||||||
local px = if type(o.px) == "number" and o.px > 0 and o.px <= 1024 then o.px else 32
|
local px = if type(o.px) == "number" and o.px > 0 and o.px <= 1024 then o.px else 32
|
||||||
local pad = if type(o.padding) == "number" and o.padding >= 0 then math.floor(o.padding) else 1
|
local pad = if type(o.padding) == "number" and o.padding >= 0 then math.floor(o.padding) else 1
|
||||||
local scale = px / font.unitsPerEm
|
local scale = px / font.unitsPerEm
|
||||||
local glyphs = {}
|
local glyphs: { { cp: number, g: number, img: Types.Image } } = {}
|
||||||
local area = 0
|
local area = 0
|
||||||
local seen = {}
|
local seen = {}
|
||||||
for _, cp in codepoints(o.chars) do
|
for _, cp in codepoints(o.chars) do
|
||||||
local g = font:glyphIndex(cp)
|
local g = (font :: any):glyphIndex(cp)
|
||||||
if (g ~= 0 or cp == 0) and not seen[cp] then
|
if (g ~= 0 or cp == 0) and not seen[cp] then
|
||||||
seen[cp] = true
|
seen[cp] = true
|
||||||
local img = font:rasterize(g, px)
|
local img: Types.Image? = (font :: any):rasterize(g, px)
|
||||||
if img then
|
if img then
|
||||||
table.insert(glyphs, { cp = cp, g = g, img = img })
|
table.insert(glyphs, { cp = cp, g = g, img = img })
|
||||||
area += (img.width + pad) * (img.height + pad)
|
area += (img.width + pad) * (img.height + pad)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local size = o.pageSize
|
local size: number
|
||||||
if type(size) ~= "number" then
|
if type(o.pageSize) == "number" then
|
||||||
|
size = o.pageSize
|
||||||
|
else
|
||||||
size = 64
|
size = 64
|
||||||
while size * size < area * 1.3 and size < 4096 do
|
while size * size < area * 1.3 and size < 4096 do
|
||||||
size *= 2
|
size *= 2
|
||||||
|
|||||||
@@ -150,9 +150,11 @@ local function glyf(b: buffer, p: number, n: number, maxBytes: number): (any?, s
|
|||||||
fl = band(fl, 0x7F)
|
fl = band(fl, 0x7F)
|
||||||
local dx, dy
|
local dx, dy
|
||||||
if fl < 10 then
|
if fl < 10 then
|
||||||
dx, dy = 0, withSign(fl, band(fl, 14) * 128 + su8(glyphS))
|
dx = 0
|
||||||
|
dy = withSign(fl, band(fl, 14) * 128 + su8(glyphS))
|
||||||
elseif fl < 20 then
|
elseif fl < 20 then
|
||||||
dx, dy = withSign(fl, band(fl - 10, 14) * 128 + su8(glyphS)), 0
|
dx = withSign(fl, band(fl - 10, 14) * 128 + su8(glyphS))
|
||||||
|
dy = 0
|
||||||
elseif fl < 84 then
|
elseif fl < 84 then
|
||||||
local b0 = fl - 20
|
local b0 = fl - 20
|
||||||
local b1 = su8(glyphS)
|
local b1 = su8(glyphS)
|
||||||
@@ -181,12 +183,17 @@ local function glyf(b: buffer, p: number, n: number, maxBytes: number): (any?, s
|
|||||||
end
|
end
|
||||||
local x0, y0, x1, y1
|
local x0, y0, x1, y1
|
||||||
if hasBox(g) then
|
if hasBox(g) then
|
||||||
x0, y0, x1, y1 = si16(bboxS), si16(bboxS), si16(bboxS), si16(bboxS)
|
x0 = si16(bboxS)
|
||||||
|
y0 = si16(bboxS)
|
||||||
|
x1 = si16(bboxS)
|
||||||
|
y1 = si16(bboxS)
|
||||||
else
|
else
|
||||||
x0, y0, x1, y1 = 32767, 32767, -32768, -32768
|
x0, y0, x1, y1 = 32767, 32767, -32768, -32768
|
||||||
for k = 1, total do
|
for k = 1, total do
|
||||||
x0, y0 = math.min(x0, xs[k]), math.min(y0, ys[k])
|
x0 = math.min(x0, xs[k])
|
||||||
x1, y1 = math.max(x1, xs[k]), math.max(y1, ys[k])
|
y0 = math.min(y0, ys[k])
|
||||||
|
x1 = math.max(x1, xs[k])
|
||||||
|
y1 = math.max(y1, ys[k])
|
||||||
end
|
end
|
||||||
if total == 0 then
|
if total == 0 then
|
||||||
x0, y0, x1, y1 = 0, 0, 0, 0
|
x0, y0, x1, y1 = 0, 0, 0, 0
|
||||||
|
|||||||
@@ -209,7 +209,9 @@ function Bmp.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Image?, Err.E
|
|||||||
if comp == 3 or comp == 6 then
|
if comp == 3 or comp == 6 then
|
||||||
hasMasks = true
|
hasMasks = true
|
||||||
if hs >= 52 then
|
if hs >= 52 then
|
||||||
rm, gm, bm = readu32(buf, 54), readu32(buf, 58), readu32(buf, 62)
|
rm = readu32(buf, 54)
|
||||||
|
gm = readu32(buf, 58)
|
||||||
|
bm = readu32(buf, 62)
|
||||||
if hs >= 56 then
|
if hs >= 56 then
|
||||||
am = readu32(buf, 66)
|
am = readu32(buf, 66)
|
||||||
end
|
end
|
||||||
@@ -218,7 +220,9 @@ function Bmp.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Image?, Err.E
|
|||||||
if palStart + count * 4 > n then
|
if palStart + count * 4 > n then
|
||||||
return nil, Err.new(Err.TRUNCATED, "truncated bit masks")
|
return nil, Err.new(Err.TRUNCATED, "truncated bit masks")
|
||||||
end
|
end
|
||||||
rm, gm, bm = readu32(buf, palStart), readu32(buf, palStart + 4), readu32(buf, palStart + 8)
|
rm = readu32(buf, palStart)
|
||||||
|
gm = readu32(buf, palStart + 4)
|
||||||
|
bm = readu32(buf, palStart + 8)
|
||||||
if comp == 6 then
|
if comp == 6 then
|
||||||
am = readu32(buf, palStart + 12)
|
am = readu32(buf, palStart + 12)
|
||||||
end
|
end
|
||||||
@@ -385,7 +389,8 @@ function Bmp.encode(img: Types.Image, opts: EncodeOptions?): (buffer?, Err.Err?)
|
|||||||
local dpi = img.meta and img.meta.dpi
|
local dpi = img.meta and img.meta.dpi
|
||||||
local xp: number, yp: number = 3780, 3780 -- 96 dpi, as Pillow
|
local xp: number, yp: number = 3780, 3780 -- 96 dpi, as Pillow
|
||||||
if type(dpi) == "table" and type(dpi.x) == "number" and type(dpi.y) == "number" and dpi.x > 0 and dpi.y > 0 then
|
if type(dpi) == "table" and type(dpi.x) == "number" and type(dpi.y) == "number" and dpi.x > 0 and dpi.y > 0 then
|
||||||
xp, yp = math.floor((dpi.x :: number) * 39.3701 + 0.5), math.floor((dpi.y :: number) * 39.3701 + 0.5)
|
xp = math.floor((dpi.x :: number) * 39.3701 + 0.5)
|
||||||
|
yp = math.floor((dpi.y :: number) * 39.3701 + 0.5)
|
||||||
end
|
end
|
||||||
o:i32le(xp)
|
o:i32le(xp)
|
||||||
o:i32le(yp)
|
o:i32le(yp)
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ export type EncodeOptions = {
|
|||||||
-- ------------------------------------------------------------------------------------------------ constants
|
-- ------------------------------------------------------------------------------------------------ constants
|
||||||
local readu8 = buffer.readu8
|
local readu8 = buffer.readu8
|
||||||
local DISPOSE = { [0] = "none", [1] = "none", [2] = "background", [3] = "previous" }
|
local DISPOSE = { [0] = "none", [1] = "none", [2] = "background", [3] = "previous" }
|
||||||
local DISPOSE_CODE = { none = 1, background = 2, previous = 3 }
|
local DISPOSE_CODE: { [string]: number } = { none = 1, background = 2, previous = 3 }
|
||||||
|
|
||||||
-- ------------------------------------------------------------------------------------------------ sniff
|
-- ------------------------------------------------------------------------------------------------ sniff
|
||||||
function Gif.sniff(r: Bytes.Reader): number
|
function Gif.sniff(r: Bytes.Reader): number
|
||||||
@@ -62,7 +62,7 @@ end
|
|||||||
-- a colour table at p (n entries) -> 256 u32 rgba entries (missing ones opaque black) and the { r, g, b, a } list
|
-- a colour table at p (n entries) -> 256 u32 rgba entries (missing ones opaque black) and the { r, g, b, a } list
|
||||||
local function colorTable(b: buffer, p: number, n: number): (buffer, { { number } })
|
local function colorTable(b: buffer, p: number, n: number): (buffer, { { number } })
|
||||||
local t = buffer.create(1024)
|
local t = buffer.create(1024)
|
||||||
local list = table.create(n)
|
local list: { { number } } = table.create(n) :: { { number } }
|
||||||
for i = 0, 255 do
|
for i = 0, 255 do
|
||||||
buffer.writeu32(t, i * 4, 0xFF000000)
|
buffer.writeu32(t, i * 4, 0xFF000000)
|
||||||
end
|
end
|
||||||
@@ -404,7 +404,7 @@ function Gif.encode(img: Types.Image, opts: EncodeOptions?): (buffer?, Err.Err?)
|
|||||||
end
|
end
|
||||||
-- palettes
|
-- palettes
|
||||||
local shared = (opts and opts.globalPalette) or not animated
|
local shared = (opts and opts.globalPalette) or not animated
|
||||||
local qopts = { method = method, dither = dither }
|
local qopts: Quantize.PaletteOptions = { method = method, dither = dither }
|
||||||
local globalPal: { { number } }? = nil
|
local globalPal: { { number } }? = nil
|
||||||
local globalTrans = false
|
local globalTrans = false
|
||||||
if shared then
|
if shared then
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ function Hdr.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Image?, Err.E
|
|||||||
return nil, Err.new(Err.TRUNCATED, "no resolution line", p)
|
return nil, Err.new(Err.TRUNCATED, "no resolution line", p)
|
||||||
end
|
end
|
||||||
local s1, a1, n1, s2, a2, n2 = string.match(res, "^%s*([%+%-])([XY])%s+(%d+)%s+([%+%-])([XY])%s+(%d+)%s*$")
|
local s1, a1, n1, s2, a2, n2 = string.match(res, "^%s*([%+%-])([XY])%s+(%d+)%s+([%+%-])([XY])%s+(%d+)%s*$")
|
||||||
if not s1 or a1 == a2 or #n1 > 9 or #n2 > 9 then
|
if not s1 or a1 == a2 or #(n1 :: string) > 9 or #(n2 :: string) > 9 then
|
||||||
return nil, Err.new(Err.CORRUPT, "bad resolution line", p)
|
return nil, Err.new(Err.CORRUPT, "bad resolution line", p)
|
||||||
end
|
end
|
||||||
local outer, inner = tonumber(n1) :: number, tonumber(n2) :: number
|
local outer, inner = tonumber(n1) :: number, tonumber(n2) :: number
|
||||||
@@ -170,7 +170,7 @@ function Hdr.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Image?, Err.E
|
|||||||
if truncated then
|
if truncated then
|
||||||
img.meta.truncated = true
|
img.meta.truncated = true
|
||||||
end
|
end
|
||||||
img.meta.source = { format = "hdr", bitDepth = 32, colorType = "rgbe", program = string.sub(first, 3), orientation = string.format("%s%s %s%s", s1, a1, s2, a2) }
|
img.meta.source = { format = "hdr", bitDepth = 32, colorType = "rgbe", program = string.sub(first, 3), orientation = string.format("%s%s %s%s", s1, a1 :: string, s2 :: string, a2 :: string) }
|
||||||
return img, nil
|
return img, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ function Ico.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Image?, Err.E
|
|||||||
if typ == 2 then
|
if typ == 2 then
|
||||||
im.meta.hotspot = { x = f1, y = f2 }
|
im.meta.hotspot = { x = f1, y = f2 }
|
||||||
end
|
end
|
||||||
table.insert(frames, { image = im, delay = 0, x = 0, y = 0, dispose = "none", blend = "source" })
|
table.insert(frames, { image = im, delay = 0, x = 0, y = 0, dispose = "none", blend = "source" } :: Types.Frame)
|
||||||
local score = im.width * im.height * 64 + depth
|
local score = im.width * im.height * 64 + depth
|
||||||
if score > bestScore then
|
if score > bestScore then
|
||||||
best, bestScore = im, score
|
best, bestScore = im, score
|
||||||
|
|||||||
@@ -26,19 +26,27 @@ function Codec.decode(b: buffer, p: number, limit: number, out: buffer, n: numbe
|
|||||||
if p + 3 > limit then
|
if p + 3 > limit then
|
||||||
return false, "truncated"
|
return false, "truncated"
|
||||||
end
|
end
|
||||||
r, g, bl = readu8(b, p), readu8(b, p + 1), readu8(b, p + 2)
|
r = readu8(b, p)
|
||||||
|
g = readu8(b, p + 1)
|
||||||
|
bl = readu8(b, p + 2)
|
||||||
p += 3
|
p += 3
|
||||||
elseif op == 0xFF then
|
elseif op == 0xFF then
|
||||||
if p + 4 > limit then
|
if p + 4 > limit then
|
||||||
return false, "truncated"
|
return false, "truncated"
|
||||||
end
|
end
|
||||||
r, g, bl, a = readu8(b, p), readu8(b, p + 1), readu8(b, p + 2), readu8(b, p + 3)
|
r = readu8(b, p)
|
||||||
|
g = readu8(b, p + 1)
|
||||||
|
bl = readu8(b, p + 2)
|
||||||
|
a = readu8(b, p + 3)
|
||||||
p += 4
|
p += 4
|
||||||
else
|
else
|
||||||
local tag = op // 64
|
local tag = op // 64
|
||||||
if tag == 0 then
|
if tag == 0 then
|
||||||
local q = op * 4
|
local q = op * 4
|
||||||
r, g, bl, a = readu8(index, q), readu8(index, q + 1), readu8(index, q + 2), readu8(index, q + 3)
|
r = readu8(index, q)
|
||||||
|
g = readu8(index, q + 1)
|
||||||
|
bl = readu8(index, q + 2)
|
||||||
|
a = readu8(index, q + 3)
|
||||||
elseif tag == 1 then
|
elseif tag == 1 then
|
||||||
r = (r + (op // 16) % 4 - 2) % 256
|
r = (r + (op // 16) % 4 - 2) % 256
|
||||||
g = (g + (op // 4) % 4 - 2) % 256
|
g = (g + (op // 4) % 4 - 2) % 256
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ function Qoi.encode(img: Types.Image, opts: EncodeOptions?): (buffer?, Err.Err?)
|
|||||||
buffer.writestring(out, 0, "qoif")
|
buffer.writestring(out, 0, "qoif")
|
||||||
buffer.writeu32(out, 4, bit32.byteswap(w))
|
buffer.writeu32(out, 4, bit32.byteswap(w))
|
||||||
buffer.writeu32(out, 8, bit32.byteswap(h))
|
buffer.writeu32(out, 8, bit32.byteswap(h))
|
||||||
buffer.writeu8(out, 12, channels)
|
buffer.writeu8(out, 12, channels :: number)
|
||||||
buffer.writeu8(out, 13, if linear then 1 else 0)
|
buffer.writeu8(out, 13, if linear then 1 else 0)
|
||||||
local o = Codec.encode(img.pixels, n, bpp, out, 14)
|
local o = Codec.encode(img.pixels, n, bpp, out, 14)
|
||||||
buffer.writestring(out, o, "\0\0\0\0\0\0\0\1")
|
buffer.writestring(out, o, "\0\0\0\0\0\0\0\1")
|
||||||
|
|||||||
@@ -384,7 +384,9 @@ function Pixels.convert(P: Params)
|
|||||||
r, g, bl = 0, 0, 0
|
r, g, bl = 0, 0, 0
|
||||||
end
|
end
|
||||||
elseif photo == 2 then
|
elseif photo == 2 then
|
||||||
r, g, bl = norm(0, x, y), norm(1, x, y), norm(2, x, y)
|
r = norm(0, x, y)
|
||||||
|
g = norm(1, x, y)
|
||||||
|
bl = norm(2, x, y)
|
||||||
elseif photo == 5 then
|
elseif photo == 5 then
|
||||||
local c, m, ye, k = norm(0, x, y), norm(1, x, y), norm(2, x, y), norm(3, x, y)
|
local c, m, ye, k = norm(0, x, y), norm(1, x, y), norm(2, x, y), norm(3, x, y)
|
||||||
r, g, bl = (1 - c) * (1 - k), (1 - m) * (1 - k), (1 - ye) * (1 - k)
|
r, g, bl = (1 - c) * (1 - k), (1 - m) * (1 - k), (1 - ye) * (1 - k)
|
||||||
@@ -399,7 +401,9 @@ function Pixels.convert(P: Params)
|
|||||||
a = norm(alpha, x, y)
|
a = norm(alpha, x, y)
|
||||||
if assoc then
|
if assoc then
|
||||||
if a > 0 then
|
if a > 0 then
|
||||||
r, g, bl = math.min(r / a, 1), math.min(g / a, 1), math.min(bl / a, 1)
|
r = math.min(r / a, 1)
|
||||||
|
g = math.min(g / a, 1)
|
||||||
|
bl = math.min(bl / a, 1)
|
||||||
else
|
else
|
||||||
r, g, bl = 0, 0, 0
|
r, g, bl = 0, 0, 0
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -322,7 +322,7 @@ local function decodePage(c: Ctx, t: { [number]: Entry }, opts: DecodeOptions?):
|
|||||||
if not offs or #offs < perPlane * nplanes then
|
if not offs or #offs < perPlane * nplanes then
|
||||||
return nil, Err.new(Err.CORRUPT, "missing or short strip / tile offsets")
|
return nil, Err.new(Err.CORRUPT, "missing or short strip / tile offsets")
|
||||||
end
|
end
|
||||||
local planes = table.create(nplanes)
|
local planes: { buffer } = table.create(nplanes) :: { buffer }
|
||||||
for i = 1, nplanes do
|
for i = 1, nplanes do
|
||||||
planes[i] = buffer.create(rb * h + 8)
|
planes[i] = buffer.create(rb * h + 8)
|
||||||
end
|
end
|
||||||
@@ -583,7 +583,7 @@ function Tiff.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Image?, Err.
|
|||||||
end
|
end
|
||||||
local img, perr = decodePage(c, t, opts)
|
local img, perr = decodePage(c, t, opts)
|
||||||
if img then
|
if img then
|
||||||
img.meta.source.pages = #list
|
(img.meta.source :: { [string]: any }).pages = #list
|
||||||
end
|
end
|
||||||
return img, perr
|
return img, perr
|
||||||
end
|
end
|
||||||
@@ -608,7 +608,7 @@ function Tiff.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Image?, Err.
|
|||||||
table.insert(frames, { image = img, delay = 0, x = 0, y = 0, dispose = "none", blend = "source" })
|
table.insert(frames, { image = img, delay = 0, x = 0, y = 0, dispose = "none", blend = "source" })
|
||||||
end
|
end
|
||||||
local img = first :: Types.Image
|
local img = first :: Types.Image
|
||||||
img.meta.source.pages = #frames
|
(img.meta.source :: { [string]: any }).pages = #frames
|
||||||
if #frames > 1 then
|
if #frames > 1 then
|
||||||
img.frames = frames :: any
|
img.frames = frames :: any
|
||||||
end
|
end
|
||||||
@@ -722,7 +722,7 @@ local function encodePage(img: Types.Image, o: EncodeOptions, comp: number): ({
|
|||||||
end
|
end
|
||||||
local text = img.meta and img.meta.text
|
local text = img.meta and img.meta.text
|
||||||
if type(text) == "table" then
|
if type(text) == "table" then
|
||||||
for key, tag in { description = 270, software = 305, datetime = 306, artist = 315, copyright = 33432 } do
|
for key, tag in { description = 270, software = 305, datetime = 306, artist = 315, copyright = 33432 } :: { [string]: number } do
|
||||||
if type(text[key]) == "string" then
|
if type(text[key]) == "string" then
|
||||||
table.insert(tags, { tag = tag, typ = 2, data = buffer.fromstring(text[key] .. "\0") })
|
table.insert(tags, { tag = tag, typ = 2, data = buffer.fromstring(text[key] .. "\0") })
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ function Channels.rleCounts(src: buffer, p: number, limit: number, rows: number,
|
|||||||
if rows < 0 or p + rows * size > limit then
|
if rows < 0 or p + rows * size > limit then
|
||||||
return nil, p
|
return nil, p
|
||||||
end
|
end
|
||||||
local counts = table.create(rows)
|
local counts: { number } = table.create(rows) :: { number }
|
||||||
for i = 1, rows do
|
for i = 1, rows do
|
||||||
if psb then
|
if psb then
|
||||||
counts[i] = byteswap(readu32(src, p))
|
counts[i] = byteswap(readu32(src, p))
|
||||||
@@ -247,11 +247,15 @@ function Channels.toRGBA(planes: { [any]: buffer }, w: number, h: number, depth:
|
|||||||
local mm = if c2 then sample8(c2, i, depth) else 255
|
local mm = if c2 then sample8(c2, i, depth) else 255
|
||||||
local yy = if c3 then sample8(c3, i, depth) else 255
|
local yy = if c3 then sample8(c3, i, depth) else 255
|
||||||
local kk = if c4 then sample8(c4, i, depth) else 255
|
local kk = if c4 then sample8(c4, i, depth) else 255
|
||||||
r, g, b = floor(cc * kk / 255 + 0.5), floor(mm * kk / 255 + 0.5), floor(yy * kk / 255 + 0.5)
|
r = floor(cc * kk / 255 + 0.5)
|
||||||
|
g = floor(mm * kk / 255 + 0.5)
|
||||||
|
b = floor(yy * kk / 255 + 0.5)
|
||||||
elseif mode == 2 then
|
elseif mode == 2 then
|
||||||
local k = if c1 then readu8(c1, i) else 0
|
local k = if c1 then readu8(c1, i) else 0
|
||||||
if palette and blen(palette) >= 768 then
|
if palette and blen(palette) >= 768 then
|
||||||
r, g, b = readu8(palette, k), readu8(palette, 256 + k), readu8(palette, 512 + k)
|
r = readu8(palette, k)
|
||||||
|
g = readu8(palette, 256 + k)
|
||||||
|
b = readu8(palette, 512 + k)
|
||||||
else
|
else
|
||||||
r, g, b = k, k, k
|
r, g, b = k, k, k
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ function Render.timeline(midi: Types.Midi): Timeline
|
|||||||
end
|
end
|
||||||
return a[3] < b[3]
|
return a[3] < b[3]
|
||||||
end)
|
end)
|
||||||
local tl: Timeline = { time = table.create(#items), status = table.create(#items), d1 = table.create(#items), d2 = table.create(#items), length = Render.length(midi) }
|
local tl: Timeline = { time = table.create(#items) :: { number }, status = table.create(#items) :: { number }, d1 = table.create(#items) :: { number }, d2 = table.create(#items) :: { number }, length = Render.length(midi) }
|
||||||
for i, it in items do
|
for i, it in items do
|
||||||
tl.time[i], tl.status[i], tl.d1[i], tl.d2[i] = it[1], it[4], it[5] % 128, it[6] % 128
|
tl.time[i], tl.status[i], tl.d1[i], tl.d2[i] = it[1], it[4], it[5] % 128, it[6] % 128
|
||||||
end
|
end
|
||||||
@@ -192,7 +192,7 @@ function Render.decoder(midi: Types.Midi, opts: RenderOptions?): (Types.Decoder?
|
|||||||
local tail = o.tail or 1
|
local tail = o.tail or 1
|
||||||
local frames = math.max(0, math.ceil((tl.length + tail) * rate))
|
local frames = math.max(0, math.ceil((tl.length + tail) * rate))
|
||||||
local nev = #tl.time
|
local nev = #tl.time
|
||||||
local evFrame = table.create(nev)
|
local evFrame: { number } = table.create(nev) :: { number }
|
||||||
for i = 1, nev do
|
for i = 1, nev do
|
||||||
evFrame[i] = math.floor(tl.time[i] * rate + 0.5)
|
evFrame[i] = math.floor(tl.time[i] * rate + 0.5)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export type WriteOptions = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
local function bytesOf(b: buffer, p: number, n: number): { number }
|
local function bytesOf(b: buffer, p: number, n: number): { number }
|
||||||
local t: { number } = table.create(n)
|
local t: { number } = table.create(n) :: { number }
|
||||||
for i = 0, n - 1 do
|
for i = 0, n - 1 do
|
||||||
t[i + 1] = readu8(b, p + i)
|
t[i + 1] = readu8(b, p + i)
|
||||||
end
|
end
|
||||||
@@ -309,7 +309,7 @@ function Smf.write(midi: Types.Midi, opts: WriteOptions?): (buffer?, Err.Err?)
|
|||||||
end
|
end
|
||||||
last = ev.tick
|
last = ev.tick
|
||||||
end
|
end
|
||||||
local list = events
|
local list: { any } = events
|
||||||
if not sorted then
|
if not sorted then
|
||||||
list = table.clone(events)
|
list = table.clone(events)
|
||||||
local order: { [any]: number } = {}
|
local order: { [any]: number } = {}
|
||||||
|
|||||||
@@ -204,7 +204,8 @@ function S3m.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?)
|
|||||||
vol = math.min(pr:u8(), 64) + 1
|
vol = math.min(pr:u8(), 64) + 1
|
||||||
end
|
end
|
||||||
if bit32.band(what, 0x80) ~= 0 then
|
if bit32.band(what, 0x80) ~= 0 then
|
||||||
cmd, info = pr:u8(), pr:u8()
|
cmd = pr:u8()
|
||||||
|
info = pr:u8()
|
||||||
if cmd > 26 then
|
if cmd > 26 then
|
||||||
cmd, info = 0, 0
|
cmd, info = 0, 0
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -149,7 +149,11 @@ function Xm.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?)
|
|||||||
param = pr:u8()
|
param = pr:u8()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
note, ins, vol, fx, param = b, pr:u8(), pr:u8(), pr:u8(), pr:u8()
|
note = b
|
||||||
|
ins = pr:u8()
|
||||||
|
vol = pr:u8()
|
||||||
|
fx = pr:u8()
|
||||||
|
param = pr:u8()
|
||||||
end
|
end
|
||||||
if pr.err then
|
if pr.err then
|
||||||
break -- a short pattern: the rest stays empty
|
break -- a short pattern: the rest stays empty
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ end
|
|||||||
-- ------------------------------------------------------------------------------------------------ decode
|
-- ------------------------------------------------------------------------------------------------ decode
|
||||||
local function parsePls(ls: { string }, base: string?, baseScheme: string?, warnings: { string }): Result
|
local function parsePls(ls: { string }, base: string?, baseScheme: string?, warnings: { string }): Result
|
||||||
local res: Result = { kind = "playlist", format = "pls", entries = {}, warnings = warnings, meta = {} }
|
local res: Result = { kind = "playlist", format = "pls", entries = {}, warnings = warnings, meta = {} }
|
||||||
local files, titles, lengths = {}, {}, {}
|
local files: { [number]: string }, titles: { [number]: string }, lengths: { [number]: string } = {}, {}, {}
|
||||||
local declared = nil
|
local declared = nil
|
||||||
for _, line in ls do
|
for _, line in ls do
|
||||||
local l = Text.trim(line)
|
local l = Text.trim(line)
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ function Xspf.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Playlist?, E
|
|||||||
for _, list in elements(root, "trackList") do
|
for _, list in elements(root, "trackList") do
|
||||||
for i, track in elements(list, "track") do
|
for i, track in elements(list, "track") do
|
||||||
local tbase, tscheme = withXmlBase(track, pbase, pscheme)
|
local tbase, tscheme = withXmlBase(track, pbase, pscheme)
|
||||||
local locs = {}
|
local locs: { string } = {}
|
||||||
for _, l in elements(track, "location") do
|
for _, l in elements(track, "location") do
|
||||||
local s = trim(Xml.text(l))
|
local s = trim(Xml.text(l))
|
||||||
if s ~= "" then
|
if s ~= "" then
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ function Ass.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Subtitles?, E
|
|||||||
stylesName = name
|
stylesName = name
|
||||||
section = "styles"
|
section = "styles"
|
||||||
elseif section ~= "script info" and section ~= "events" then
|
elseif section ~= "script info" and section ~= "events" then
|
||||||
table.insert(sections, { name = name, lines = {} })
|
table.insert(sections, { name = name, lines = {} :: { string } })
|
||||||
end
|
end
|
||||||
continue
|
continue
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ local LOCAL: { [string]: boolean } = {
|
|||||||
filter = true,
|
filter = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
local UNSUPPORTED = { text = true, image = true, pattern = true, mask = true, marker = true, filter = true, foreignObject = true, textPath = true, tspan = true }
|
local UNSUPPORTED: { [string]: boolean } = { text = true, image = true, pattern = true, mask = true, marker = true, filter = true, foreignObject = true, textPath = true, tspan = true }
|
||||||
local CONTAINERS = { g = true, a = true, switch = true }
|
local CONTAINERS = { g = true, a = true, switch = true }
|
||||||
local SHAPES = { path = true, rect = true, circle = true, ellipse = true, line = true, polyline = true, polygon = true }
|
local SHAPES = { path = true, rect = true, circle = true, ellipse = true, line = true, polyline = true, polygon = true }
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ local function specified(n: Node, ctx: Ctx): { [string]: string }
|
|||||||
for c in string.gmatch(attr(n, "class") or "", "%S+") do
|
for c in string.gmatch(attr(n, "class") or "", "%S+") do
|
||||||
classes[c] = true
|
classes[c] = true
|
||||||
end
|
end
|
||||||
local hits = {}
|
local hits: { Style.Rule } = {}
|
||||||
for _, r in ctx.rules do
|
for _, r in ctx.rules do
|
||||||
if Style.matches(r.selector, local_(n), attr(n, "id"), classes) then
|
if Style.matches(r.selector, local_(n), attr(n, "id"), classes) then
|
||||||
table.insert(hits, r)
|
table.insert(hits, r)
|
||||||
@@ -296,7 +296,7 @@ local function shape(n: Node, st: { [string]: string }, ctx: Ctx): { PathData.Cm
|
|||||||
if w <= 0 or h <= 0 then
|
if w <= 0 or h <= 0 then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
local rx, ry = len(attr(n, "rx"), vw, st), len(attr(n, "ry"), vh, st)
|
local rx: number?, ry: number? = len(attr(n, "rx"), vw, st), len(attr(n, "ry"), vh, st)
|
||||||
if rx and rx < 0 then
|
if rx and rx < 0 then
|
||||||
rx = nil
|
rx = nil
|
||||||
end
|
end
|
||||||
@@ -305,9 +305,9 @@ local function shape(n: Node, st: { [string]: string }, ctx: Ctx): { PathData.Cm
|
|||||||
end
|
end
|
||||||
rx = rx or ry or 0
|
rx = rx or ry or 0
|
||||||
ry = ry or rx
|
ry = ry or rx
|
||||||
rx, ry = math.min(rx :: number, w / 2), math.min(ry :: number, h / 2)
|
local rx: number, ry: number = math.min(rx :: number, w / 2), math.min(ry :: number, h / 2)
|
||||||
if rx <= 0 or ry <= 0 then
|
if rx <= 0 or ry <= 0 then
|
||||||
return { { op = "M", x, y }, { op = "L", x + w, y }, { op = "L", x + w, y + h }, { op = "L", x, y + h }, { op = "Z" } }
|
return { { op = "M", x, y }, { op = "L", x + w, y }, { op = "L", x + w, y + h }, { op = "L", x, y + h }, { op = "Z" } } :: { PathData.Cmd }
|
||||||
end
|
end
|
||||||
local out: { PathData.Cmd } = { { op = "M", x + rx, y }, { op = "L", x + w - rx, y } }
|
local out: { PathData.Cmd } = { { op = "M", x + rx, y }, { op = "L", x + w - rx, y } }
|
||||||
PathData.arc(x + w - rx, y, rx, ry, 0, false, true, x + w, y + ry, out)
|
PathData.arc(x + w - rx, y, rx, ry, 0, false, true, x + w, y + ry, out)
|
||||||
@@ -317,7 +317,7 @@ local function shape(n: Node, st: { [string]: string }, ctx: Ctx): { PathData.Cm
|
|||||||
PathData.arc(x + rx, y + h, rx, ry, 0, false, true, x, y + h - ry, out)
|
PathData.arc(x + rx, y + h, rx, ry, 0, false, true, x, y + h - ry, out)
|
||||||
table.insert(out, { op = "L", x, y + ry })
|
table.insert(out, { op = "L", x, y + ry })
|
||||||
PathData.arc(x, y + ry, rx, ry, 0, false, true, x + rx, y, out)
|
PathData.arc(x, y + ry, rx, ry, 0, false, true, x + rx, y, out)
|
||||||
table.insert(out, { op = "Z" })
|
table.insert(out, { op = "Z" } :: PathData.Cmd)
|
||||||
return out
|
return out
|
||||||
elseif kind == "circle" or kind == "ellipse" then
|
elseif kind == "circle" or kind == "ellipse" then
|
||||||
local cx, cy = len(attr(n, "cx"), vw, st, 0) :: number, len(attr(n, "cy"), vh, st, 0) :: number
|
local cx, cy = len(attr(n, "cx"), vw, st, 0) :: number, len(attr(n, "cy"), vh, st, 0) :: number
|
||||||
@@ -338,12 +338,12 @@ local function shape(n: Node, st: { [string]: string }, ctx: Ctx): { PathData.Cm
|
|||||||
PathData.arc(cx, cy + ry, rx, ry, 0, false, true, cx - rx, cy, out)
|
PathData.arc(cx, cy + ry, rx, ry, 0, false, true, cx - rx, cy, out)
|
||||||
PathData.arc(cx - rx, cy, rx, ry, 0, false, true, cx, cy - ry, out)
|
PathData.arc(cx - rx, cy, rx, ry, 0, false, true, cx, cy - ry, out)
|
||||||
PathData.arc(cx, cy - ry, rx, ry, 0, false, true, cx + rx, cy, out)
|
PathData.arc(cx, cy - ry, rx, ry, 0, false, true, cx + rx, cy, out)
|
||||||
table.insert(out, { op = "Z" })
|
table.insert(out, { op = "Z" } :: PathData.Cmd)
|
||||||
return out
|
return out
|
||||||
elseif kind == "line" then
|
elseif kind == "line" then
|
||||||
local x1, y1 = len(attr(n, "x1"), vw, st, 0) :: number, len(attr(n, "y1"), vh, st, 0) :: number
|
local x1, y1 = len(attr(n, "x1"), vw, st, 0) :: number, len(attr(n, "y1"), vh, st, 0) :: number
|
||||||
local x2, y2 = len(attr(n, "x2"), vw, st, 0) :: number, len(attr(n, "y2"), vh, st, 0) :: number
|
local x2, y2 = len(attr(n, "x2"), vw, st, 0) :: number, len(attr(n, "y2"), vh, st, 0) :: number
|
||||||
return { { op = "M", x1, y1 }, { op = "L", x2, y2 } }
|
return { { op = "M", x1, y1 }, { op = "L", x2, y2 } } :: { PathData.Cmd }
|
||||||
elseif kind == "polyline" or kind == "polygon" then
|
elseif kind == "polyline" or kind == "polygon" then
|
||||||
local v = Style.numbers(attr(n, "points"))
|
local v = Style.numbers(attr(n, "points"))
|
||||||
if #v < 4 then
|
if #v < 4 then
|
||||||
@@ -354,7 +354,7 @@ local function shape(n: Node, st: { [string]: string }, ctx: Ctx): { PathData.Cm
|
|||||||
table.insert(out, { op = "L", v[i], v[i + 1] })
|
table.insert(out, { op = "L", v[i], v[i + 1] })
|
||||||
end
|
end
|
||||||
if kind == "polygon" then
|
if kind == "polygon" then
|
||||||
table.insert(out, { op = "Z" })
|
table.insert(out, { op = "Z" } :: PathData.Cmd)
|
||||||
end
|
end
|
||||||
return out
|
return out
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ function PathData.parse(d: string): ({ Cmd }, boolean)
|
|||||||
local last = "" -- previous command letter (upper case)
|
local last = "" -- previous command letter (upper case)
|
||||||
local cmd: string? = nil
|
local cmd: string? = nil
|
||||||
local rel = false
|
local rel = false
|
||||||
local nums: { number } = table.create(7)
|
local nums: { number } = table.create(7) :: { number }
|
||||||
local function ws()
|
local function ws()
|
||||||
while i <= n do
|
while i <= n do
|
||||||
local c = byte(d, i)
|
local c = byte(d, i)
|
||||||
@@ -175,7 +175,7 @@ function PathData.parse(d: string): ({ Cmd }, boolean)
|
|||||||
rel = c ~= up
|
rel = c ~= up
|
||||||
i += 1
|
i += 1
|
||||||
if up == "Z" then
|
if up == "Z" then
|
||||||
table.insert(out, { op = "Z" })
|
table.insert(out, { op = "Z" } :: Cmd)
|
||||||
cx, cy = sx, sy
|
cx, cy = sx, sy
|
||||||
last = "Z"
|
last = "Z"
|
||||||
cmd = nil
|
cmd = nil
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ local function scan(s: string, i: number): (number?, number)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- length(s, ref?, fontSize?) -> number in user units | nil. ref: what 100% is (default 100)
|
-- length(s, ref?, fontSize?) -> number in user units | nil. ref: what 100% is (default 100)
|
||||||
local UNITS = { px = 1, pt = 4 / 3, pc = 16, mm = 96 / 25.4, cm = 96 / 2.54, ["in"] = 96, q = 96 / 101.6 }
|
local UNITS: { [string]: number } = { px = 1, pt = 4 / 3, pc = 16, mm = 96 / 25.4, cm = 96 / 2.54, ["in"] = 96, q = 96 / 101.6 }
|
||||||
function Style.length(s: string?, ref: number?, fontSize: number?): number?
|
function Style.length(s: string?, ref: number?, fontSize: number?): number?
|
||||||
if s == nil then
|
if s == nil then
|
||||||
return nil
|
return nil
|
||||||
@@ -355,11 +355,11 @@ function Style.css(text: string, rules: { Rule }?): { Rule }
|
|||||||
if not s then
|
if not s then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
text = string.sub(text, 1, s - 1) .. string.sub(text, e + 1)
|
text = string.sub(text, 1, s - 1) .. string.sub(text, (e :: number) + 1)
|
||||||
end
|
end
|
||||||
text = string.gsub(text, "@[%w-]+[^;{]*;", "")
|
text = string.gsub(text, "@[%w-]+[^;{]*;", "")
|
||||||
for sels, body in string.gmatch(text, "([^{}]+)(%b{})") do
|
for sels, body in string.gmatch(text, "([^{}]+)(%b{})") do
|
||||||
local decls = Style.declarations(string.sub(body, 2, -2))
|
local decls = Style.declarations(string.sub(body :: string, 2, -2))
|
||||||
for one in string.gmatch(sels, "[^,]+") do
|
for one in string.gmatch(sels, "[^,]+") do
|
||||||
local sel = selector(one)
|
local sel = selector(one)
|
||||||
if sel then
|
if sel then
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ function Write.vector(v: Types.Vector): (string?, string?)
|
|||||||
for k, d in p.strokeDashArray do
|
for k, d in p.strokeDashArray do
|
||||||
parts[k] = num(tonumber(d) or 0)
|
parts[k] = num(tonumber(d) or 0)
|
||||||
end
|
end
|
||||||
table.insert(attrs, { "stroke-dasharray", table.concat(parts, " ") })
|
table.insert(attrs, { "stroke-dasharray", table.concat(parts :: { string }, " ") })
|
||||||
local off = tonumber(p.strokeDashOffset)
|
local off = tonumber(p.strokeDashOffset)
|
||||||
table.insert(attrs, { "stroke-dashoffset", if off and off ~= 0 then off else nil })
|
table.insert(attrs, { "stroke-dashoffset", if off and off ~= 0 then off else nil })
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -42,11 +42,11 @@ function Data.base64(text: string, compression: string?): ({ number }?, string?,
|
|||||||
return nil, "compression " .. compression .. " is not supported", true
|
return nil, "compression " .. compression .. " is not supported", true
|
||||||
end
|
end
|
||||||
local n = buffer.len(bytes) // 4
|
local n = buffer.len(bytes) // 4
|
||||||
local out = table.create(n)
|
local out: { number } = table.create(n) :: { number }
|
||||||
for i = 0, n - 1 do
|
for i = 0, n - 1 do
|
||||||
out[i + 1] = buffer.readu32(bytes, i * 4)
|
out[i + 1] = buffer.readu32(bytes, i * 4)
|
||||||
end
|
end
|
||||||
return out, nil
|
return out, nil, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- toBase64(gids, compression?, level?) -> text | nil, message
|
-- toBase64(gids, compression?, level?) -> text | nil, message
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ function Tiled.encode(map: Types.TileMap, opts: EncodeOptions?): (buffer?, Err.E
|
|||||||
if o.compression and o.compression ~= "zlib" and o.compression ~= "gzip" then
|
if o.compression and o.compression ~= "zlib" and o.compression ~= "gzip" then
|
||||||
return nil, Err.new(Err.ARG, "compression must be zlib or gzip")
|
return nil, Err.new(Err.ARG, "compression must be zlib or gzip")
|
||||||
end
|
end
|
||||||
local wo = { encoding = o.encoding, compression = o.compression, level = o.level }
|
local wo: Tmx.WriteOptions = { encoding = o.encoding :: string?, compression = o.compression, level = o.level }
|
||||||
if fmt == "tmx" or fmt == "tsx" or fmt == "xml" then
|
if fmt == "tmx" or fmt == "tsx" or fmt == "xml" then
|
||||||
local doc: any, err: string?
|
local doc: any, err: string?
|
||||||
if tilesetOnly then
|
if tilesetOnly then
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ function AviFormat.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
|
|||||||
for _, item in Source.interleave(streams) do
|
for _, item in Source.interleave(streams) do
|
||||||
table.insert(chunks, { item[1], item[2].data, true })
|
table.insert(chunks, { item[1], item[2].data, true })
|
||||||
end
|
end
|
||||||
local ok, buf = pcall(Avi.write, { streams = wstreams, microSecPerFrame = usPerFrame, width = width, height = height }, chunks)
|
local ok, buf = pcall(Avi.write, { streams = wstreams, microSecPerFrame = usPerFrame, width = width, height = height } :: Avi.WOptions, chunks)
|
||||||
if not ok then
|
if not ok then
|
||||||
return nil, Err.new(Err.ARG, "internal error: " .. tostring(buf))
|
return nil, Err.new(Err.ARG, "internal error: " .. tostring(buf))
|
||||||
end
|
end
|
||||||
@@ -293,7 +293,7 @@ function AviFormat.open(r: Bytes.Reader, opts: OpenOptions?): (Types.VideoDecode
|
|||||||
if not dmx then
|
if not dmx then
|
||||||
return nil, err
|
return nil, err
|
||||||
end
|
end
|
||||||
return Video.open(dmx, opts)
|
return Video.open(dmx, opts :: Video.OpenOptions?)
|
||||||
end
|
end
|
||||||
|
|
||||||
return AviFormat
|
return AviFormat
|
||||||
@@ -127,7 +127,7 @@ function Mkv.open(r: Bytes.Reader, opts: OpenOptions?): (Types.VideoDecoder?, Er
|
|||||||
if not dmx then
|
if not dmx then
|
||||||
return nil, err
|
return nil, err
|
||||||
end
|
end
|
||||||
return Video.open(dmx, opts)
|
return Video.open(dmx, opts :: Video.OpenOptions?)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ------------------------------------------------------------------------------------------------ extras
|
-- ------------------------------------------------------------------------------------------------ extras
|
||||||
@@ -151,7 +151,7 @@ function Mkv.subtitles(dmx: any, trackId: number?): Types.Subtitles?
|
|||||||
if p then
|
if p then
|
||||||
local start = p.pts / track.timescale
|
local start = p.pts / track.timescale
|
||||||
local stop = start + (p.duration or 0) / track.timescale
|
local stop = start + (p.duration or 0) / track.timescale
|
||||||
table.insert(subs.cues, { start = start, stop = stop, text = buffer.tostring(p.data) })
|
table.insert(subs.cues, { start = start, stop = stop, text = buffer.tostring(p.data) } :: Types.Cue)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return subs
|
return subs
|
||||||
|
|||||||
@@ -318,7 +318,7 @@ function Mp4.open(r: Bytes.Reader, opts: OpenOptions?): (Types.VideoDecoder?, Er
|
|||||||
if not dmx then
|
if not dmx then
|
||||||
return nil, err
|
return nil, err
|
||||||
end
|
end
|
||||||
return Video.open(dmx, opts)
|
return Video.open(dmx, opts :: Video.OpenOptions?)
|
||||||
end
|
end
|
||||||
|
|
||||||
return Mp4
|
return Mp4
|
||||||
@@ -145,7 +145,7 @@ function Ps.demux(r: Bytes.Reader, _opts: OpenOptions?): (any, Err.Err?)
|
|||||||
codecTag = string.format("0x%02x", id % 256),
|
codecTag = string.format("0x%02x", id % 256),
|
||||||
timescale = 90000,
|
timescale = 90000,
|
||||||
streamId = id,
|
streamId = id,
|
||||||
})
|
} :: Types.Track)
|
||||||
end
|
end
|
||||||
local dmx = Demux.new("mpegps", tracks, r.buf, { mpeg2 = file.mpeg2, errors = file.errors })
|
local dmx = Demux.new("mpegps", tracks, r.buf, { mpeg2 = file.mpeg2, errors = file.errors })
|
||||||
for i, id in file.order do
|
for i, id in file.order do
|
||||||
@@ -186,7 +186,7 @@ function Ps.open(r: Bytes.Reader, opts: OpenOptions?): (Types.VideoDecoder?, Err
|
|||||||
if not dmx then
|
if not dmx then
|
||||||
return nil, err
|
return nil, err
|
||||||
end
|
end
|
||||||
return Video.open(dmx, opts)
|
return Video.open(dmx, opts :: Video.OpenOptions?)
|
||||||
end
|
end
|
||||||
|
|
||||||
return Ps
|
return Ps
|
||||||
@@ -154,7 +154,7 @@ function Ts.demux(r: Bytes.Reader, _opts: OpenOptions?): (any, Err.Err?)
|
|||||||
streamType = st,
|
streamType = st,
|
||||||
}
|
}
|
||||||
byPid[pid] = t
|
byPid[pid] = t
|
||||||
table.insert(tracks, t)
|
table.insert(tracks, t :: Types.Track)
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
for _, s in d.streams do
|
for _, s in d.streams do
|
||||||
@@ -239,7 +239,7 @@ function Ts.open(r: Bytes.Reader, opts: OpenOptions?): (Types.VideoDecoder?, Err
|
|||||||
if not dmx then
|
if not dmx then
|
||||||
return nil, err
|
return nil, err
|
||||||
end
|
end
|
||||||
return Video.open(dmx, opts)
|
return Video.open(dmx, opts :: Video.OpenOptions?)
|
||||||
end
|
end
|
||||||
|
|
||||||
return Ts
|
return Ts
|
||||||
@@ -105,7 +105,7 @@ function Y4m.demux(r: Bytes.Reader, opts: OpenOptions?): (any, Err.Err?)
|
|||||||
h = tonumber(v) or 0
|
h = tonumber(v) or 0
|
||||||
elseif k == "F" then
|
elseif k == "F" then
|
||||||
local a, b = string.match(v, "^(%d+):(%d+)$")
|
local a, b = string.match(v, "^(%d+):(%d+)$")
|
||||||
if a and b and tonumber(a) > 0 and tonumber(b) > 0 then
|
if a and b and (tonumber(a) :: number) > 0 and (tonumber(b) :: number) > 0 then
|
||||||
fn, fd = tonumber(a) :: number, tonumber(b) :: number
|
fn, fd = tonumber(a) :: number, tonumber(b) :: number
|
||||||
end
|
end
|
||||||
elseif k == "C" then
|
elseif k == "C" then
|
||||||
@@ -203,7 +203,7 @@ function Y4m.open(r: Bytes.Reader, opts: OpenOptions?): (Types.VideoDecoder?, Er
|
|||||||
if not dmx then
|
if not dmx then
|
||||||
return nil, err
|
return nil, err
|
||||||
end
|
end
|
||||||
return Video.open(dmx, opts)
|
return Video.open(dmx, opts :: Video.OpenOptions?)
|
||||||
end
|
end
|
||||||
|
|
||||||
return Y4m
|
return Y4m
|
||||||
Reference in new issue
Block a user