From 84051387c5f6dc97614c76a23d1c03e8448849b5 Mon Sep 17 00:00:00 2001 From: Setsugennoao <41454651+Setsugennoao@users.noreply.github.com> Date: Sun, 4 Aug 2024 12:08:44 +0200 Subject: [PATCH] Merge files --- vskernels/kernels/__init__.py | 2 - vskernels/kernels/ewa.py | 79 ----------------------------------- vskernels/kernels/placebo.py | 73 +++++++++++++++++++++++++++++++- vskernels/kernels/resize.py | 51 ---------------------- vskernels/kernels/various.py | 46 +++++++++++++++++--- 5 files changed, 113 insertions(+), 138 deletions(-) delete mode 100644 vskernels/kernels/ewa.py delete mode 100644 vskernels/kernels/resize.py diff --git a/vskernels/kernels/__init__.py b/vskernels/kernels/__init__.py index 71f5afd..a4f9325 100644 --- a/vskernels/kernels/__init__.py +++ b/vskernels/kernels/__init__.py @@ -2,8 +2,6 @@ from .bicubic import * # noqa: F401, F403 from .complex import * # noqa: F401, F403 from .custom import * # noqa: F401, F403 -from .ewa import * # noqa: F401, F403 from .placebo import * # noqa: F401, F403 -from .resize import * # noqa: F401, F403 from .spline import * # noqa: F401, F403 from .various import * # noqa: F401, F403 diff --git a/vskernels/kernels/ewa.py b/vskernels/kernels/ewa.py deleted file mode 100644 index beb2f6c..0000000 --- a/vskernels/kernels/ewa.py +++ /dev/null @@ -1,79 +0,0 @@ -from __future__ import annotations - -from typing import Any - -from .placebo import Placebo - -__all__ = [ - 'EwaBicubic', - 'EwaJinc', - 'EwaLanczos', - 'EwaGinseng', - 'EwaHann', - 'EwaHannSoft', - 'EwaRobidoux', - 'EwaRobidouxSharp', -] - - -class EwaBicubic(Placebo): - _kernel = 'ewa_robidoux' - - def __init__(self, b: float = 0.0, c: float = 0.5, radius: int | None = None, **kwargs: Any) -> None: - radius = kwargs.pop('taps', radius) - - if radius is None: - from .bicubic import Bicubic - - radius = Bicubic(b, c).kernel_radius - - super().__init__(radius, b, c, **kwargs) - - -class EwaLanczos(Placebo): - _kernel = 'ewa_lanczos' - - def __init__(self, taps: float = 3.2383154841662362076499, **kwargs: Any) -> None: - super().__init__(taps, None, None, **kwargs) - - -class EwaJinc(Placebo): - _kernel = 'ewa_jinc' - - def __init__(self, taps: float = 3.2383154841662362076499, **kwargs: Any) -> None: - super().__init__(taps, None, None, **kwargs) - - -class EwaGinseng(Placebo): - _kernel = 'ewa_ginseng' - - def __init__(self, taps: float = 3.2383154841662362076499, **kwargs: Any) -> None: - super().__init__(taps, None, None, **kwargs) - - -class EwaHann(Placebo): - _kernel = 'ewa_hann' - - def __init__(self, taps: float = 3.2383154841662362076499, **kwargs: Any) -> None: - super().__init__(taps, None, None, **kwargs) - - -class EwaHannSoft(Placebo): - _kernel = 'haasnsoft' - - def __init__(self, taps: float = 3.2383154841662362076499, **kwargs: Any) -> None: - super().__init__(taps, None, None, **kwargs) - - -class EwaRobidoux(Placebo): - _kernel = 'ewa_robidoux' - - def __init__(self, **kwargs: Any) -> None: - super().__init__(None, None, None, **kwargs) - - -class EwaRobidouxSharp(Placebo): - _kernel = 'ewa_robidouxsharp' - - def __init__(self, **kwargs: Any) -> None: - super().__init__(None, None, None, **kwargs) diff --git a/vskernels/kernels/placebo.py b/vskernels/kernels/placebo.py index 0dd24d3..5fc6978 100644 --- a/vskernels/kernels/placebo.py +++ b/vskernels/kernels/placebo.py @@ -10,7 +10,15 @@ from .complex import LinearScaler __all__ = [ - 'Placebo' + 'Placebo', + 'EwaBicubic', + 'EwaJinc', + 'EwaLanczos', + 'EwaGinseng', + 'EwaHann', + 'EwaHannSoft', + 'EwaRobidoux', + 'EwaRobidouxSharp', ] @@ -90,3 +98,66 @@ def kernel_radius(self) -> int: # type: ignore return Bicubic(fallback(self.b, 0), fallback(self.c, 0.5)).kernel_radius return 2 + + +class EwaBicubic(Placebo): + _kernel = 'ewa_robidoux' + + def __init__(self, b: float = 0.0, c: float = 0.5, radius: int | None = None, **kwargs: Any) -> None: + radius = kwargs.pop('taps', radius) + + if radius is None: + from .bicubic import Bicubic + + radius = Bicubic(b, c).kernel_radius + + super().__init__(radius, b, c, **kwargs) + + +class EwaLanczos(Placebo): + _kernel = 'ewa_lanczos' + + def __init__(self, taps: float = 3.2383154841662362076499, **kwargs: Any) -> None: + super().__init__(taps, None, None, **kwargs) + + +class EwaJinc(Placebo): + _kernel = 'ewa_jinc' + + def __init__(self, taps: float = 3.2383154841662362076499, **kwargs: Any) -> None: + super().__init__(taps, None, None, **kwargs) + + +class EwaGinseng(Placebo): + _kernel = 'ewa_ginseng' + + def __init__(self, taps: float = 3.2383154841662362076499, **kwargs: Any) -> None: + super().__init__(taps, None, None, **kwargs) + + +class EwaHann(Placebo): + _kernel = 'ewa_hann' + + def __init__(self, taps: float = 3.2383154841662362076499, **kwargs: Any) -> None: + super().__init__(taps, None, None, **kwargs) + + +class EwaHannSoft(Placebo): + _kernel = 'haasnsoft' + + def __init__(self, taps: float = 3.2383154841662362076499, **kwargs: Any) -> None: + super().__init__(taps, None, None, **kwargs) + + +class EwaRobidoux(Placebo): + _kernel = 'ewa_robidoux' + + def __init__(self, **kwargs: Any) -> None: + super().__init__(None, None, None, **kwargs) + + +class EwaRobidouxSharp(Placebo): + _kernel = 'ewa_robidouxsharp' + + def __init__(self, **kwargs: Any) -> None: + super().__init__(None, None, None, **kwargs) diff --git a/vskernels/kernels/resize.py b/vskernels/kernels/resize.py deleted file mode 100644 index 4f41cbe..0000000 --- a/vskernels/kernels/resize.py +++ /dev/null @@ -1,51 +0,0 @@ -from __future__ import annotations - -from typing import Any - -from vstools import inject_self - -from .helpers import sinc -from .complex import CustomComplexKernel, CustomComplexTapsKernel - -__all__ = [ - 'Point', - 'Bilinear', - 'Lanczos', -] - - -class Point(CustomComplexKernel): - """Built-in point resizer.""" - - _static_kernel_radius = 1 - - @inject_self - def kernel(self, *, x: float) -> float: # type: ignore - return 1.0 - - -class Bilinear(CustomComplexKernel): - """Built-in bilinear resizer.""" - - _static_kernel_radius = 1 - - @inject_self - def kernel(self, *, x: float) -> float: # type: ignore - return max(1.0 - abs(x), 0.0) - - -class Lanczos(CustomComplexTapsKernel): - """ - Lanczos resizer. - - :param taps: taps param for lanczos kernel - """ - - def __init__(self, taps: int = 3, **kwargs: Any) -> None: - super().__init__(taps, **kwargs) - - @inject_self - def kernel(self, *, x: float) -> float: # type: ignore - x, taps = abs(x), self.kernel_radius - - return sinc(x) * sinc(x / taps) if x < taps else 0.0 diff --git a/vskernels/kernels/various.py b/vskernels/kernels/various.py index a3ca2fb..fc861bb 100644 --- a/vskernels/kernels/various.py +++ b/vskernels/kernels/various.py @@ -9,6 +9,9 @@ from .helpers import sinc __all__ = [ + 'Point', + 'Bilinear', + 'Lanczos', 'Gaussian', 'Box', 'BlackMan', @@ -44,15 +47,48 @@ def to_libplacebo(self, sigma: float) -> float: return 4 * (sigma ** 2) +class Point(CustomComplexKernel): + """Point resizer.""" + + _static_kernel_radius = 1 + + @inject_self + def kernel(self, *, x: float) -> float: # type: ignore + return 1.0 + + +class Bilinear(CustomComplexKernel): + """Bilinear resizer.""" + + _static_kernel_radius = 1 + + @inject_self + def kernel(self, *, x: float) -> float: # type: ignore + return max(1.0 - abs(x), 0.0) + + +class Lanczos(CustomComplexTapsKernel): + """ + Lanczos resizer. + + :param taps: taps param for lanczos kernel + """ + + def __init__(self, taps: int = 3, **kwargs: Any) -> None: + super().__init__(taps, **kwargs) + + @inject_self + def kernel(self, *, x: float) -> float: # type: ignore + x, taps = abs(x), self.kernel_radius + + return sinc(x) * sinc(x / taps) if x < taps else 0.0 + + class Gaussian(CustomComplexTapsKernel): """Gaussian resizer.""" def __init__(self, sigma: float = 0.5, taps: int = 2, **kwargs: Any) -> None: - """ - Sigma is imagemagick's sigma scaling. - - You can specify "curve" to override sigma and specify the original `a1` value. - """ + """Sigma is the same as imagemagick's sigma scaling.""" self._sigma = sigma