1
1
from typing import Optional
2
2
3
- import mvsfunc as mvf
4
3
import vapoursynth as vs
5
- from havsfunc import cround , m4 , mt_expand_multi , mt_inpand_multi , scale
6
4
from vapoursynth import core
7
5
6
+ import mbfunc .havsfunc as haf
7
+ import mbfunc .mvsfunc as mvf
8
+
8
9
9
10
def DeHalo_alpha (
10
11
clp : vs .VideoNode ,
@@ -33,12 +34,12 @@ def DeHalo_alpha(
33
34
ox = clp .width
34
35
oy = clp .height
35
36
36
- halos = clp .resize .Bicubic (m4 ( ox / rx ), m4 ( oy / ry ), filter_param_a = 1 / 3 , filter_param_b = 1 / 3 ). resize . Bicubic (
37
- ox , oy , filter_param_a = 1 , filter_param_b = 0
38
- )
37
+ halos = clp .resize .Bicubic (
38
+ haf . m4 ( ox / rx ), haf . m4 ( oy / ry ) , filter_param_a = 1 / 3 , filter_param_b = 1 / 3
39
+ ). resize . Bicubic ( ox , oy , filter_param_a = 1 , filter_param_b = 0 )
39
40
are = core .std .Expr ([clp .std .Maximum (), clp .std .Minimum ()], expr = ["x y -" ])
40
41
ugly = core .std .Expr ([halos .std .Maximum (), halos .std .Minimum ()], expr = ["x y -" ])
41
- expr = f"y x - y y 0 = + / { peak } * { scale (lowsens , peak )} - y { scale (256 , peak )} + { scale (512 , peak )} / { highsens / 100 } + *"
42
+ expr = f"y x - y y 0 = + / { peak } * { haf . scale (lowsens , peak )} - y { haf . scale (256 , peak )} + { haf . scale (512 , peak )} / { highsens / 100 } + *"
42
43
so = core .std .Expr ([ugly , are ], expr = [expr ])
43
44
lets = core .std .MaskedMerge (halos , clp , so )
44
45
if ss <= 1 :
@@ -48,14 +49,16 @@ def DeHalo_alpha(
48
49
[
49
50
core .std .Expr (
50
51
[
51
- clp .resize .Lanczos (m4 (ox * ss ), m4 (oy * ss )),
52
+ clp .resize .Lanczos (haf . m4 (ox * ss ), haf . m4 (oy * ss )),
52
53
lets .std .Maximum ().resize .Bicubic (
53
- m4 (ox * ss ), m4 (oy * ss ), filter_param_a = 1 / 3 , filter_param_b = 1 / 3
54
+ haf . m4 (ox * ss ), haf . m4 (oy * ss ), filter_param_a = 1 / 3 , filter_param_b = 1 / 3
54
55
),
55
56
],
56
57
expr = ["x y min" ],
57
58
),
58
- lets .std .Minimum ().resize .Bicubic (m4 (ox * ss ), m4 (oy * ss ), filter_param_a = 1 / 3 , filter_param_b = 1 / 3 ),
59
+ lets .std .Minimum ().resize .Bicubic (
60
+ haf .m4 (ox * ss ), haf .m4 (oy * ss ), filter_param_a = 1 / 3 , filter_param_b = 1 / 3
61
+ ),
59
62
],
60
63
expr = ["x y max" ],
61
64
).resize .Lanczos (ox , oy )
@@ -99,23 +102,23 @@ def FineDehalo(
99
102
if ry is None :
100
103
ry = rx
101
104
102
- rx_i = cround (rx )
103
- ry_i = cround (ry )
105
+ rx_i = haf . cround (rx )
106
+ ry_i = haf . cround (ry )
104
107
105
108
dehaloed = DeHalo_alpha (src , rx = rx , ry = ry , darkstr = darkstr , brightstr = brightstr )
106
109
edges = core .std .Prewitt (src )
107
110
108
111
# Keeps only the sharpest edges (line edges)
109
112
strong = edges .std .Expr (
110
113
expr = [
111
- f"x { scale (thmi , peak )} - { thma - thmi } / 255 *"
114
+ f"x { haf . scale (thmi , peak )} - { thma - thmi } / 255 *"
112
115
if isInteger
113
- else f"x { scale (thmi , peak )} - { thma - thmi } / 255 * 0 max 1 min"
116
+ else f"x { haf . scale (thmi , peak )} - { thma - thmi } / 255 * 0 max 1 min"
114
117
]
115
118
)
116
119
117
120
# Extends them to include the potential halos
118
- large = mt_expand_multi (strong , sw = rx_i , sh = ry_i )
121
+ large = haf . mt_expand_multi (strong , sw = rx_i , sh = ry_i )
119
122
120
123
### Exclusion zones ###
121
124
@@ -125,24 +128,24 @@ def FineDehalo(
125
128
# Includes more edges than previously, but ignores simple details
126
129
light = edges .std .Expr (
127
130
expr = [
128
- f"x { scale (thlimi , peak )} - { thlima - thlimi } / 255 *"
131
+ f"x { haf . scale (thlimi , peak )} - { thlima - thlimi } / 255 *"
129
132
if isInteger
130
- else f"x { scale (thlimi , peak )} - { thlima - thlimi } / 255 * 0 max 1 min"
133
+ else f"x { haf . scale (thlimi , peak )} - { thlima - thlimi } / 255 * 0 max 1 min"
131
134
]
132
135
)
133
136
134
137
# To build the exclusion zone, we make grow the edge mask, then shrink it to its original shape
135
138
# During the growing stage, close adjacent edge masks will join and merge, forming a solid area, which will remain solid even after the shrinking stage
136
139
137
140
# Mask growing
138
- shrink = mt_expand_multi (light , mode = "ellipse" , sw = rx_i , sh = ry_i )
141
+ shrink = haf . mt_expand_multi (light , mode = "ellipse" , sw = rx_i , sh = ry_i )
139
142
140
143
# At this point, because the mask was made of a shades of grey, we may end up with large areas of dark grey after shrinking
141
144
# To avoid this, we amplify and saturate the mask here (actually we could even binarize it)
142
145
shrink = shrink .std .Expr (expr = ["x 4 *" if isInteger else "x 4 * 1 min" ])
143
146
144
147
# Mask shrinking
145
- shrink = mt_inpand_multi (shrink , mode = "ellipse" , sw = rx_i , sh = ry_i )
148
+ shrink = haf . mt_inpand_multi (shrink , mode = "ellipse" , sw = rx_i , sh = ry_i )
146
149
147
150
# This mask is almost binary, which will produce distinct discontinuities once applied. Then we have to smooth it
148
151
shrink = shrink .std .Convolution (matrix = [1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ]).std .Convolution (
0 commit comments