diff --git a/vsrgtools/blur.py b/vsrgtools/blur.py index 08866e7..461a8a0 100644 --- a/vsrgtools/blur.py +++ b/vsrgtools/blur.py @@ -71,28 +71,33 @@ def box_blur( if not radius: return clip - fp16 = clip.format.sample_type == vs.FLOAT and clip.format.bits_per_sample == 16 + box_args = ( + planes, + radius, 0 if mode == ConvMode.VERTICAL else passes, + radius, 0 if mode == ConvMode.HORIZONTAL else passes + ) - if radius > 12 and not fp16: - blurred = clip.std.BoxBlur( - planes, - radius, 0 if mode == ConvMode.VERTICAL else passes, - radius, 0 if mode == ConvMode.HORIZONTAL else passes - ) + if hasattr(core, 'vszip'): + blurred = clip.vszip.BoxBlur(*box_args) else: - matrix_size = radius * 2 | 1 + fp16 = clip.format.sample_type == vs.FLOAT and clip.format.bits_per_sample == 16 - if fp16: - matrix_size **= 2 + if radius > 12 and not fp16: + blurred = clip.std.BoxBlur(*box_args) + else: + matrix_size = radius * 2 | 1 - blurred = clip - for _ in range(passes): if fp16: - blurred = norm_expr(blurred, [ - ExprOp.matrix('x', radius, mode=mode), ExprOp.ADD * (matrix_size - 1), matrix_size, ExprOp.DIV - ], planes) - else: - blurred = blurred.std.Convolution([1] * matrix_size, planes=planes, mode=mode) + matrix_size **= 2 + + blurred = clip + for _ in range(passes): + if fp16: + blurred = norm_expr(blurred, [ + ExprOp.matrix('x', radius, mode=mode), ExprOp.ADD * (matrix_size - 1), matrix_size, ExprOp.DIV + ], planes) + else: + blurred = blurred.std.Convolution([1] * matrix_size, planes=planes, mode=mode) return blurred @@ -110,7 +115,7 @@ def side_box_blur( conv_m1 = partial(core.std.Convolution, matrix=half_kernel, planes=planes) conv_m2 = partial(core.std.Convolution, matrix=half_kernel[::-1], planes=planes) - blur_pt = partial(core.std.BoxBlur, planes=planes) + blur_pt = partial(box_blur, planes=planes) vrt_filters, hrz_filters = [ [ @@ -395,6 +400,9 @@ def bilateral( if ref and clip.format != ref.format: ref = depth(ref, clip) - clip = clip.bilateral.Bilateral(ref, sigmaS, sigmaR) + if hasattr(core, 'vszip'): + clip = clip.vszip.Bilateral(ref, sigmaS, sigmaR) + else: + clip = clip.bilateral.Bilateral(ref, sigmaS, sigmaR) return depth(clip, bits)