SHOW:
|
|
- or go back to the newest paste.
1 | ############################### | |
2 | - | # FastLineDarken 1.46x MT MOD # |
2 | + | # FastLineDarken 1.47x MT MOD # |
3 | ############################### | |
4 | # | |
5 | # Written by Vectrangle (http://forum.doom9.org/showthread.php?t=82125) | |
6 | # Didée: - Speed Boost, Updated: 11th May 2007 | |
7 | # Dogway - added protection option. 12-May-2011 | |
8 | # A.SONY - added high bit support and others. 31-Mar-2017 | |
9 | # | |
10 | # * requires mt_masktools v2 in avs2.5 and masktools 2.2.17 in avs 2.6 or avs+ | |
11 | # * requires yuv input | |
12 | # | |
13 | # | |
14 | # | |
15 | # Parameters are: | |
16 | # strength (integer) - Line darkening amount, 0-256. Default 48. Represents the _maximum_ amount | |
17 | # that the luma will be reduced by, weaker lines will be reduced by | |
18 | # proportionately less. | |
19 | # prot (integer) - Prevents the darkest lines from being darkened. Protection acts as a threshold. | |
20 | # Values range from 0 (no prot) to ~50 (protect everything). Default 5. | |
21 | # luma_cap (integer) - value from 0 (black) to 255 (white), used to stop the darkening | |
22 | # determination from being 'blinded' by bright pixels, and to stop grey | |
23 | # lines on white backgrounds being darkened. Any pixels brighter than | |
24 | # luma_cap are treated as only being as bright as luma_cap. Lowering | |
25 | # luma_cap tends to reduce line darkening. 255 disables capping. Default 191. | |
26 | # threshold (integer) - any pixels that were going to be darkened by an amount less than | |
27 | # threshold will not be touched. setting this to 0 will disable it, setting | |
28 | # it to 4 (default) is recommended, since often a lot of random pixels are | |
29 | # marked for very slight darkening and a threshold of about 4 should fix | |
30 | # them. Note if you set threshold too high, some lines will not be darkened | |
31 | # thinning (integer) - optional line thinning amount, 0-256. Setting this to 0 will disable it, | |
32 | # which is gives a _big_ speed increase. Note that thinning the lines will | |
33 | # inherently darken the remaining pixels in each line a little. Default 0. | |
34 | # | |
35 | # Changelog: | |
36 | # 1.43 - update to masktools 2.2.17 | |
37 | # 1.42 - added high bit support in avs+ and others Optmized | |
38 | # 1.4 - added protection option. Prevents darkest lines to be over darkened thus creating artifacts (i.e. aliasing, clipping...) | |
39 | # - Optmized the code as suggested by Didée for possible faster processing. It also deals with the green screen bug. | |
40 | # 1.3 - added ability to thin lines, now runs much slower unless thinning=0. Changed the defaults (again) | |
41 | # 1.2 - huge speed increase using yv12lutxy =) | |
42 | # - weird darkening issues gone (they were caused by yv12layer) | |
43 | # - show option no longer available due to optimizations. Use subtract() instead | |
44 | # 1.1 - added luma_cap option | |
45 | # 1.0 - initial release | |
46 | # | |
47 | ||
48 | ||
49 | function FastLineDarkenMOD4( clip input, float "strength", float "prot", float "luma_cap", float "threshold", float "thinning") | |
50 | { | |
51 | ## parameters ## | |
52 | str = string(default(strength, 48) /128.) | |
53 | lum = string(default(luma_cap, 191)) | |
54 | protection = default(prot,5) | |
55 | thr = string(default(threshold, 4)) | |
56 | thinning = default(thinning,0) | |
57 | thn = string(thinning /16.) | |
58 | ||
59 | Assert(!(input.isrgb()), "FastLineDarkenMOD4: RGB Color formats is not supported" ) | |
60 | ||
61 | sisphbd = AvsPlusVersionNumber > 2294 | |
62 | ||
63 | sislumaonly = sisphbd ? input.isy() : VersionNumber() < 2.6 ? true : input.isy8() | |
64 | ||
65 | c = sislumaonly ? input : sisphbd ? input.converttoy() : input.converttoy8() | |
66 | ||
67 | ## filtering ## | |
68 | exin = c.mt_expand(thy=255/(protection+1)).mt_inpand() | |
69 | diff = VersionNumber() < 2.6 ? mt_lutxy(c,exin,yexpr="y "+lum+" < y "+lum+" ? x "+thr+" + > x y "+lum+" < y "+lum+" ? - 0 ? 127 +",uexpr="x",vexpr="x") | |
70 | \ : mt_lutxy(c,exin,yexpr="y "+lum+" scalef < y "+lum+" scalef ? x "+thr+" scalef + > x y "+lum+" scalef < y "+lum+" scalef ? - 0 ? 127 scalef +", use_expr=1) | |
71 | linemask= thinning != 0 ? VersionNumber() < 2.6 ? mt_lut(diff.mt_inpand(),"x 127 - "+thn+" * 255 +").RemoveGrain(20,-1) | |
72 | - | \ : mt_lut(diff.mt_inpand(),"x 127 scalef - "+thn+" * range_max +",clamp_float=true,use_expr=3).RemoveGrain(20,-1) : nop() |
72 | + | \ : mt_lut(diff.mt_inpand(),"x 127 scalef - "+thn+" * range_max +",clamp_float=true,use_expr=2).RemoveGrain(20,-1) : nop() |
73 | thick = VersionNumber() < 2.6 ? mt_lutxy(c, exin, yexpr="y "+lum+" < y "+lum+" ? x "+thr+" + > x y "+lum+" < y "+lum+" ? - 0 ? "+str+" * x +",uexpr="x",vexpr="x",u=2, v=2) | |
74 | \ : mt_lutxy(c, exin, yexpr="y "+lum+" scalef < y "+lum+" scalef ? x "+thr+" scalef + > x y "+lum+" scalef < y "+lum+" scalef ? - 0 ? "+str+" * x +",clamp_float=true,use_expr=1,u=2, v=2) | |
75 | thin = thinning != 0 ? VersionNumber() < 2.6 ? mt_lutxy(c.mt_expand(U=2,V=2),diff,yexpr="x y 127 - "+str+" 1 + * +",u=2, v=2) | |
76 | \ : mt_lutxy(c.mt_expand(U=2,V=2),diff,yexpr="x y 127 scalef - "+str+" 1 + * +", scale_inputs="floatf", use_expr=3,u=2, v=2) : nop() | |
77 | ||
78 | thinning == 0 ? thick : mt_merge(thin,thick,linemask,y=3,u=2,v=2) | |
79 | ||
80 | return sislumaonly ? last : sisphbd ? CombinePlanes(last,input,planes="YUV",sample_clip=input) : ytouv(input.utoy8(),input.vtoy8(),last) | |
81 | } | |
82 | ||
83 | ############# | |
84 | ||
85 | ||
86 | function FastLineDarkenMOD3( clip c, int "strength", int "prot", int "luma_cap", int "threshold", int "thinning") | |
87 | { | |
88 | ## parameters ## | |
89 | str = string(default(strength, 50) /128.) | |
90 | lum = string(default(luma_cap, 191)) | |
91 | protection = default(prot,5) | |
92 | thr = string(default(threshold, 4)) | |
93 | thinning = default(thinning,0) | |
94 | thn = string(thinning /16.) | |
95 | ||
96 | ## filtering ## | |
97 | exin = c.mt_expand(thy=255/(protection+1)).mt_inpand() | |
98 | diff = mt_lutxy(c,exin,yexpr="y "+lum+" < y "+lum+" ? x "+thr+" + > x y "+lum+" < y "+lum+" ? - 0 ? 127 +",uexpr="x",vexpr="x") | |
99 | linemask= mt_lut(diff.mt_inpand(),"x 127 - "+thn+" * 255 +").mt_convolution("1 1 1","1 1 1",y=3,u=0,v=0)#".RemoveGrain(20,-1)" gives a little speed boost. | |
100 | thick = mt_lutxy(c, exin, yexpr="y "+lum+" < y "+lum+" ? x "+thr+" + > x y "+lum+" < y "+lum+" ? - 0 ? "+str+" * x +",uexpr="x",vexpr="x") | |
101 | thin = mt_lutxy(c.mt_expand(),diff,yexpr="x y 127 - "+str+" 1 + * +") | |
102 | ||
103 | (thinning == 0) ? thick : mt_merge(thin,thick,linemask,y=3) | |
104 | return mergechroma(c)} | |
105 | ||
106 | ############# | |
107 | ||
108 | ||
109 | function FastLineDarkenMOD2( clip c, int "strength", int "luma_cap", int "threshold", int "thinning") | |
110 | { | |
111 | ## parameters ## | |
112 | str = string(default(strength, 48) /128.) | |
113 | lum = string(default(luma_cap, 191)) | |
114 | thr = string(default(threshold, 4)) | |
115 | thinning = default(thinning,24) | |
116 | thn = string(thinning /16.) | |
117 | ||
118 | ## filtering ## | |
119 | exin = c.mt_expand().mt_inpand() | |
120 | diff = mt_lutxy(c,exin,yexpr="y "+lum+" < y "+lum+" ? x "+thr+" + > x y "+lum+" < y "+lum+" ? - 0 ? 127 +",uexpr="x",vexpr="x",u=2, v=2) | |
121 | linemask= mt_lut(diff.mt_inpand(),"x 127 - "+thn+" * 255 +").mt_convolution("1 1 1","1 1 1",y=3,u=0,v=0)#".RemoveGrain(20,-1)" gives a little speed boost. | |
122 | thick = mt_lutxy(c, exin, yexpr="y "+lum+" < y "+lum+" ? x "+thr+" + > x y "+lum+" < y "+lum+" ? - 0 ? "+str+" * x +",uexpr="x",vexpr="x",u=2, v=2) | |
123 | thin = mt_lutxy(c.mt_expand(U=2,V=2),diff,yexpr="x y 127 - "+str+" 1 + * +",u=2, v=2) | |
124 | ||
125 | return (thinning == 0) ? thick : mt_merge(thin,thick,linemask,y=3,u=2,v=2) | |
126 | } |