Skip to content

Commit

Permalink
Add utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Setsugennoao committed Jul 9, 2024
1 parent 79f9452 commit 7200f55
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
47 changes: 47 additions & 0 deletions vskernels/kernels/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from math import floor, pi, sin

__all__ = [
'sinc', 'poly3', 'round_halfup', 'bic_vals'
]


class bic_vals:
@staticmethod
def p0(b: float, c: float) -> float:
return (6.0 - 2.0 * b) / 6.0

@staticmethod
def p2(b: float, c: float) -> float:
return (-18.0 + 12.0 * b + 6.0 * c) / 6.0

@staticmethod
def p3(b: float, c: float) -> float:
return (12.0 - 9.0 * b - 6.0 * c) / 6.0

@staticmethod
def q0(b: float, c: float) -> float:
return (8.0 * b + 24.0 * c) / 6.0

@staticmethod
def q1(b: float, c: float) -> float:
return (-12.0 * b - 48.0 * c) / 6.0

@staticmethod
def q2(b: float, c: float) -> float:
return (6.0 * b + 30.0 * c) / 6.0

@staticmethod
def q3(b: float, c: float) -> float:
return (-b - 6.0 * c) / 6.0


def sinc(x: float) -> float:
return 1.0 if x == 0.0 else sin(x * pi) / (x * pi)


def poly3(x: float, c0: float, c1: float, c2: float, c3: float) -> float:
return c0 + x * (c1 + x * (c2 + x * c3))


def round_halfup(x: float) -> float:
return floor(x + 0.5) if x < 0 else floor(x + 0.49999999999999994)
9 changes: 4 additions & 5 deletions vskernels/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
)

from .kernels import (
Bicubic, BicubicAuto, Catrom, ComplexKernel, Descaler, FmtConv, Impulse, Kernel, KernelT, LinearDescaler, Placebo,
Point, Resampler, ResamplerT, Scaler, ZimgComplexKernel, ZimgDescaler
Bicubic, BicubicAuto, Catrom, ComplexKernel, CustomComplexKernel, Descaler, Kernel, KernelT, LinearDescaler,
Placebo, Point, Resampler, ResamplerT, Scaler
)
from .types import Center, LeftShift, Slope, TopShift

Expand Down Expand Up @@ -88,7 +88,7 @@ def scale( # type: ignore
self, clip: vs.VideoNode, width: int, height: int, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
try:
return super().scale(clip, clip.width, clip.height, shift, **kwargs) # type: ignore
return super().scale(clip, clip.width, clip.height, shift, **kwargs)
except Exception:
return clip

Expand All @@ -108,8 +108,7 @@ class inner_no_scale(kernel_t, NoScaleBase): # type: ignore


abstract_kernels = list[type[Scaler | Descaler | Resampler | Kernel]]([
Kernel, FmtConv, Impulse, Placebo, ComplexKernel,
ZimgDescaler, ZimgComplexKernel, LinearDescaler
Kernel, Placebo, ComplexKernel, CustomComplexKernel, LinearDescaler
])


Expand Down

0 comments on commit 7200f55

Please sign in to comment.