From ad1cb82bdc922d7eedf4382a71a862a6b7dc5524 Mon Sep 17 00:00:00 2001 From: LightArrowsEXE Date: Mon, 30 Sep 2024 22:46:58 +0200 Subject: [PATCH] Eedi3: Allow VideoNode to be passed to sclip_aa #32 --- vsaa/antialiasers/eedi3.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/vsaa/antialiasers/eedi3.py b/vsaa/antialiasers/eedi3.py index 2120eab..2535639 100644 --- a/vsaa/antialiasers/eedi3.py +++ b/vsaa/antialiasers/eedi3.py @@ -34,17 +34,17 @@ class EEDI3(_Antialiaser): opencl: bool = dc_field(default=False, kw_only=True) mclip: vs.VideoNode | None = None - sclip_aa: type[Antialiaser] | Antialiaser | Literal[True] | None = dc_field( + sclip_aa: type[Antialiaser] | Antialiaser | Literal[True] | vs.VideoNode | None = dc_field( default_factory=lambda: nnedi3.Nnedi3 ) def __post_init__(self) -> None: super().__post_init__() - self._sclip_aa: Antialiaser | Literal[True] | None + self._sclip_aa: Antialiaser | Literal[True] | vs.VideoNode | None - if self.sclip_aa and self.sclip_aa is not True and not isinstance(self.sclip_aa, Antialiaser): - self._sclip_aa = self.sclip_aa() + if self.sclip_aa and self.sclip_aa is not True and not isinstance(self.sclip_aa, (Antialiaser, vs.VideoNode)): + self._sclip_aa = self.sclip_aa() # type: ignore[operator] else: self._sclip_aa = self.sclip_aa # type: ignore[assignment] @@ -69,9 +69,22 @@ def interpolate(self, clip: vs.VideoNode, double_y: bool, **kwargs: Any) -> vs.V aa_kwargs = self.get_aa_args(clip, **kwargs) if self._sclip_aa and ((('sclip' in kwargs) and not kwargs['sclip']) or 'sclip' not in kwargs): - if self._sclip_aa is True: + if self._sclip_aa is True or isinstance(self._sclip_aa, vs.VideoNode): if double_y: - raise CustomValueError("You can't pass sclip_aa=True when supersampling!", self.__class__) + if self._sclip_aa is True: + raise CustomValueError("You can't pass sclip_aa=True when supersampling!", self.__class__) + + expected_dimensions = (clip.width * 2, clip.height * 2) + actual_dimensions = (clip.width, clip.height) + + if expected_dimensions != actual_dimensions: + raise CustomValueError( + f"The dimensions of sclip_aa ({actual_dimensions[0]}x{actual_dimensions[1]}) " + f"don't match the expected dimensions for supersampling " + f"({expected_dimensions[0]}x{expected_dimensions[1]})!", + self.__class__ + ) + aa_kwargs.update(sclip=clip) else: sclip_args = self._sclip_aa.get_aa_args(clip, **(dict(mclip=kwargs.get('mclip', None))))