Skip to content

Commit

Permalink
Use padder in vsdpir
Browse files Browse the repository at this point in the history
Fix #104
  • Loading branch information
Setsugennoao committed Jun 17, 2024
1 parent 0ead078 commit 26d2998
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions vsdenoise/deblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from typing import Any, Literal, SupportsFloat, cast

from vsexprtools import expr_func, norm_expr
from vskernels import Catrom, Kernel, KernelT, Point
from vskernels import Catrom, Kernel, KernelT
from vsmasktools import FDoG, GenericMaskT, adg_mask, normalize_mask
from vsrgtools import gauss_blur
from vstools import (
ColorRange, CustomStrEnum, DependencyNotFoundError, FrameRangeN, FrameRangesN, InvalidColorFamilyError,
KwargsT, LengthMismatchError, Matrix, MatrixT, UnsupportedVideoFormatError, check_variable, core, depth, fallback,
get_depth, get_nvidia_version, get_y, join, replace_ranges, vs
ColorRange, CustomStrEnum, DependencyNotFoundError, FrameRangeN, FrameRangesN, InvalidColorFamilyError, KwargsT,
LengthMismatchError, Matrix, MatrixT, UnsupportedVideoFormatError, check_variable, core, depth, fallback, get_depth,
get_nvidia_version, get_y, join, padder, replace_ranges, vs
)

__all__ = [
Expand Down Expand Up @@ -134,21 +134,13 @@ def _norm_str_clip(str_clip: vs.VideoNode) -> vs.VideoNode:
else:
overlap_w, overlap_h = overlap

multiple = 8
padding = padder.mod_padding((clip_rgb.width, clip_rgb.height), multiple := 8, 0)

mod_w, mod_h = clip_rgb.width % multiple, clip_rgb.height % multiple

if to_pad := any({mod_w, mod_h}):
d_width, d_height = clip_rgb.width + mod_w, clip_rgb.height + mod_h

clip_rgb = Point(src_width=d_width, src_height=d_height).scale(
clip_rgb, d_width, d_height, (-mod_h, -mod_w)
)
if (to_pad := any(padding)):
clip_rgb = padder.MIRROR(clip_rgb, *padding)

if isinstance(strength, vs.VideoNode):
strength = Point(src_width=d_width, src_height=d_height).scale(
strength, d_width, d_height, (-mod_h, -mod_w) # type: ignore
)
strength = padder.MIRROR(strength, *padding)

if isinstance(tiles, tuple):
tilesize = tiles
Expand Down Expand Up @@ -208,9 +200,7 @@ def _norm_str_clip(str_clip: vs.VideoNode) -> vs.VideoNode:
if len(dpir_zones) <= 2:
for rrange, sclip in dpir_zones.items():
if to_pad:
sclip = Point(src_width=d_width, src_height=d_height).scale(
sclip, d_width, d_height, (-mod_h, -mod_w)
)
sclip = padder.MIRROR(sclip, *padding)
zoned_strength_clip = replace_ranges(zoned_strength_clip, sclip, rrange)
else:
dpir_ranges_zones = {
Expand Down Expand Up @@ -298,7 +288,7 @@ def _select_sclip(n: int) -> vs.VideoNode:
run_dpir = replace_ranges(run_dpir, clip_rgb, no_dpir_zones)

if to_pad:
run_dpir = run_dpir.std.Crop(0, mod_w, mod_h, 0)
run_dpir = run_dpir.std.Crop(0, *padding)

if is_rgb or is_gray:
return depth(run_dpir, bit_depth)
Expand Down

0 comments on commit 26d2998

Please sign in to comment.