-
Notifications
You must be signed in to change notification settings - Fork 5
/
quickTraceMask.avsi
33 lines (29 loc) · 1.67 KB
/
quickTraceMask.avsi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function quickTraceMask(clip c, string "colors", int "tolerance", int "lumalow", int "lumahigh", string "mode", float "ss", bool "aa", int "expand", bool "show", bool "bt601", int "postexpand")
{
mode = Default(mode, "and")
ss = Default(ss, 2.0)
aa = Default(aa, true)
expand = Default(expand, 3)
bt601 = Default(bt601, false)
lumalow = Default(lumalow, 0)
lumahigh=Default(lumahigh, 255)
show = Default(show, false)
postexpand = Default(postexpand, -1)
sw = c.Width sh = c.Height
ssw = int(round(sw*ss/4.0)*4) ssh = int(round(sh*ss/4.0)*4)
useluma = (lumalow > 0 || lumahigh < 255) ? true : false
usecolor = Defined(colors) && colors!=""
c
if(ss != 1.0) { Spline36Resize(ssw, ssh) }
if(usecolor) { cmask = tcolormask(colors, tolerance, bt601).ConvertToY8(bt601 ? "Rec601" : "Rec709") }
lmask = useluma ? ConvertToY8(bt601 ? "Rec601" : "Rec709").mt_lut("x " + String(lumalow) + " >= x " + String(lumahigh) + " <= & 255 0 ?",y=3,u=1,v=1)
\: (mode.LuIsEq("min||and")) ? last.BlankClip(pixel_type = "Y8", color_yuv=0) : last.BlankClip(pixel_type = "Y8", color_yuv=$FFFFFF)
usecolor ? useluma ? mt_logic(cmask, lmask, mode) : cmask : lmask
if(expand > 0) {mt_expand_multi(sw=expand, sh=expand)}
else if(expand < 0) {mt_inpand_multi(sw=-expand, sh=-expand)}
if(postexpand > 0) {mt_expand_multi(sw=postexpand, sh=postexpand)}
else if(postexpand < 0) {mt_inpand_multi(sw=-postexpand, sh=-postexpand)}
if(ss != 1.0) { Spline36Resize(sw, sh) }
if(aa) { HiAA(aa="sangnom2", preaa=True) }
return show ? c.mt_merge(c.mt_lut(y=2, u=0, v=0), last, u=3, v=3, luma=true) : mt_invert()
}