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
@@ -13,9 +13,9 @@ local floor, clamp = math.floor, math.clamp
|
||||
local K = {}
|
||||
|
||||
-- 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.KIND = { rgba8 = 1, rgba16 = 2, rgbaf32 = 4, rgb8 = 1, gray8 = 1, gray16 = 2, graya8 = 1, alpha8 = 1 }
|
||||
K.CHANNELS = { rgba8 = 4, rgba16 = 4, rgbaf32 = 4, rgb8 = 3, gray8 = 1, gray16 = 1, graya8 = 2, alpha8 = 1 }
|
||||
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 } :: { [string]: number }
|
||||
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
|
||||
if kind == 1 then
|
||||
@@ -74,11 +74,11 @@ local function luma(r: number, g: number, b: number, depth: number): number
|
||||
end
|
||||
|
||||
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 toGray = df == 5 or df == 6 or df == 7
|
||||
for i = 0, n - 1 do
|
||||
local r, g, b, a
|
||||
local r: number, g: number, b: number, a: number
|
||||
if sf == 1 then
|
||||
local o = i * 4
|
||||
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 support = support0 * 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
|
||||
local center = (xx + 0.5) * scale
|
||||
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
|
||||
local iw: { { number } } = weights
|
||||
if fixed then
|
||||
iw = table.create(outN)
|
||||
iw = table.create(outN) :: { { number } }
|
||||
for i = 1, outN do
|
||||
local src0 = weights[i]
|
||||
local t = table.create(#src0, 0)
|
||||
|
||||
@@ -62,7 +62,7 @@ end
|
||||
ImageOps.check = check
|
||||
|
||||
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
|
||||
return nil, Err.new(Err.LIMIT, string.format("%d x %d is over the %d pixel limit", w, h, max))
|
||||
end
|
||||
@@ -159,7 +159,7 @@ local function viaRgba(img: Image, f: (Image) -> (Image?, Err.Err?)): (Image?, E
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ 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)
|
||||
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
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ 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? }
|
||||
|
||||
@@ -435,7 +435,7 @@ function ImageOps.unpremultiply(img: Image): (Image?, Err.Err?)
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ 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;
|
||||
-- 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)
|
||||
return nb
|
||||
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
|
||||
end
|
||||
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))
|
||||
end
|
||||
else
|
||||
local poly = table.create(k)
|
||||
local poly = table.create(k) :: { number }
|
||||
for a = 0, k - 1 do
|
||||
poly[a + 1] = readu32(ib, (at + a) * 4)
|
||||
end
|
||||
@@ -856,7 +856,7 @@ function MeshOps.merge(input: any, opts: { byMaterial: boolean?, method: string?
|
||||
end
|
||||
return out, nil
|
||||
end
|
||||
local all = groups[0] or {}
|
||||
local all: { Primitive } = groups[0] or {}
|
||||
local first = all[1]
|
||||
return concat(all, first and first.material), nil
|
||||
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 lut: { { number } } = {}
|
||||
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
|
||||
lut[i] = { c[1] or 0, c[2] or 0, c[3] or 0, c[4] or 255 }
|
||||
else
|
||||
|
||||
Reference in new issue
Block a user