Clamp values for alpha tags with wave transforms
Closed this issue · 0 comments
petzku commented
Tags such as \alpha
(with a strict range of valid values) can be transformed using ln.wave.transform
, but values aren't clamped, so wave values outside the range (0, 255)
produce invalid tags. Negative values seem to result in integer underflow(?) and give tags like \alpha&HFFFFFFFFFFFFFF83&
, while values greater than 255 simply give tags like \alpha&H152&
.
A workaround exists, by supplying modifierFunctions
the values can be clamped by the user, but I see no need to allow invalid values in the first place.
Example code that produces this sort of output:
Comment: 50,0:00:04.20,0:00:04.20,Default,,0,0,0,code once,ln = _G.require 'ln.kara'; ln.init(tenv)
Comment: 50,0:00:04.20,0:00:04.20,Default,,0,0,0,code once,alphaWave = ln.wave.new();
Comment: 50,0:00:04.20,0:00:04.20,Default,,0,0,0,code once,alphaWave.addWave("sine", 3000, 256, 0.5); alphaWave.addFunction(function (t) return 128 end);
Comment: 1,0:00:04.20,0:00:04.20,OP2 - ENG,,0,0,0,template char noblank,{\an5\pos($center,$middle)\blur0.7\!ln.wave.transform(alphaWave, "alpha")!}
Workaround:
Comment: 50,0:00:04.20,0:00:04.20,Default,,0,0,0,code once,function alphaFilter(x) return clamp(x, 0, 255) end
Comment: 1,0:00:04.20,0:00:04.20,OP2 - ENG,,0,0,0,template char noblank,{\an5\pos($center,$middle)\blur0.7\!ln.wave.transform(alphaWave, "alpha", nil, nil, nil, nil, nil, {alphaFilter})!}