Skip to content

Commit

Permalink
Add _static_kernel_size for kernel with static sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
Setsugennoao committed Nov 11, 2023
1 parent 02a278d commit 3ef3cb6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
27 changes: 15 additions & 12 deletions vskernels/kernels/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@
]


def _default_kernel_size(cls, self) -> int:
if hasattr(self, '_static_kernel_size'):
return ceil(self._static_kernel_size)

try:
return super(cls, self).kernel_size
except AttributeError:
...

raise NotImplementedError


class BaseScaler:
@staticmethod
def from_param(
Expand Down Expand Up @@ -122,10 +134,7 @@ def multi(

@inject_self.property
def kernel_size(self) -> int:
try:
super().kernel_size
except AttributeError:
raise NotImplementedError
return _default_kernel_size(__class__, self)


class Descaler(vs_object):
Expand Down Expand Up @@ -174,10 +183,7 @@ def ensure_obj(

@inject_self.property
def kernel_size(self) -> int:
try:
super().kernel_size
except AttributeError:
raise NotImplementedError
return _default_kernel_size(__class__, self)


class Resampler(vs_object):
Expand All @@ -202,10 +208,7 @@ def ensure_obj(

@inject_self.property
def kernel_size(self) -> int:
try:
super().kernel_size
except AttributeError:
raise NotImplementedError
return _default_kernel_size(__class__, self)


class Kernel(Scaler, Descaler, Resampler):
Expand Down
10 changes: 2 additions & 8 deletions vskernels/kernels/resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,15 @@ class Point(ZimgComplexKernel):
"""Built-in point resizer."""

scale_function = resample_function = descale_function = core.lazy.resize.Point

@inject_self.property
def kernel_size(self) -> int:
return 1
_static_kernel_size = 1


class Bilinear(ZimgComplexKernel):
"""Built-in bilinear resizer."""

scale_function = resample_function = core.lazy.resize.Bilinear
descale_function = core.lazy.descale.Debilinear

@inject_self.property
def kernel_size(self) -> int:
return 1
_static_kernel_size = 1


class Lanczos(ZimgComplexKernel):
Expand Down
17 changes: 4 additions & 13 deletions vskernels/kernels/spline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import Any

from vstools import core, inject_self
from vstools import core

from .fmtconv import FmtConv
from .zimg import ZimgComplexKernel
Expand Down Expand Up @@ -35,10 +35,7 @@ class Spline16(ZimgComplexKernel):

scale_function = resample_function = core.lazy.resize.Spline16
descale_function = core.lazy.descale.Despline16

@inject_self.property
def kernel_size(self) -> int:
return 2
_static_kernel_size = 2


class Spline36(ZimgComplexKernel):
Expand All @@ -52,10 +49,7 @@ class Spline36(ZimgComplexKernel):

scale_function = resample_function = core.lazy.resize.Spline36
descale_function = core.lazy.descale.Despline36

@inject_self.property
def kernel_size(self) -> int:
return 3
_static_kernel_size = 3


class Spline64(ZimgComplexKernel):
Expand All @@ -69,7 +63,4 @@ class Spline64(ZimgComplexKernel):

scale_function = resample_function = core.lazy.resize.Spline64
descale_function = core.lazy.descale.Despline64

@inject_self.property
def kernel_size(self) -> int:
return 4
_static_kernel_size = 4

0 comments on commit 3ef3cb6

Please sign in to comment.