Skip to content

Commit b95e2e2

Browse files
authored
feat: use internal mvsfunc and havsfunc (#5)
1 parent 5109f3f commit b95e2e2

File tree

11 files changed

+10979
-28
lines changed

11 files changed

+10979
-28
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ mbf's VapourSynth functions
99

1010
### Requirements
1111

12-
- [mvsfunc](https://github.com/HomeOfVapourSynthEvolution/mvsfunc)
13-
- [havsfunc](https://github.com/HomeOfVapourSynthEvolution/havsfunc)
12+
- [VapourSynth](https://github.com/vapoursynth/vapoursynth)
1413

1514
### Installation
1615

mbfunc/dehalo/dehalo.py

+21-18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from typing import Optional
22

3-
import mvsfunc as mvf
43
import vapoursynth as vs
5-
from havsfunc import cround, m4, mt_expand_multi, mt_inpand_multi, scale
64
from vapoursynth import core
75

6+
import mbfunc.havsfunc as haf
7+
import mbfunc.mvsfunc as mvf
8+
89

910
def DeHalo_alpha(
1011
clp: vs.VideoNode,
@@ -33,12 +34,12 @@ def DeHalo_alpha(
3334
ox = clp.width
3435
oy = clp.height
3536

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)
3940
are = core.std.Expr([clp.std.Maximum(), clp.std.Minimum()], expr=["x y -"])
4041
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} + *"
4243
so = core.std.Expr([ugly, are], expr=[expr])
4344
lets = core.std.MaskedMerge(halos, clp, so)
4445
if ss <= 1:
@@ -48,14 +49,16 @@ def DeHalo_alpha(
4849
[
4950
core.std.Expr(
5051
[
51-
clp.resize.Lanczos(m4(ox * ss), m4(oy * ss)),
52+
clp.resize.Lanczos(haf.m4(ox * ss), haf.m4(oy * ss)),
5253
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
5455
),
5556
],
5657
expr=["x y min"],
5758
),
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+
),
5962
],
6063
expr=["x y max"],
6164
).resize.Lanczos(ox, oy)
@@ -99,23 +102,23 @@ def FineDehalo(
99102
if ry is None:
100103
ry = rx
101104

102-
rx_i = cround(rx)
103-
ry_i = cround(ry)
105+
rx_i = haf.cround(rx)
106+
ry_i = haf.cround(ry)
104107

105108
dehaloed = DeHalo_alpha(src, rx=rx, ry=ry, darkstr=darkstr, brightstr=brightstr)
106109
edges = core.std.Prewitt(src)
107110

108111
# Keeps only the sharpest edges (line edges)
109112
strong = edges.std.Expr(
110113
expr=[
111-
f"x {scale(thmi, peak)} - {thma - thmi} / 255 *"
114+
f"x {haf.scale(thmi, peak)} - {thma - thmi} / 255 *"
112115
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"
114117
]
115118
)
116119

117120
# 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)
119122

120123
### Exclusion zones ###
121124

@@ -125,24 +128,24 @@ def FineDehalo(
125128
# Includes more edges than previously, but ignores simple details
126129
light = edges.std.Expr(
127130
expr=[
128-
f"x {scale(thlimi, peak)} - {thlima - thlimi} / 255 *"
131+
f"x {haf.scale(thlimi, peak)} - {thlima - thlimi} / 255 *"
129132
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"
131134
]
132135
)
133136

134137
# To build the exclusion zone, we make grow the edge mask, then shrink it to its original shape
135138
# 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
136139

137140
# 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)
139142

140143
# 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
141144
# To avoid this, we amplify and saturate the mask here (actually we could even binarize it)
142145
shrink = shrink.std.Expr(expr=["x 4 *" if isInteger else "x 4 * 1 min"])
143146

144147
# 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)
146149

147150
# This mask is almost binary, which will produce distinct discontinuities once applied. Then we have to smooth it
148151
shrink = shrink.std.Convolution(matrix=[1, 1, 1, 1, 1, 1, 1, 1, 1]).std.Convolution(

mbfunc/havsfunc/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .havsfunc import * # noqa

0 commit comments

Comments
 (0)