diff --git a/vskernels/kernels/abstract.py b/vskernels/kernels/abstract.py index 0acd50a..09eb9c3 100644 --- a/vskernels/kernels/abstract.py +++ b/vskernels/kernels/abstract.py @@ -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( @@ -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): @@ -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): @@ -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): diff --git a/vskernels/kernels/resize.py b/vskernels/kernels/resize.py index f2c0018..b446b1b 100644 --- a/vskernels/kernels/resize.py +++ b/vskernels/kernels/resize.py @@ -18,10 +18,7 @@ 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): @@ -29,10 +26,7 @@ class Bilinear(ZimgComplexKernel): 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): diff --git a/vskernels/kernels/spline.py b/vskernels/kernels/spline.py index cf1e4cd..f768922 100644 --- a/vskernels/kernels/spline.py +++ b/vskernels/kernels/spline.py @@ -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 @@ -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): @@ -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): @@ -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