merge master

This commit is contained in:
4DBug committed 2026-10-31 14:25:41 -05:00
commit b5964d4afc
39 files changed
+1158 -73

No files matched your search

+36 -8
View File
@@ -273,14 +273,40 @@ local function composite(dst: buffer, dw: number, dh: number, src: buffer, sw: n
end
end
-- lerp(dst, from, t, n): dst = from + (dst - from) * t per byte over n pixels (pass-through group opacity)
local function lerp(dst: buffer, from: buffer, t: number, n: number)
-- lerp(dst, from, t, n, w?, mask?): dst = from + (dst - from) * t per byte over n pixels (pass-through group opacity);
-- with a mask ({ pixels, width, height, x, y, default } as for composite, in the coordinates of a w-wide canvas) t is
-- also scaled by the mask value of each pixel
local function lerp(dst: buffer, from: buffer, t: number, n: number, w: number?, mask: any?)
if blen(dst) < n * 4 or blen(from) < n * 4 then
return
end
for i = 0, n * 4 - 1 do
local a = readu8(from, i)
writeu8(dst, i, floor(a + (readu8(dst, i) - a) * t + 0.5))
if mask == nil or w == nil or w <= 0 then
for i = 0, n * 4 - 1 do
local a = readu8(from, i)
writeu8(dst, i, floor(a + (readu8(dst, i) - a) * t + 0.5))
end
return
end
local mbuf: buffer? = mask.pixels
local mw, mh = floor(tonumber(mask.width) or 0), floor(tonumber(mask.height) or 0)
local mx0, my0 = floor(tonumber(mask.x) or 0), floor(tonumber(mask.y) or 0)
local mdef = (tonumber(mask.default) or 255) / 255
if type(mbuf) ~= "buffer" or mw <= 0 or mh <= 0 or blen(mbuf) < mw * mh then
mbuf = nil
end
for p = 0, n - 1 do
local px, py = p % w, p // w
local mv = mdef
local mxx, myy = px - mx0, py - my0
if mbuf ~= nil and mxx >= 0 and myy >= 0 and mxx < mw and myy < mh then
mv = readu8(mbuf, myy * mw + mxx) / 255
end
local tt = t * mv
local o = p * 4
for k = o, o + 3 do
local a = readu8(from, k)
writeu8(dst, k, floor(a + (readu8(dst, k) - a) * tt + 0.5))
end
end
end
Blend.composite = composite
@@ -330,8 +356,10 @@ local function compose(layers: { any }, canvas: buffer, w: number, h: number, hi
local before = buffer.create(w * h * 4)
buffer.copy(before, 0, canvas, 0, w * h * 4)
compose(l.children, canvas, w, h, hidden)
if opacity < 1 then
lerp(canvas, before, opacity, w * h)
-- the group's opacity and mask limit how much of its effect reaches the canvas (as in Photoshop)
local gm = maskOf(l)
if opacity < 1 or gm ~= nil then
lerp(canvas, before, opacity, w * h, w, gm)
end
continue
end
@@ -360,7 +388,7 @@ end
-- flatten(layers, canvas, w, h, hidden): composites a Types.Layer tree (bottom to top) onto the w x h rgba8 canvas:
-- blend modes, opacity x fillOpacity, groups (isolated, or "passThrough": blended straight onto the canvas, the group
-- opacity then mixing before / after), clipping layers (clip = true: source-atop onto the layer below), grey masks.
-- opacity and mask then mixing before / after), clipping layers (clip = true: source-atop onto the layer below), grey masks.
-- hidden = true includes invisible layers.
function Blend.flatten(layers: { any }, canvas: buffer, w: number, h: number, hidden: boolean)
if blen(canvas) >= w * h * 4 then
+6
View File
@@ -466,6 +466,11 @@ function Video.open(demuxer: Types.Demuxer, opts: OpenOptions?): (Types.VideoDec
if img then
local t = (pts or 0) / scale - start
if t + 1e-9 >= skipUntil then
if index < 0 then
-- the first frame after a seek: its position in the stream (constant-rate: round(pts * fps);
-- without a frame rate, counted from the seek)
index = if v.frameRate > 0 then math.max(0, math.floor(t * v.frameRate + 0.5)) else 0
end
index += 1
local d = defaultDur
if lastPts and t > (lastPts :: number) and defaultDur == 0 then
@@ -502,6 +507,7 @@ function Video.open(demuxer: Types.Demuxer, opts: OpenOptions?): (Types.VideoDec
flushed = false
skipUntil = seconds
lastPts = nil
index = -1 -- recomputed from the first frame's time
if self.audio then
pcall(self.audio.seek, self.audio, seconds)
end