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
@@ -209,7 +209,9 @@ function Bmp.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Image?, Err.E
|
||||
if comp == 3 or comp == 6 then
|
||||
hasMasks = true
|
||||
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
|
||||
am = readu32(buf, 66)
|
||||
end
|
||||
@@ -218,7 +220,9 @@ function Bmp.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Image?, Err.E
|
||||
if palStart + count * 4 > n then
|
||||
return nil, Err.new(Err.TRUNCATED, "truncated bit masks")
|
||||
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
|
||||
am = readu32(buf, palStart + 12)
|
||||
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 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
|
||||
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
|
||||
o:i32le(xp)
|
||||
o:i32le(yp)
|
||||
|
||||
@@ -50,7 +50,7 @@ export type EncodeOptions = {
|
||||
-- ------------------------------------------------------------------------------------------------ constants
|
||||
local readu8 = buffer.readu8
|
||||
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
|
||||
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
|
||||
local function colorTable(b: buffer, p: number, n: number): (buffer, { { number } })
|
||||
local t = buffer.create(1024)
|
||||
local list = table.create(n)
|
||||
local list: { { number } } = table.create(n) :: { { number } }
|
||||
for i = 0, 255 do
|
||||
buffer.writeu32(t, i * 4, 0xFF000000)
|
||||
end
|
||||
@@ -404,7 +404,7 @@ function Gif.encode(img: Types.Image, opts: EncodeOptions?): (buffer?, Err.Err?)
|
||||
end
|
||||
-- palettes
|
||||
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 globalTrans = false
|
||||
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)
|
||||
end
|
||||
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)
|
||||
end
|
||||
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
|
||||
img.meta.truncated = true
|
||||
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
|
||||
end
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ function Ico.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Image?, Err.E
|
||||
if typ == 2 then
|
||||
im.meta.hotspot = { x = f1, y = f2 }
|
||||
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
|
||||
if score > bestScore then
|
||||
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
|
||||
return false, "truncated"
|
||||
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
|
||||
elseif op == 0xFF then
|
||||
if p + 4 > limit then
|
||||
return false, "truncated"
|
||||
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
|
||||
else
|
||||
local tag = op // 64
|
||||
if tag == 0 then
|
||||
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
|
||||
r = (r + (op // 16) % 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.writeu32(out, 4, bit32.byteswap(w))
|
||||
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)
|
||||
local o = Codec.encode(img.pixels, n, bpp, out, 14)
|
||||
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
|
||||
end
|
||||
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
|
||||
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)
|
||||
@@ -399,7 +401,9 @@ function Pixels.convert(P: Params)
|
||||
a = norm(alpha, x, y)
|
||||
if assoc 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
|
||||
r, g, bl = 0, 0, 0
|
||||
end
|
||||
|
||||
@@ -322,7 +322,7 @@ local function decodePage(c: Ctx, t: { [number]: Entry }, opts: DecodeOptions?):
|
||||
if not offs or #offs < perPlane * nplanes then
|
||||
return nil, Err.new(Err.CORRUPT, "missing or short strip / tile offsets")
|
||||
end
|
||||
local planes = table.create(nplanes)
|
||||
local planes: { buffer } = table.create(nplanes) :: { buffer }
|
||||
for i = 1, nplanes do
|
||||
planes[i] = buffer.create(rb * h + 8)
|
||||
end
|
||||
@@ -583,7 +583,7 @@ function Tiff.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Image?, Err.
|
||||
end
|
||||
local img, perr = decodePage(c, t, opts)
|
||||
if img then
|
||||
img.meta.source.pages = #list
|
||||
(img.meta.source :: { [string]: any }).pages = #list
|
||||
end
|
||||
return img, perr
|
||||
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" })
|
||||
end
|
||||
local img = first :: Types.Image
|
||||
img.meta.source.pages = #frames
|
||||
(img.meta.source :: { [string]: any }).pages = #frames
|
||||
if #frames > 1 then
|
||||
img.frames = frames :: any
|
||||
end
|
||||
@@ -722,7 +722,7 @@ local function encodePage(img: Types.Image, o: EncodeOptions, comp: number): ({
|
||||
end
|
||||
local text = img.meta and img.meta.text
|
||||
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
|
||||
table.insert(tags, { tag = tag, typ = 2, data = buffer.fromstring(text[key] .. "\0") })
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user