logarrhythmic / karaOK

Aegisub KFX library
28 stars 7 forks source link

Clamp values for alpha tags with wave transforms #2

Closed petzku closed 4 years ago

petzku commented 4 years ago

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})!}