ws-cleanup-types: containers, ops: type the tables and locals the solver cannot infer
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
2c15b97cd8
commit
8e6894c6b5
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.
|
||||
|
||||
Reference in new issue
Block a user