ws-cleanup-types: containers, ops: type the tables and locals the solver cannot infer
This commit is contained in:
1 parent
f209801579
commit
cfe325dcf8
12 files changed
+37
-32
No files matched your search
@@ -28,7 +28,7 @@ local BPP: { [string]: number } = {
|
|||||||
graya8 = 2,
|
graya8 = 2,
|
||||||
alpha8 = 1,
|
alpha8 = 1,
|
||||||
}
|
}
|
||||||
Types.BPP = table.freeze(BPP)
|
Types.BPP = table.freeze(BPP) :: { [string]: number }
|
||||||
|
|
||||||
export type ImageMeta = {
|
export type ImageMeta = {
|
||||||
colorSpace: string?, -- "srgb" (default), "linear", "display-p3", ...
|
colorSpace: string?, -- "srgb" (default), "linear", "display-p3", ...
|
||||||
@@ -429,7 +429,7 @@ local COMPONENT_SIZE: { [string]: number } = {
|
|||||||
snorm8 = 1,
|
snorm8 = 1,
|
||||||
snorm16 = 2,
|
snorm16 = 2,
|
||||||
}
|
}
|
||||||
Types.COMPONENT_SIZE = table.freeze(COMPONENT_SIZE)
|
Types.COMPONENT_SIZE = table.freeze(COMPONENT_SIZE) :: { [string]: number }
|
||||||
-- accessor(data, type, components, count) -> Accessor (data = nil allocates a zero-filled buffer)
|
-- accessor(data, type, components, count) -> Accessor (data = nil allocates a zero-filled buffer)
|
||||||
function Scene.accessor(data: buffer?, type: any, components: number, count: number): Accessor
|
function Scene.accessor(data: buffer?, type: any, components: number, count: number): Accessor
|
||||||
local d = data or buffer.create(count * components * (COMPONENT_SIZE[type] or 4))
|
local d = data or buffer.create(count * components * (COMPONENT_SIZE[type] or 4))
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ local function public(e: Entry): Types.ArchiveEntry
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Methods.list(self: any): { Types.ArchiveEntry }
|
function Methods.list(self: any): { Types.ArchiveEntry }
|
||||||
local out = table.create(#self._entries)
|
local out = table.create(#self._entries) :: { Types.ArchiveEntry }
|
||||||
for i, e in self._entries do
|
for i, e in self._entries do
|
||||||
out[i] = public(e)
|
out[i] = public(e)
|
||||||
end
|
end
|
||||||
@@ -91,7 +91,7 @@ end
|
|||||||
|
|
||||||
-- write(opts?) -> buffer | nil, Err: the archive's own format (opts.format is handled by the api)
|
-- write(opts?) -> buffer | nil, Err: the archive's own format (opts.format is handled by the api)
|
||||||
function Methods.write(self: any, opts: any?): (buffer?, Err.Err?)
|
function Methods.write(self: any, opts: any?): (buffer?, Err.Err?)
|
||||||
local enc = self._encode
|
local enc: Encoder? = self._encode
|
||||||
if not enc then
|
if not enc then
|
||||||
return nil, Err.new(Err.UNSUPPORTED, self.format .. " archives are read-only")
|
return nil, Err.new(Err.UNSUPPORTED, self.format .. " archives are read-only")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,8 +18,13 @@ local Mux = require("@formats/containers/Ogg/Mux")
|
|||||||
|
|
||||||
local AudioWrap = {}
|
local AudioWrap = {}
|
||||||
|
|
||||||
local function allPackets(dmx: any, track: Types.Track): { Types.Packet }
|
type PacketSource = {
|
||||||
local out = {}
|
count: ((self: any, track: number) -> number)?,
|
||||||
|
get: ((self: any, track: number, k: number) -> Types.Packet?)?,
|
||||||
|
}
|
||||||
|
|
||||||
|
local function allPackets(dmx: PacketSource, track: Types.Track): { Types.Packet }
|
||||||
|
local out: { Types.Packet } = {}
|
||||||
local n = if dmx.count then dmx:count(track.id) else 0
|
local n = if dmx.count then dmx:count(track.id) else 0
|
||||||
if n > 0 and dmx.get then
|
if n > 0 and dmx.get then
|
||||||
for k = 1, n do
|
for k = 1, n do
|
||||||
@@ -437,11 +442,11 @@ function AudioWrap.wrap(dmx: any, track: Types.Track): (buffer?, string?, Err.Er
|
|||||||
return granule
|
return granule
|
||||||
end
|
end
|
||||||
local mb = 0
|
local mb = 0
|
||||||
while 2 ^ mb < #modes do
|
while 2 ^ mb < #(modes :: { boolean }) do
|
||||||
mb += 1
|
mb += 1
|
||||||
end
|
end
|
||||||
local m = if mb > 0 and buffer.len(d) * 8 > mb then bits(d, 1, mb) else 0
|
local m = if mb > 0 and buffer.len(d) * 8 > mb then bits(d, 1, mb) else 0
|
||||||
local cur = sizes[if modes[m + 1] then 2 else 1]
|
local cur = sizes[if (modes :: { boolean })[m + 1] then 2 else 1]
|
||||||
if prev then
|
if prev then
|
||||||
granule += (prev + cur) // 4
|
granule += (prev + cur) // 4
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -491,7 +491,7 @@ function Avi.write(opts: WOptions, chunks: { { any } }): buffer
|
|||||||
w:u32le(0)
|
w:u32le(0)
|
||||||
local moviBase = w:tell()
|
local moviBase = w:tell()
|
||||||
w:string("movi")
|
w:string("movi")
|
||||||
local index = table.create(#chunks)
|
local index = table.create(#chunks) :: { { any } }
|
||||||
for _, c in chunks do
|
for _, c in chunks do
|
||||||
local si, data, key = c[1], c[2], c[3]
|
local si, data, key = c[1], c[2], c[3]
|
||||||
local s = opts.streams[si]
|
local s = opts.streams[si]
|
||||||
|
|||||||
@@ -324,9 +324,9 @@ local function track(b: buffer, trak: Box.Box, movieTimescale: number, trex: { [
|
|||||||
r:skip(3)
|
r:skip(3)
|
||||||
local n = r:u32be()
|
local n = r:u32be()
|
||||||
if n <= (elst.stop - elst.data) // 12 then
|
if n <= (elst.stop - elst.data) // 12 then
|
||||||
local edits = {}
|
local edits: { Edit } = {}
|
||||||
for _ = 1, n do
|
for _ = 1, n do
|
||||||
local dur, mt
|
local dur: number, mt: number
|
||||||
if v == 1 then
|
if v == 1 then
|
||||||
dur, mt = r:u64be(), r:i64be()
|
dur, mt = r:u64be(), r:i64be()
|
||||||
else
|
else
|
||||||
@@ -522,7 +522,7 @@ local function track(b: buffer, trak: Box.Box, movieTimescale: number, trex: { [
|
|||||||
if n * 12 > r:remaining() then
|
if n * 12 > r:remaining() then
|
||||||
return nil, Err.new(Err.TRUNCATED, "stsc table runs past its box", stsc.start)
|
return nil, Err.new(Err.TRUNCATED, "stsc table runs past its box", stsc.start)
|
||||||
end
|
end
|
||||||
local first, per, desc = {}, {}, {}
|
local first: { number }, per: { number }, desc: { number } = {}, {}, {}
|
||||||
for k = 1, n do
|
for k = 1, n do
|
||||||
first[k], per[k], desc[k] = r:u32be(), r:u32be(), r:u32be()
|
first[k], per[k], desc[k] = r:u32be(), r:u32be(), r:u32be()
|
||||||
end
|
end
|
||||||
@@ -739,7 +739,7 @@ export type Movie = {
|
|||||||
|
|
||||||
-- parse(r, opts) -> Movie | nil, Err: the box tree, ftyp, mvhd and every track (fragments included)
|
-- parse(r, opts) -> Movie | nil, Err: the box tree, ftyp, mvhd and every track (fragments included)
|
||||||
function Demux.parse(r: Bytes.Reader, opts: Options?): (Movie?, Err.Err?)
|
function Demux.parse(r: Bytes.Reader, opts: Options?): (Movie?, Err.Err?)
|
||||||
local o = opts or {}
|
local o: Options = opts or {}
|
||||||
local b = r.buf
|
local b = r.buf
|
||||||
local top, terr = Box.list(b, r.base, r.limit)
|
local top, terr = Box.list(b, r.base, r.limit)
|
||||||
if #top == 0 then
|
if #top == 0 then
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ function Meta.items(b: buffer, meta: Box.Box): (Items?, Err.Err?)
|
|||||||
it = {
|
it = {
|
||||||
id = id, type = "", name = "", hidden = false, construction = 0, baseOffset = 0, extents = {},
|
id = id, type = "", name = "", hidden = false, construction = 0, baseOffset = 0, extents = {},
|
||||||
properties = {}, essential = {}, refs = {},
|
properties = {}, essential = {}, refs = {},
|
||||||
}
|
} :: Item
|
||||||
out.items[id] = it
|
out.items[id] = it
|
||||||
table.insert(out.order, id)
|
table.insert(out.order, id)
|
||||||
end
|
end
|
||||||
@@ -496,7 +496,7 @@ function Meta.writeIlst(w: Bytes.Writer, tags: { [string]: string }, pictures: {
|
|||||||
end
|
end
|
||||||
if pictures and #pictures > 0 then
|
if pictures and #pictures > 0 then
|
||||||
box(w, "covr", function()
|
box(w, "covr", function()
|
||||||
for _, p in pictures do
|
for _, p in pictures :: { Picture } do
|
||||||
dataBox(w, if p.mime == "image/png" then 14 elseif p.mime == "image/bmp" then 27 else 13, p.data)
|
dataBox(w, if p.mime == "image/png" then 14 elseif p.mime == "image/bmp" then 27 else 13, p.data)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ function MpegPs.read(b: buffer, base: number, limit: number): (File?, Err.Err?)
|
|||||||
if ok and q <= stop then
|
if ok and q <= stop then
|
||||||
local s = file.streams[id]
|
local s = file.streams[id]
|
||||||
if not s then
|
if not s then
|
||||||
s = { id = id, kind = kind, codec = codec, streamType = st, pes = {} }
|
s = { id = id, kind = kind, codec = codec, streamType = st, pes = {} } :: Stream
|
||||||
file.streams[id] = s
|
file.streams[id] = s
|
||||||
table.insert(file.order, id)
|
table.insert(file.order, id)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -350,7 +350,7 @@ function Tar.write(entries: { WriteEntry }, opts: WriteOptions?): (buffer?, Err.
|
|||||||
end
|
end
|
||||||
local data = e.data or buffer.create(0)
|
local data = e.data or buffer.create(0)
|
||||||
local typ = e.type or (if e.dir then "5" else "0")
|
local typ = e.type or (if e.dir then "5" else "0")
|
||||||
local name = e.name
|
local name: string = e.name
|
||||||
if typ == "5" and string.sub(name, -1) ~= "/" then
|
if typ == "5" and string.sub(name, -1) ~= "/" then
|
||||||
name ..= "/"
|
name ..= "/"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ local floor, clamp = math.floor, math.clamp
|
|||||||
local K = {}
|
local K = {}
|
||||||
|
|
||||||
-- format ids: rgba8 1, rgba16 2, rgbaf32 3, rgb8 4, gray8 5, gray16 6, graya8 7, alpha8 8
|
-- format ids: rgba8 1, rgba16 2, rgbaf32 3, rgb8 4, gray8 5, gray16 6, graya8 7, alpha8 8
|
||||||
K.ID = { rgba8 = 1, rgba16 = 2, rgbaf32 = 3, rgb8 = 4, gray8 = 5, gray16 = 6, graya8 = 7, alpha8 = 8 }
|
K.ID = { rgba8 = 1, rgba16 = 2, rgbaf32 = 3, rgb8 = 4, gray8 = 5, gray16 = 6, graya8 = 7, alpha8 = 8 } :: { [string]: number }
|
||||||
K.KIND = { rgba8 = 1, rgba16 = 2, rgbaf32 = 4, rgb8 = 1, gray8 = 1, gray16 = 2, graya8 = 1, alpha8 = 1 }
|
K.KIND = { rgba8 = 1, rgba16 = 2, rgbaf32 = 4, rgb8 = 1, gray8 = 1, gray16 = 2, graya8 = 1, alpha8 = 1 } :: { [string]: number }
|
||||||
K.CHANNELS = { rgba8 = 4, rgba16 = 4, rgbaf32 = 4, rgb8 = 3, gray8 = 1, gray16 = 1, graya8 = 2, alpha8 = 1 }
|
K.CHANNELS = { rgba8 = 4, rgba16 = 4, rgbaf32 = 4, rgb8 = 3, gray8 = 1, gray16 = 1, graya8 = 2, alpha8 = 1 } :: { [string]: number }
|
||||||
|
|
||||||
local function rd(b: buffer, o: number, kind: number): number
|
local function rd(b: buffer, o: number, kind: number): number
|
||||||
if kind == 1 then
|
if kind == 1 then
|
||||||
@@ -74,11 +74,11 @@ local function luma(r: number, g: number, b: number, depth: number): number
|
|||||||
end
|
end
|
||||||
|
|
||||||
function K.convert(src: buffer, sf: number, dst: buffer, df: number, n: number)
|
function K.convert(src: buffer, sf: number, dst: buffer, df: number, n: number)
|
||||||
local sd, dd = DEPTH[sf], DEPTH[df]
|
local sd, dd = DEPTH[sf] :: number, DEPTH[df] :: number
|
||||||
local smax = if sd == 8 then 255 elseif sd == 16 then 65535 else 1
|
local smax = if sd == 8 then 255 elseif sd == 16 then 65535 else 1
|
||||||
local toGray = df == 5 or df == 6 or df == 7
|
local toGray = df == 5 or df == 6 or df == 7
|
||||||
for i = 0, n - 1 do
|
for i = 0, n - 1 do
|
||||||
local r, g, b, a
|
local r: number, g: number, b: number, a: number
|
||||||
if sf == 1 then
|
if sf == 1 then
|
||||||
local o = i * 4
|
local o = i * 4
|
||||||
r, g, b, a = readu8(src, o), readu8(src, o + 1), readu8(src, o + 2), readu8(src, o + 3)
|
r, g, b, a = readu8(src, o), readu8(src, o + 1), readu8(src, o + 2), readu8(src, o + 3)
|
||||||
@@ -281,7 +281,7 @@ function K.coeffs(inSize: number, outSize: number, filter: string): Coeffs
|
|||||||
local filterscale = math.max(scale, 1)
|
local filterscale = math.max(scale, 1)
|
||||||
local support = support0 * filterscale
|
local support = support0 * filterscale
|
||||||
local ss = 1 / filterscale
|
local ss = 1 / filterscale
|
||||||
local start, count, weights = table.create(outSize, 0), table.create(outSize, 0), table.create(outSize)
|
local start, count, weights = table.create(outSize, 0), table.create(outSize, 0), table.create(outSize) :: { { number } }
|
||||||
for xx = 0, outSize - 1 do
|
for xx = 0, outSize - 1 do
|
||||||
local center = (xx + 0.5) * scale
|
local center = (xx + 0.5) * scale
|
||||||
local xmin = math.max(0, trunc(center - support + 0.5))
|
local xmin = math.max(0, trunc(center - support + 0.5))
|
||||||
@@ -311,7 +311,7 @@ function K.resamplePass(src: buffer, w: number, h: number, ch: number, kind: num
|
|||||||
-- 8-bit: Pillow's 22-bit fixed-point coefficients
|
-- 8-bit: Pillow's 22-bit fixed-point coefficients
|
||||||
local iw: { { number } } = weights
|
local iw: { { number } } = weights
|
||||||
if fixed then
|
if fixed then
|
||||||
iw = table.create(outN)
|
iw = table.create(outN) :: { { number } }
|
||||||
for i = 1, outN do
|
for i = 1, outN do
|
||||||
local src0 = weights[i]
|
local src0 = weights[i]
|
||||||
local t = table.create(#src0, 0)
|
local t = table.create(#src0, 0)
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ end
|
|||||||
ImageOps.check = check
|
ImageOps.check = check
|
||||||
|
|
||||||
local function limit(w: number, h: number, opts: any): (boolean?, Err.Err?)
|
local function limit(w: number, h: number, opts: any): (boolean?, Err.Err?)
|
||||||
local max = (type(opts) == "table" and opts.maxPixels) or MAX_PIXELS
|
local max: number = (type(opts) == "table" and opts.maxPixels) or MAX_PIXELS
|
||||||
if w * h > max then
|
if w * h > max then
|
||||||
return nil, Err.new(Err.LIMIT, string.format("%d x %d is over the %d pixel limit", w, h, max))
|
return nil, Err.new(Err.LIMIT, string.format("%d x %d is over the %d pixel limit", w, h, max))
|
||||||
end
|
end
|
||||||
@@ -159,7 +159,7 @@ local function viaRgba(img: Image, f: (Image) -> (Image?, Err.Err?)): (Image?, E
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- ------------------------------------------------------------------------------------------------ geometry
|
-- ------------------------------------------------------------------------------------------------ geometry
|
||||||
local ALPHA_CH = { rgba8 = 4, rgba16 = 4, rgbaf32 = 4, graya8 = 2 }
|
local ALPHA_CH: { [string]: number } = { rgba8 = 4, rgba16 = 4, rgbaf32 = 4, graya8 = 2 }
|
||||||
|
|
||||||
-- crop(img, x, y, w, h) -> the rectangle clipped to the image | nil, Err (empty)
|
-- crop(img, x, y, w, h) -> the rectangle clipped to the image | nil, Err (empty)
|
||||||
function ImageOps.crop(img: Image, x: number, y: number, w: number, h: number): (Image?, Err.Err?)
|
function ImageOps.crop(img: Image, x: number, y: number, w: number, h: number): (Image?, Err.Err?)
|
||||||
@@ -338,7 +338,7 @@ function ImageOps.rotate(img: Image, degrees: number, opts: { expand: boolean?,
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- ------------------------------------------------------------------------------------------------ compositing
|
-- ------------------------------------------------------------------------------------------------ compositing
|
||||||
local RGBA = { rgba8 = true, rgba16 = true, rgbaf32 = true }
|
local RGBA: { [string]: boolean } = { rgba8 = true, rgba16 = true, rgbaf32 = true }
|
||||||
|
|
||||||
export type BlitOptions = { blend: ("over" | "source")?, opacity: number? }
|
export type BlitOptions = { blend: ("over" | "source")?, opacity: number? }
|
||||||
|
|
||||||
@@ -435,7 +435,7 @@ function ImageOps.unpremultiply(img: Image): (Image?, Err.Err?)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- ------------------------------------------------------------------------------------------------ pixels
|
-- ------------------------------------------------------------------------------------------------ pixels
|
||||||
local MAXV = { rgba8 = 255, rgba16 = 65535, rgbaf32 = 1, rgb8 = 255, gray8 = 255, gray16 = 65535, graya8 = 255, alpha8 = 255, yuv420p = 255 }
|
local MAXV: { [string]: number } = { rgba8 = 255, rgba16 = 65535, rgbaf32 = 1, rgb8 = 255, gray8 = 255, gray16 = 65535, graya8 = 255, alpha8 = 255, yuv420p = 255 }
|
||||||
|
|
||||||
-- getPixel(img, x, y) -> r, g, b, a in the format's scale (0..255, 0..65535 or float); grey gives r = g = b;
|
-- getPixel(img, x, y) -> r, g, b, a in the format's scale (0..255, 0..65535 or float); grey gives r = g = b;
|
||||||
-- alpha8 gives white; yuv420p converts to RGB. nil, Err out of range.
|
-- alpha8 gives white; yuv420p converts to RGB. nil, Err out of range.
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ function Greedy.run(data: buffer, sx: number, sy: number, sz: number, ox: number
|
|||||||
buffer.copy(nb, 0, b, 0, cap * per)
|
buffer.copy(nb, 0, b, 0, cap * per)
|
||||||
return nb
|
return nb
|
||||||
end
|
end
|
||||||
pos, nrm, idx, tri = grow2(pos, 48), grow2(nrm, 48), grow2(idx, 4), grow2(tri, 24)
|
pos, nrm, idx, tri = grow2(pos, 48), grow2(nrm, 48), grow2(idx, 4), grow2(tri, 24) :: buffer
|
||||||
cap = ncap
|
cap = ncap
|
||||||
end
|
end
|
||||||
corner[d + 1] = slice + 1
|
corner[d + 1] = slice + 1
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ function MeshOps.triangulate(prim: Primitive, opts: { method: string? }?): (Prim
|
|||||||
table.insert(out, readu32(ib, (at + a + 1) * 4))
|
table.insert(out, readu32(ib, (at + a + 1) * 4))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local poly = table.create(k)
|
local poly = table.create(k) :: { number }
|
||||||
for a = 0, k - 1 do
|
for a = 0, k - 1 do
|
||||||
poly[a + 1] = readu32(ib, (at + a) * 4)
|
poly[a + 1] = readu32(ib, (at + a) * 4)
|
||||||
end
|
end
|
||||||
@@ -856,7 +856,7 @@ function MeshOps.merge(input: any, opts: { byMaterial: boolean?, method: string?
|
|||||||
end
|
end
|
||||||
return out, nil
|
return out, nil
|
||||||
end
|
end
|
||||||
local all = groups[0] or {}
|
local all: { Primitive } = groups[0] or {}
|
||||||
local first = all[1]
|
local first = all[1]
|
||||||
return concat(all, first and first.material), nil
|
return concat(all, first and first.material), nil
|
||||||
end
|
end
|
||||||
@@ -1025,7 +1025,7 @@ function MeshOps.voxelsToPrimitive(v: Types.Voxels, opts: { pivot: string?, scal
|
|||||||
local col = buffer.create(nv * (if srgb then 4 else 16))
|
local col = buffer.create(nv * (if srgb then 4 else 16))
|
||||||
local lut: { { number } } = {}
|
local lut: { { number } } = {}
|
||||||
for i = 1, 255 do
|
for i = 1, 255 do
|
||||||
local c = pal[i] or { 255, 255, 255, 255 }
|
local c: { number } = pal[i] or { 255, 255, 255, 255 }
|
||||||
if srgb then
|
if srgb then
|
||||||
lut[i] = { c[1] or 0, c[2] or 0, c[3] or 0, c[4] or 255 }
|
lut[i] = { c[1] or 0, c[2] or 0, c[3] or 0, c[4] or 255 }
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in new issue
Block a user