Skip to content

various

Classes:

BlackMan

BlackMan(taps: float = 4, **kwargs: Any)

Bases: CustomComplexTapsKernel

Blackman resizer.

Methods:

Attributes:

  • kwargs (KwargsT) –

    Arguments passed to the internal scale function

  • taps
Source code
79
80
def __init__(self, taps: float = 4, **kwargs: Any) -> None:
    super().__init__(taps, **kwargs)

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

taps instance-attribute

taps = taps

descale

descale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: ShiftT = (0, 0),
    *,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    field_based: FieldBased | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    blur: float = 1.0,
    ignore_mask: VideoNode | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
@inject_self.cached
@inject_kwargs_params
def descale(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: ShiftT = (0, 0),
    *,
    # `border_handling`, `sample_grid_model` and `field_based` from Descaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    field_based: FieldBased | None = None,
    # `linear` and `sigmoid` parameters from LinearDescaler
    linear: bool = False, sigmoid: bool | tuple[Slope, Center] = False,
    # `blur` and `ignore_mask` from CustomKernel
    blur: float = 1.0, ignore_mask: vs.VideoNode | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode
Source code
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def descale_function(
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode:
    kernel, support = self._modify_kernel_func(kwargs)

    clean_kwargs = {
        k: v for k, v in kwargs.items()
        if k not in Signature.from_callable(self._modify_kernel_func).parameters.keys()
    }

    try:
        return core.descale.Decustom(clip, width, height, kernel, ceil(support), *args, **clean_kwargs)
    except vs.Error as e:
        if 'Output dimension must be' in str(e):
            raise CustomValueError(
                f'Output dimension ({width}x{height}) must be less than or equal to '
                f'input dimension ({clip.width}x{clip.height}).', self.__class__
            )

        raise CustomValueError(e, self.__class__)

ensure_obj classmethod

ensure_obj(
    kernel: KernelT | None = ..., /, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: str | type[BaseScaler] | BaseScaler | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> BaseScaler
Source code
647
648
649
650
651
652
653
654
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: str | type[BaseScaler] | BaseScaler | None = None, /,
    func_except: FuncExceptT | None = None
) -> BaseScaler:
    return _base_ensure_obj(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = ..., /, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: str | type[BaseScaler] | BaseScaler | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> type[BaseScaler]
Source code
611
612
613
614
615
616
617
@classmethod
def from_param(
    cls, kernel: str | type[BaseScaler] | BaseScaler | None = None, /, func_except: FuncExceptT | None = None
) -> type[BaseScaler]:
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
216
217
def get_clean_kwargs(self, *funcs: Callable[..., Any] | None) -> KwargsT:
    return _clean_self_kwargs(funcs, self)

get_descale_args

get_descale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
673
674
675
676
677
678
679
680
681
682
683
@inject_kwargs_params
def get_descale_args(
    self, clip: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None, height: int | None = None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(src_top=shift[0], src_left=shift[1])
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(True, clip, width, height, **kwargs)
    )

get_implemented_funcs

get_implemented_funcs() -> tuple[Callable[..., Any], ...]
Source code
701
702
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )

get_params_args

get_params_args(
    is_descale: bool,
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]
Source code
85
86
87
88
89
90
91
92
93
94
def get_params_args(
    self, is_descale: bool, clip: vs.VideoNode, width: int | None = None, height: int | None = None, **kwargs: Any
) -> dict[str, Any]:
    args = super().get_params_args(is_descale, clip, width, height, **kwargs)

    if not is_descale:
        for key in ('border_handling', 'ignore_mask'):
            args.pop(key, None)

    return args

get_resample_args

get_resample_args(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None,
    matrix_in: MatrixT | None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
@inject_kwargs_params
def get_resample_args(
    self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None, matrix_in: MatrixT | None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(
            format=get_video_format(format).id,
            matrix=Matrix.from_param(matrix),
            matrix_in=Matrix.from_param(matrix_in)
        )
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(False, clip, **kwargs)
    )

get_scale_args

get_scale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
661
662
663
664
665
666
667
668
669
670
671
@inject_kwargs_params
def get_scale_args(
    self, clip: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None, height: int | None = None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(src_top=shift[0], src_left=shift[1])
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(False, clip, width, height, **kwargs)
    )

kernel

kernel(*, x: float) -> float
Source code
87
88
89
90
91
92
@inject_self.cached
def kernel(self, *, x: float) -> float:
    if x >= self.kernel_radius:
        return 0.0

    return sinc(x) * self._win_coef(x)

kernel_radius

kernel_radius() -> int
Source code
287
288
289
@inject_self.cached.property
def kernel_radius(self) -> int:
    return ceil(self.taps)

multi

multi(
    clip: VideoNode,
    multi: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
272
273
274
275
276
277
278
279
280
281
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:

    import warnings

    warnings.warn('The "multi" method is deprecated. Use "supersample" instead.', DeprecationWarning)

    return self.supersample(clip, multi, shift, **kwargs)

pretty_string

pretty_string() -> str
Source code
225
226
227
@inject_self.cached.property
def pretty_string(self) -> str:
    return self._pretty_string()

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
438
439
440
441
442
443
444
445
446
@inject_self.cached
@inject_kwargs_params
def resample(
    self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None, matrix_in: MatrixT | None = None, **kwargs: Any
) -> ConstantFormatVideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

resample_function

resample_function(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    *args: Any,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
59
60
61
62
def resample_function(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode:
    return self.scale_function(clip, width, height, *args, **kwargs)  # type: ignore[return-value]

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
@inject_self.cached
@inject_kwargs_params
def scale(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    # `border_handling`, `sample_grid_model`, `sar`, `dar`, `dar_in` and `keep_ar` from KeepArScaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | float | bool | None = None, dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None, keep_ar: bool | None = None,
    # `linear` and `sigmoid` from LinearScaler
    linear: bool = False, sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> vs.VideoNode:
    width, height = Scaler._wh_norm(clip, width, height)
    return super().scale(
        clip, width, height, shift,
        border_handling=border_handling, sample_grid_model=sample_grid_model,
        sar=sar, dar=dar, dar_in=dar_in, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid,
        **kwargs
    )

scale_function

scale_function(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    *args: Any,
    **kwargs: Any
) -> VideoNode
Source code
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def scale_function(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None, *args: Any, **kwargs: Any
) -> vs.VideoNode:

    if not hasattr(core, 'resize2'):
        raise DependencyNotFoundError(
            self.__class__, 'resize2', 'Missing dependency \'resize2\'! '
            'You can find it here: https://github.com/Jaded-Encoding-Thaumaturgy/vapoursynth-resize2'
        )

    kernel, support = self._modify_kernel_func(kwargs)

    clean_kwargs = {
        k: v for k, v in kwargs.items()
        if k not in Signature.from_callable(self._modify_kernel_func).parameters.keys()
    }

    return core.resize2.Custom(clip, kernel, ceil(support), width, height, *args, **clean_kwargs)

shift

shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any,
) -> ConstantFormatVideoNode
Source code
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
@inject_self.cached
@inject_kwargs_params
def shift(
    self,
    clip: vs.VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any
) -> ConstantFormatVideoNode:
    assert check_variable_format(clip, self.shift)

    n_planes = clip.format.num_planes

    def _shift(src: VideoNodeT, shift: tuple[TopShift, LeftShift] = (0, 0)) -> VideoNodeT:
        return self.scale(src, src.width, src.height, shift, **kwargs)

    if not shifts_or_top and not shift_left:
        return _shift(clip)

    if isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)

    if isinstance(shifts_or_top, float) and isinstance(shift_left, float):
        return _shift(clip, (shifts_or_top, shift_left))

    if shifts_or_top is None:
        shifts_or_top = 0.0
    if shift_left is None:
        shift_left = 0.0

    shifts_top = shifts_or_top if isinstance(shifts_or_top, list) else [shifts_or_top]
    shifts_left = shift_left if isinstance(shift_left, list) else [shift_left]

    if not shifts_top:
        shifts_top = [0.0] * n_planes
    elif (ltop := len(shifts_top)) > n_planes:
        shifts_top = shifts_top[:n_planes]
    else:
        shifts_top += shifts_top[-1:] * (n_planes - ltop)

    if not shifts_left:
        shifts_left = [0.0] * n_planes
    elif (lleft := len(shifts_left)) > n_planes:
        shifts_left = shifts_left[:n_planes]
    else:
        shifts_left += shifts_left[-1:] * (n_planes - lleft)

    if len(set(shifts_top)) == len(set(shifts_left)) == 1 or n_planes == 1:
        return _shift(clip, (shifts_top[0], shifts_left[0]))

    planes = split(clip)

    shifted_planes = [
        plane if top == left == 0 else _shift(plane, (top, left))
        for plane, top, left in zip(planes, shifts_top, shifts_left)
    ]

    return core.std.ShufflePlanes(shifted_planes, [0, 0, 0], clip.format.color_family)

supersample

supersample(
    clip: VideoNode,
    rfactor: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
257
258
259
260
261
262
263
264
265
266
267
268
269
270
@inject_self.cached
def supersample(
    self, clip: vs.VideoNode, rfactor: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

    dst_width, dst_height = ceil(clip.width * rfactor), ceil(clip.height * rfactor)

    if max(dst_width, dst_height) <= 0.0:
        raise CustomValueError(
            'Multiplying the resolution by "rfactor" must result in a positive resolution!', self.supersample, rfactor
        )

    return self.scale(clip, dst_width, dst_height, shift, **kwargs)

BlackManMinLobe

BlackManMinLobe(taps: float = 4, **kwargs: Any)

Bases: BlackMan

Blackmanminlobe resizer.

Methods:

Attributes:

  • kwargs (KwargsT) –

    Arguments passed to the internal scale function

  • taps
Source code
79
80
def __init__(self, taps: float = 4, **kwargs: Any) -> None:
    super().__init__(taps, **kwargs)

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

taps instance-attribute

taps = taps

descale

descale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: ShiftT = (0, 0),
    *,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    field_based: FieldBased | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    blur: float = 1.0,
    ignore_mask: VideoNode | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
@inject_self.cached
@inject_kwargs_params
def descale(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: ShiftT = (0, 0),
    *,
    # `border_handling`, `sample_grid_model` and `field_based` from Descaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    field_based: FieldBased | None = None,
    # `linear` and `sigmoid` parameters from LinearDescaler
    linear: bool = False, sigmoid: bool | tuple[Slope, Center] = False,
    # `blur` and `ignore_mask` from CustomKernel
    blur: float = 1.0, ignore_mask: vs.VideoNode | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode
Source code
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def descale_function(
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode:
    kernel, support = self._modify_kernel_func(kwargs)

    clean_kwargs = {
        k: v for k, v in kwargs.items()
        if k not in Signature.from_callable(self._modify_kernel_func).parameters.keys()
    }

    try:
        return core.descale.Decustom(clip, width, height, kernel, ceil(support), *args, **clean_kwargs)
    except vs.Error as e:
        if 'Output dimension must be' in str(e):
            raise CustomValueError(
                f'Output dimension ({width}x{height}) must be less than or equal to '
                f'input dimension ({clip.width}x{clip.height}).', self.__class__
            )

        raise CustomValueError(e, self.__class__)

ensure_obj classmethod

ensure_obj(
    kernel: KernelT | None = ..., /, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: str | type[BaseScaler] | BaseScaler | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> BaseScaler
Source code
647
648
649
650
651
652
653
654
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: str | type[BaseScaler] | BaseScaler | None = None, /,
    func_except: FuncExceptT | None = None
) -> BaseScaler:
    return _base_ensure_obj(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = ..., /, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: str | type[BaseScaler] | BaseScaler | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> type[BaseScaler]
Source code
611
612
613
614
615
616
617
@classmethod
def from_param(
    cls, kernel: str | type[BaseScaler] | BaseScaler | None = None, /, func_except: FuncExceptT | None = None
) -> type[BaseScaler]:
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
216
217
def get_clean_kwargs(self, *funcs: Callable[..., Any] | None) -> KwargsT:
    return _clean_self_kwargs(funcs, self)

get_descale_args

get_descale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
673
674
675
676
677
678
679
680
681
682
683
@inject_kwargs_params
def get_descale_args(
    self, clip: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None, height: int | None = None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(src_top=shift[0], src_left=shift[1])
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(True, clip, width, height, **kwargs)
    )

get_implemented_funcs

get_implemented_funcs() -> tuple[Callable[..., Any], ...]
Source code
701
702
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )

get_params_args

get_params_args(
    is_descale: bool,
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]
Source code
85
86
87
88
89
90
91
92
93
94
def get_params_args(
    self, is_descale: bool, clip: vs.VideoNode, width: int | None = None, height: int | None = None, **kwargs: Any
) -> dict[str, Any]:
    args = super().get_params_args(is_descale, clip, width, height, **kwargs)

    if not is_descale:
        for key in ('border_handling', 'ignore_mask'):
            args.pop(key, None)

    return args

get_resample_args

get_resample_args(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None,
    matrix_in: MatrixT | None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
@inject_kwargs_params
def get_resample_args(
    self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None, matrix_in: MatrixT | None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(
            format=get_video_format(format).id,
            matrix=Matrix.from_param(matrix),
            matrix_in=Matrix.from_param(matrix_in)
        )
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(False, clip, **kwargs)
    )

get_scale_args

get_scale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
661
662
663
664
665
666
667
668
669
670
671
@inject_kwargs_params
def get_scale_args(
    self, clip: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None, height: int | None = None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(src_top=shift[0], src_left=shift[1])
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(False, clip, width, height, **kwargs)
    )

kernel

kernel(*, x: float) -> float
Source code
87
88
89
90
91
92
@inject_self.cached
def kernel(self, *, x: float) -> float:
    if x >= self.kernel_radius:
        return 0.0

    return sinc(x) * self._win_coef(x)

kernel_radius

kernel_radius() -> int
Source code
287
288
289
@inject_self.cached.property
def kernel_radius(self) -> int:
    return ceil(self.taps)

multi

multi(
    clip: VideoNode,
    multi: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
272
273
274
275
276
277
278
279
280
281
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:

    import warnings

    warnings.warn('The "multi" method is deprecated. Use "supersample" instead.', DeprecationWarning)

    return self.supersample(clip, multi, shift, **kwargs)

pretty_string

pretty_string() -> str
Source code
225
226
227
@inject_self.cached.property
def pretty_string(self) -> str:
    return self._pretty_string()

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
438
439
440
441
442
443
444
445
446
@inject_self.cached
@inject_kwargs_params
def resample(
    self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None, matrix_in: MatrixT | None = None, **kwargs: Any
) -> ConstantFormatVideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

resample_function

resample_function(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    *args: Any,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
59
60
61
62
def resample_function(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode:
    return self.scale_function(clip, width, height, *args, **kwargs)  # type: ignore[return-value]

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
@inject_self.cached
@inject_kwargs_params
def scale(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    # `border_handling`, `sample_grid_model`, `sar`, `dar`, `dar_in` and `keep_ar` from KeepArScaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | float | bool | None = None, dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None, keep_ar: bool | None = None,
    # `linear` and `sigmoid` from LinearScaler
    linear: bool = False, sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> vs.VideoNode:
    width, height = Scaler._wh_norm(clip, width, height)
    return super().scale(
        clip, width, height, shift,
        border_handling=border_handling, sample_grid_model=sample_grid_model,
        sar=sar, dar=dar, dar_in=dar_in, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid,
        **kwargs
    )

scale_function

scale_function(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    *args: Any,
    **kwargs: Any
) -> VideoNode
Source code
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def scale_function(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None, *args: Any, **kwargs: Any
) -> vs.VideoNode:

    if not hasattr(core, 'resize2'):
        raise DependencyNotFoundError(
            self.__class__, 'resize2', 'Missing dependency \'resize2\'! '
            'You can find it here: https://github.com/Jaded-Encoding-Thaumaturgy/vapoursynth-resize2'
        )

    kernel, support = self._modify_kernel_func(kwargs)

    clean_kwargs = {
        k: v for k, v in kwargs.items()
        if k not in Signature.from_callable(self._modify_kernel_func).parameters.keys()
    }

    return core.resize2.Custom(clip, kernel, ceil(support), width, height, *args, **clean_kwargs)

shift

shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any,
) -> ConstantFormatVideoNode
Source code
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
@inject_self.cached
@inject_kwargs_params
def shift(
    self,
    clip: vs.VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any
) -> ConstantFormatVideoNode:
    assert check_variable_format(clip, self.shift)

    n_planes = clip.format.num_planes

    def _shift(src: VideoNodeT, shift: tuple[TopShift, LeftShift] = (0, 0)) -> VideoNodeT:
        return self.scale(src, src.width, src.height, shift, **kwargs)

    if not shifts_or_top and not shift_left:
        return _shift(clip)

    if isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)

    if isinstance(shifts_or_top, float) and isinstance(shift_left, float):
        return _shift(clip, (shifts_or_top, shift_left))

    if shifts_or_top is None:
        shifts_or_top = 0.0
    if shift_left is None:
        shift_left = 0.0

    shifts_top = shifts_or_top if isinstance(shifts_or_top, list) else [shifts_or_top]
    shifts_left = shift_left if isinstance(shift_left, list) else [shift_left]

    if not shifts_top:
        shifts_top = [0.0] * n_planes
    elif (ltop := len(shifts_top)) > n_planes:
        shifts_top = shifts_top[:n_planes]
    else:
        shifts_top += shifts_top[-1:] * (n_planes - ltop)

    if not shifts_left:
        shifts_left = [0.0] * n_planes
    elif (lleft := len(shifts_left)) > n_planes:
        shifts_left = shifts_left[:n_planes]
    else:
        shifts_left += shifts_left[-1:] * (n_planes - lleft)

    if len(set(shifts_top)) == len(set(shifts_left)) == 1 or n_planes == 1:
        return _shift(clip, (shifts_top[0], shifts_left[0]))

    planes = split(clip)

    shifted_planes = [
        plane if top == left == 0 else _shift(plane, (top, left))
        for plane, top, left in zip(planes, shifts_top, shifts_left)
    ]

    return core.std.ShufflePlanes(shifted_planes, [0, 0, 0], clip.format.color_family)

supersample

supersample(
    clip: VideoNode,
    rfactor: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
257
258
259
260
261
262
263
264
265
266
267
268
269
270
@inject_self.cached
def supersample(
    self, clip: vs.VideoNode, rfactor: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

    dst_width, dst_height = ceil(clip.width * rfactor), ceil(clip.height * rfactor)

    if max(dst_width, dst_height) <= 0.0:
        raise CustomValueError(
            'Multiplying the resolution by "rfactor" must result in a positive resolution!', self.supersample, rfactor
        )

    return self.scale(clip, dst_width, dst_height, shift, **kwargs)

Bohman

Bohman(taps: float, **kwargs: Any)

Bases: CustomComplexTapsKernel

Bohman kernel.

Methods:

Attributes:

  • kwargs (KwargsT) –

    Arguments passed to the internal scale function

  • taps
Source code
283
284
285
def __init__(self, taps: float, **kwargs: Any) -> None:
    self.taps = taps
    super().__init__(**kwargs)

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

taps instance-attribute

taps = taps

descale

descale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: ShiftT = (0, 0),
    *,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    field_based: FieldBased | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    blur: float = 1.0,
    ignore_mask: VideoNode | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
@inject_self.cached
@inject_kwargs_params
def descale(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: ShiftT = (0, 0),
    *,
    # `border_handling`, `sample_grid_model` and `field_based` from Descaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    field_based: FieldBased | None = None,
    # `linear` and `sigmoid` parameters from LinearDescaler
    linear: bool = False, sigmoid: bool | tuple[Slope, Center] = False,
    # `blur` and `ignore_mask` from CustomKernel
    blur: float = 1.0, ignore_mask: vs.VideoNode | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode
Source code
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def descale_function(
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode:
    kernel, support = self._modify_kernel_func(kwargs)

    clean_kwargs = {
        k: v for k, v in kwargs.items()
        if k not in Signature.from_callable(self._modify_kernel_func).parameters.keys()
    }

    try:
        return core.descale.Decustom(clip, width, height, kernel, ceil(support), *args, **clean_kwargs)
    except vs.Error as e:
        if 'Output dimension must be' in str(e):
            raise CustomValueError(
                f'Output dimension ({width}x{height}) must be less than or equal to '
                f'input dimension ({clip.width}x{clip.height}).', self.__class__
            )

        raise CustomValueError(e, self.__class__)

ensure_obj classmethod

ensure_obj(
    kernel: KernelT | None = ..., /, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: str | type[BaseScaler] | BaseScaler | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> BaseScaler
Source code
647
648
649
650
651
652
653
654
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: str | type[BaseScaler] | BaseScaler | None = None, /,
    func_except: FuncExceptT | None = None
) -> BaseScaler:
    return _base_ensure_obj(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = ..., /, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: str | type[BaseScaler] | BaseScaler | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> type[BaseScaler]
Source code
611
612
613
614
615
616
617
@classmethod
def from_param(
    cls, kernel: str | type[BaseScaler] | BaseScaler | None = None, /, func_except: FuncExceptT | None = None
) -> type[BaseScaler]:
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
216
217
def get_clean_kwargs(self, *funcs: Callable[..., Any] | None) -> KwargsT:
    return _clean_self_kwargs(funcs, self)

get_descale_args

get_descale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
673
674
675
676
677
678
679
680
681
682
683
@inject_kwargs_params
def get_descale_args(
    self, clip: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None, height: int | None = None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(src_top=shift[0], src_left=shift[1])
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(True, clip, width, height, **kwargs)
    )

get_implemented_funcs

get_implemented_funcs() -> tuple[Callable[..., Any], ...]
Source code
701
702
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )

get_params_args

get_params_args(
    is_descale: bool,
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]
Source code
85
86
87
88
89
90
91
92
93
94
def get_params_args(
    self, is_descale: bool, clip: vs.VideoNode, width: int | None = None, height: int | None = None, **kwargs: Any
) -> dict[str, Any]:
    args = super().get_params_args(is_descale, clip, width, height, **kwargs)

    if not is_descale:
        for key in ('border_handling', 'ignore_mask'):
            args.pop(key, None)

    return args

get_resample_args

get_resample_args(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None,
    matrix_in: MatrixT | None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
@inject_kwargs_params
def get_resample_args(
    self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None, matrix_in: MatrixT | None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(
            format=get_video_format(format).id,
            matrix=Matrix.from_param(matrix),
            matrix_in=Matrix.from_param(matrix_in)
        )
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(False, clip, **kwargs)
    )

get_scale_args

get_scale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
661
662
663
664
665
666
667
668
669
670
671
@inject_kwargs_params
def get_scale_args(
    self, clip: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None, height: int | None = None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(src_top=shift[0], src_left=shift[1])
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(False, clip, width, height, **kwargs)
    )

kernel

kernel(*, x: float) -> float
Source code
167
168
169
170
171
172
173
174
175
@inject_self.cached
def kernel(self, *, x: float) -> float:
    if x >= self.kernel_radius:
        return 0.0

    cosine = cos(pi * x)
    sine = sqrt(1.0 - cosine * cosine)

    return (1.0 - x) * cosine + (1.0 / pi) * sine

kernel_radius

kernel_radius() -> int
Source code
287
288
289
@inject_self.cached.property
def kernel_radius(self) -> int:
    return ceil(self.taps)

multi

multi(
    clip: VideoNode,
    multi: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
272
273
274
275
276
277
278
279
280
281
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:

    import warnings

    warnings.warn('The "multi" method is deprecated. Use "supersample" instead.', DeprecationWarning)

    return self.supersample(clip, multi, shift, **kwargs)

pretty_string

pretty_string() -> str
Source code
225
226
227
@inject_self.cached.property
def pretty_string(self) -> str:
    return self._pretty_string()

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
438
439
440
441
442
443
444
445
446
@inject_self.cached
@inject_kwargs_params
def resample(
    self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None, matrix_in: MatrixT | None = None, **kwargs: Any
) -> ConstantFormatVideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

resample_function

resample_function(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    *args: Any,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
59
60
61
62
def resample_function(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode:
    return self.scale_function(clip, width, height, *args, **kwargs)  # type: ignore[return-value]

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
@inject_self.cached
@inject_kwargs_params
def scale(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    # `border_handling`, `sample_grid_model`, `sar`, `dar`, `dar_in` and `keep_ar` from KeepArScaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | float | bool | None = None, dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None, keep_ar: bool | None = None,
    # `linear` and `sigmoid` from LinearScaler
    linear: bool = False, sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> vs.VideoNode:
    width, height = Scaler._wh_norm(clip, width, height)
    return super().scale(
        clip, width, height, shift,
        border_handling=border_handling, sample_grid_model=sample_grid_model,
        sar=sar, dar=dar, dar_in=dar_in, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid,
        **kwargs
    )

scale_function

scale_function(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    *args: Any,
    **kwargs: Any
) -> VideoNode
Source code
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def scale_function(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None, *args: Any, **kwargs: Any
) -> vs.VideoNode:

    if not hasattr(core, 'resize2'):
        raise DependencyNotFoundError(
            self.__class__, 'resize2', 'Missing dependency \'resize2\'! '
            'You can find it here: https://github.com/Jaded-Encoding-Thaumaturgy/vapoursynth-resize2'
        )

    kernel, support = self._modify_kernel_func(kwargs)

    clean_kwargs = {
        k: v for k, v in kwargs.items()
        if k not in Signature.from_callable(self._modify_kernel_func).parameters.keys()
    }

    return core.resize2.Custom(clip, kernel, ceil(support), width, height, *args, **clean_kwargs)

shift

shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any,
) -> ConstantFormatVideoNode
Source code
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
@inject_self.cached
@inject_kwargs_params
def shift(
    self,
    clip: vs.VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any
) -> ConstantFormatVideoNode:
    assert check_variable_format(clip, self.shift)

    n_planes = clip.format.num_planes

    def _shift(src: VideoNodeT, shift: tuple[TopShift, LeftShift] = (0, 0)) -> VideoNodeT:
        return self.scale(src, src.width, src.height, shift, **kwargs)

    if not shifts_or_top and not shift_left:
        return _shift(clip)

    if isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)

    if isinstance(shifts_or_top, float) and isinstance(shift_left, float):
        return _shift(clip, (shifts_or_top, shift_left))

    if shifts_or_top is None:
        shifts_or_top = 0.0
    if shift_left is None:
        shift_left = 0.0

    shifts_top = shifts_or_top if isinstance(shifts_or_top, list) else [shifts_or_top]
    shifts_left = shift_left if isinstance(shift_left, list) else [shift_left]

    if not shifts_top:
        shifts_top = [0.0] * n_planes
    elif (ltop := len(shifts_top)) > n_planes:
        shifts_top = shifts_top[:n_planes]
    else:
        shifts_top += shifts_top[-1:] * (n_planes - ltop)

    if not shifts_left:
        shifts_left = [0.0] * n_planes
    elif (lleft := len(shifts_left)) > n_planes:
        shifts_left = shifts_left[:n_planes]
    else:
        shifts_left += shifts_left[-1:] * (n_planes - lleft)

    if len(set(shifts_top)) == len(set(shifts_left)) == 1 or n_planes == 1:
        return _shift(clip, (shifts_top[0], shifts_left[0]))

    planes = split(clip)

    shifted_planes = [
        plane if top == left == 0 else _shift(plane, (top, left))
        for plane, top, left in zip(planes, shifts_top, shifts_left)
    ]

    return core.std.ShufflePlanes(shifted_planes, [0, 0, 0], clip.format.color_family)

supersample

supersample(
    clip: VideoNode,
    rfactor: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
257
258
259
260
261
262
263
264
265
266
267
268
269
270
@inject_self.cached
def supersample(
    self, clip: vs.VideoNode, rfactor: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

    dst_width, dst_height = ceil(clip.width * rfactor), ceil(clip.height * rfactor)

    if max(dst_width, dst_height) <= 0.0:
        raise CustomValueError(
            'Multiplying the resolution by "rfactor" must result in a positive resolution!', self.supersample, rfactor
        )

    return self.scale(clip, dst_width, dst_height, shift, **kwargs)

Box

Box(**kwargs: Any)

Bases: CustomComplexKernel

Box resizer.

Methods:

Attributes:

  • kwargs (KwargsT) –

    Arguments passed to the internal scale function

Source code
182
183
def __init__(self, **kwargs: Any) -> None:
    self.kwargs = kwargs

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

descale

descale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: ShiftT = (0, 0),
    *,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    field_based: FieldBased | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    blur: float = 1.0,
    ignore_mask: VideoNode | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
@inject_self.cached
@inject_kwargs_params
def descale(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: ShiftT = (0, 0),
    *,
    # `border_handling`, `sample_grid_model` and `field_based` from Descaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    field_based: FieldBased | None = None,
    # `linear` and `sigmoid` parameters from LinearDescaler
    linear: bool = False, sigmoid: bool | tuple[Slope, Center] = False,
    # `blur` and `ignore_mask` from CustomKernel
    blur: float = 1.0, ignore_mask: vs.VideoNode | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode
Source code
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def descale_function(
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode:
    kernel, support = self._modify_kernel_func(kwargs)

    clean_kwargs = {
        k: v for k, v in kwargs.items()
        if k not in Signature.from_callable(self._modify_kernel_func).parameters.keys()
    }

    try:
        return core.descale.Decustom(clip, width, height, kernel, ceil(support), *args, **clean_kwargs)
    except vs.Error as e:
        if 'Output dimension must be' in str(e):
            raise CustomValueError(
                f'Output dimension ({width}x{height}) must be less than or equal to '
                f'input dimension ({clip.width}x{clip.height}).', self.__class__
            )

        raise CustomValueError(e, self.__class__)

ensure_obj classmethod

ensure_obj(
    kernel: KernelT | None = ..., /, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: str | type[BaseScaler] | BaseScaler | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> BaseScaler
Source code
647
648
649
650
651
652
653
654
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: str | type[BaseScaler] | BaseScaler | None = None, /,
    func_except: FuncExceptT | None = None
) -> BaseScaler:
    return _base_ensure_obj(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = ..., /, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: str | type[BaseScaler] | BaseScaler | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> type[BaseScaler]
Source code
611
612
613
614
615
616
617
@classmethod
def from_param(
    cls, kernel: str | type[BaseScaler] | BaseScaler | None = None, /, func_except: FuncExceptT | None = None
) -> type[BaseScaler]:
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
216
217
def get_clean_kwargs(self, *funcs: Callable[..., Any] | None) -> KwargsT:
    return _clean_self_kwargs(funcs, self)

get_descale_args

get_descale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
673
674
675
676
677
678
679
680
681
682
683
@inject_kwargs_params
def get_descale_args(
    self, clip: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None, height: int | None = None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(src_top=shift[0], src_left=shift[1])
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(True, clip, width, height, **kwargs)
    )

get_implemented_funcs

get_implemented_funcs() -> tuple[Callable[..., Any], ...]
Source code
701
702
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )

get_params_args

get_params_args(
    is_descale: bool,
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]
Source code
85
86
87
88
89
90
91
92
93
94
def get_params_args(
    self, is_descale: bool, clip: vs.VideoNode, width: int | None = None, height: int | None = None, **kwargs: Any
) -> dict[str, Any]:
    args = super().get_params_args(is_descale, clip, width, height, **kwargs)

    if not is_descale:
        for key in ('border_handling', 'ignore_mask'):
            args.pop(key, None)

    return args

get_resample_args

get_resample_args(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None,
    matrix_in: MatrixT | None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
@inject_kwargs_params
def get_resample_args(
    self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None, matrix_in: MatrixT | None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(
            format=get_video_format(format).id,
            matrix=Matrix.from_param(matrix),
            matrix_in=Matrix.from_param(matrix_in)
        )
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(False, clip, **kwargs)
    )

get_scale_args

get_scale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
661
662
663
664
665
666
667
668
669
670
671
@inject_kwargs_params
def get_scale_args(
    self, clip: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None, height: int | None = None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(src_top=shift[0], src_left=shift[1])
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(False, clip, width, height, **kwargs)
    )

kernel

kernel(*, x: float) -> float
Source code
71
72
73
@inject_self.cached
def kernel(self, *, x: float) -> float:
    return 1.0 if x >= -0.5 and x < 0.5 else 0.0

kernel_radius

kernel_radius() -> int
Source code
210
211
212
213
214
@inject_self.cached.property
def kernel_radius(self) -> int:
    if hasattr(self, '_static_kernel_radius'):
        return ceil(self._static_kernel_radius)
    raise CustomNotImplementedError('kernel_radius is not implemented!', self.__class__)

multi

multi(
    clip: VideoNode,
    multi: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
272
273
274
275
276
277
278
279
280
281
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:

    import warnings

    warnings.warn('The "multi" method is deprecated. Use "supersample" instead.', DeprecationWarning)

    return self.supersample(clip, multi, shift, **kwargs)

pretty_string

pretty_string() -> str
Source code
225
226
227
@inject_self.cached.property
def pretty_string(self) -> str:
    return self._pretty_string()

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
438
439
440
441
442
443
444
445
446
@inject_self.cached
@inject_kwargs_params
def resample(
    self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None, matrix_in: MatrixT | None = None, **kwargs: Any
) -> ConstantFormatVideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

resample_function

resample_function(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    *args: Any,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
59
60
61
62
def resample_function(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode:
    return self.scale_function(clip, width, height, *args, **kwargs)  # type: ignore[return-value]

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
@inject_self.cached
@inject_kwargs_params
def scale(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    # `border_handling`, `sample_grid_model`, `sar`, `dar`, `dar_in` and `keep_ar` from KeepArScaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | float | bool | None = None, dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None, keep_ar: bool | None = None,
    # `linear` and `sigmoid` from LinearScaler
    linear: bool = False, sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> vs.VideoNode:
    width, height = Scaler._wh_norm(clip, width, height)
    return super().scale(
        clip, width, height, shift,
        border_handling=border_handling, sample_grid_model=sample_grid_model,
        sar=sar, dar=dar, dar_in=dar_in, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid,
        **kwargs
    )

scale_function

scale_function(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    *args: Any,
    **kwargs: Any
) -> VideoNode
Source code
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def scale_function(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None, *args: Any, **kwargs: Any
) -> vs.VideoNode:

    if not hasattr(core, 'resize2'):
        raise DependencyNotFoundError(
            self.__class__, 'resize2', 'Missing dependency \'resize2\'! '
            'You can find it here: https://github.com/Jaded-Encoding-Thaumaturgy/vapoursynth-resize2'
        )

    kernel, support = self._modify_kernel_func(kwargs)

    clean_kwargs = {
        k: v for k, v in kwargs.items()
        if k not in Signature.from_callable(self._modify_kernel_func).parameters.keys()
    }

    return core.resize2.Custom(clip, kernel, ceil(support), width, height, *args, **clean_kwargs)

shift

shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any,
) -> ConstantFormatVideoNode
Source code
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
@inject_self.cached
@inject_kwargs_params
def shift(
    self,
    clip: vs.VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any
) -> ConstantFormatVideoNode:
    assert check_variable_format(clip, self.shift)

    n_planes = clip.format.num_planes

    def _shift(src: VideoNodeT, shift: tuple[TopShift, LeftShift] = (0, 0)) -> VideoNodeT:
        return self.scale(src, src.width, src.height, shift, **kwargs)

    if not shifts_or_top and not shift_left:
        return _shift(clip)

    if isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)

    if isinstance(shifts_or_top, float) and isinstance(shift_left, float):
        return _shift(clip, (shifts_or_top, shift_left))

    if shifts_or_top is None:
        shifts_or_top = 0.0
    if shift_left is None:
        shift_left = 0.0

    shifts_top = shifts_or_top if isinstance(shifts_or_top, list) else [shifts_or_top]
    shifts_left = shift_left if isinstance(shift_left, list) else [shift_left]

    if not shifts_top:
        shifts_top = [0.0] * n_planes
    elif (ltop := len(shifts_top)) > n_planes:
        shifts_top = shifts_top[:n_planes]
    else:
        shifts_top += shifts_top[-1:] * (n_planes - ltop)

    if not shifts_left:
        shifts_left = [0.0] * n_planes
    elif (lleft := len(shifts_left)) > n_planes:
        shifts_left = shifts_left[:n_planes]
    else:
        shifts_left += shifts_left[-1:] * (n_planes - lleft)

    if len(set(shifts_top)) == len(set(shifts_left)) == 1 or n_planes == 1:
        return _shift(clip, (shifts_top[0], shifts_left[0]))

    planes = split(clip)

    shifted_planes = [
        plane if top == left == 0 else _shift(plane, (top, left))
        for plane, top, left in zip(planes, shifts_top, shifts_left)
    ]

    return core.std.ShufflePlanes(shifted_planes, [0, 0, 0], clip.format.color_family)

supersample

supersample(
    clip: VideoNode,
    rfactor: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
257
258
259
260
261
262
263
264
265
266
267
268
269
270
@inject_self.cached
def supersample(
    self, clip: vs.VideoNode, rfactor: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

    dst_width, dst_height = ceil(clip.width * rfactor), ceil(clip.height * rfactor)

    if max(dst_width, dst_height) <= 0.0:
        raise CustomValueError(
            'Multiplying the resolution by "rfactor" must result in a positive resolution!', self.supersample, rfactor
        )

    return self.scale(clip, dst_width, dst_height, shift, **kwargs)

Cosine

Cosine(taps: float, **kwargs: Any)

Bases: CustomComplexTapsKernel

Cosine kernel.

Methods:

Attributes:

  • kwargs (KwargsT) –

    Arguments passed to the internal scale function

  • taps
Source code
283
284
285
def __init__(self, taps: float, **kwargs: Any) -> None:
    self.taps = taps
    super().__init__(**kwargs)

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

taps instance-attribute

taps = taps

descale

descale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: ShiftT = (0, 0),
    *,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    field_based: FieldBased | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    blur: float = 1.0,
    ignore_mask: VideoNode | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
@inject_self.cached
@inject_kwargs_params
def descale(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: ShiftT = (0, 0),
    *,
    # `border_handling`, `sample_grid_model` and `field_based` from Descaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    field_based: FieldBased | None = None,
    # `linear` and `sigmoid` parameters from LinearDescaler
    linear: bool = False, sigmoid: bool | tuple[Slope, Center] = False,
    # `blur` and `ignore_mask` from CustomKernel
    blur: float = 1.0, ignore_mask: vs.VideoNode | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode
Source code
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def descale_function(
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode:
    kernel, support = self._modify_kernel_func(kwargs)

    clean_kwargs = {
        k: v for k, v in kwargs.items()
        if k not in Signature.from_callable(self._modify_kernel_func).parameters.keys()
    }

    try:
        return core.descale.Decustom(clip, width, height, kernel, ceil(support), *args, **clean_kwargs)
    except vs.Error as e:
        if 'Output dimension must be' in str(e):
            raise CustomValueError(
                f'Output dimension ({width}x{height}) must be less than or equal to '
                f'input dimension ({clip.width}x{clip.height}).', self.__class__
            )

        raise CustomValueError(e, self.__class__)

ensure_obj classmethod

ensure_obj(
    kernel: KernelT | None = ..., /, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: str | type[BaseScaler] | BaseScaler | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> BaseScaler
Source code
647
648
649
650
651
652
653
654
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: str | type[BaseScaler] | BaseScaler | None = None, /,
    func_except: FuncExceptT | None = None
) -> BaseScaler:
    return _base_ensure_obj(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = ..., /, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: str | type[BaseScaler] | BaseScaler | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> type[BaseScaler]
Source code
611
612
613
614
615
616
617
@classmethod
def from_param(
    cls, kernel: str | type[BaseScaler] | BaseScaler | None = None, /, func_except: FuncExceptT | None = None
) -> type[BaseScaler]:
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
216
217
def get_clean_kwargs(self, *funcs: Callable[..., Any] | None) -> KwargsT:
    return _clean_self_kwargs(funcs, self)

get_descale_args

get_descale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
673
674
675
676
677
678
679
680
681
682
683
@inject_kwargs_params
def get_descale_args(
    self, clip: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None, height: int | None = None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(src_top=shift[0], src_left=shift[1])
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(True, clip, width, height, **kwargs)
    )

get_implemented_funcs

get_implemented_funcs() -> tuple[Callable[..., Any], ...]
Source code
701
702
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )

get_params_args

get_params_args(
    is_descale: bool,
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]
Source code
85
86
87
88
89
90
91
92
93
94
def get_params_args(
    self, is_descale: bool, clip: vs.VideoNode, width: int | None = None, height: int | None = None, **kwargs: Any
) -> dict[str, Any]:
    args = super().get_params_args(is_descale, clip, width, height, **kwargs)

    if not is_descale:
        for key in ('border_handling', 'ignore_mask'):
            args.pop(key, None)

    return args

get_resample_args

get_resample_args(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None,
    matrix_in: MatrixT | None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
@inject_kwargs_params
def get_resample_args(
    self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None, matrix_in: MatrixT | None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(
            format=get_video_format(format).id,
            matrix=Matrix.from_param(matrix),
            matrix_in=Matrix.from_param(matrix_in)
        )
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(False, clip, **kwargs)
    )

get_scale_args

get_scale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
661
662
663
664
665
666
667
668
669
670
671
@inject_kwargs_params
def get_scale_args(
    self, clip: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None, height: int | None = None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(src_top=shift[0], src_left=shift[1])
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(False, clip, width, height, **kwargs)
    )

kernel

kernel(*, x: float) -> float
Source code
154
155
156
157
158
159
160
161
@inject_self.cached
def kernel(self, *, x: float) -> float:
    if x >= self.kernel_radius:
        return 0.0

    cosine = cos(pi * x)

    return 0.34 + cosine * (0.5 + cosine * 0.16)

kernel_radius

kernel_radius() -> int
Source code
287
288
289
@inject_self.cached.property
def kernel_radius(self) -> int:
    return ceil(self.taps)

multi

multi(
    clip: VideoNode,
    multi: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
272
273
274
275
276
277
278
279
280
281
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:

    import warnings

    warnings.warn('The "multi" method is deprecated. Use "supersample" instead.', DeprecationWarning)

    return self.supersample(clip, multi, shift, **kwargs)

pretty_string

pretty_string() -> str
Source code
225
226
227
@inject_self.cached.property
def pretty_string(self) -> str:
    return self._pretty_string()

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
438
439
440
441
442
443
444
445
446
@inject_self.cached
@inject_kwargs_params
def resample(
    self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None, matrix_in: MatrixT | None = None, **kwargs: Any
) -> ConstantFormatVideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

resample_function

resample_function(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    *args: Any,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
59
60
61
62
def resample_function(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode:
    return self.scale_function(clip, width, height, *args, **kwargs)  # type: ignore[return-value]

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
@inject_self.cached
@inject_kwargs_params
def scale(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    # `border_handling`, `sample_grid_model`, `sar`, `dar`, `dar_in` and `keep_ar` from KeepArScaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | float | bool | None = None, dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None, keep_ar: bool | None = None,
    # `linear` and `sigmoid` from LinearScaler
    linear: bool = False, sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> vs.VideoNode:
    width, height = Scaler._wh_norm(clip, width, height)
    return super().scale(
        clip, width, height, shift,
        border_handling=border_handling, sample_grid_model=sample_grid_model,
        sar=sar, dar=dar, dar_in=dar_in, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid,
        **kwargs
    )

scale_function

scale_function(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    *args: Any,
    **kwargs: Any
) -> VideoNode
Source code
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def scale_function(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None, *args: Any, **kwargs: Any
) -> vs.VideoNode:

    if not hasattr(core, 'resize2'):
        raise DependencyNotFoundError(
            self.__class__, 'resize2', 'Missing dependency \'resize2\'! '
            'You can find it here: https://github.com/Jaded-Encoding-Thaumaturgy/vapoursynth-resize2'
        )

    kernel, support = self._modify_kernel_func(kwargs)

    clean_kwargs = {
        k: v for k, v in kwargs.items()
        if k not in Signature.from_callable(self._modify_kernel_func).parameters.keys()
    }

    return core.resize2.Custom(clip, kernel, ceil(support), width, height, *args, **clean_kwargs)

shift

shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any,
) -> ConstantFormatVideoNode
Source code
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
@inject_self.cached
@inject_kwargs_params
def shift(
    self,
    clip: vs.VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any
) -> ConstantFormatVideoNode:
    assert check_variable_format(clip, self.shift)

    n_planes = clip.format.num_planes

    def _shift(src: VideoNodeT, shift: tuple[TopShift, LeftShift] = (0, 0)) -> VideoNodeT:
        return self.scale(src, src.width, src.height, shift, **kwargs)

    if not shifts_or_top and not shift_left:
        return _shift(clip)

    if isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)

    if isinstance(shifts_or_top, float) and isinstance(shift_left, float):
        return _shift(clip, (shifts_or_top, shift_left))

    if shifts_or_top is None:
        shifts_or_top = 0.0
    if shift_left is None:
        shift_left = 0.0

    shifts_top = shifts_or_top if isinstance(shifts_or_top, list) else [shifts_or_top]
    shifts_left = shift_left if isinstance(shift_left, list) else [shift_left]

    if not shifts_top:
        shifts_top = [0.0] * n_planes
    elif (ltop := len(shifts_top)) > n_planes:
        shifts_top = shifts_top[:n_planes]
    else:
        shifts_top += shifts_top[-1:] * (n_planes - ltop)

    if not shifts_left:
        shifts_left = [0.0] * n_planes
    elif (lleft := len(shifts_left)) > n_planes:
        shifts_left = shifts_left[:n_planes]
    else:
        shifts_left += shifts_left[-1:] * (n_planes - lleft)

    if len(set(shifts_top)) == len(set(shifts_left)) == 1 or n_planes == 1:
        return _shift(clip, (shifts_top[0], shifts_left[0]))

    planes = split(clip)

    shifted_planes = [
        plane if top == left == 0 else _shift(plane, (top, left))
        for plane, top, left in zip(planes, shifts_top, shifts_left)
    ]

    return core.std.ShufflePlanes(shifted_planes, [0, 0, 0], clip.format.color_family)

supersample

supersample(
    clip: VideoNode,
    rfactor: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
257
258
259
260
261
262
263
264
265
266
267
268
269
270
@inject_self.cached
def supersample(
    self, clip: vs.VideoNode, rfactor: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

    dst_width, dst_height = ceil(clip.width * rfactor), ceil(clip.height * rfactor)

    if max(dst_width, dst_height) <= 0.0:
        raise CustomValueError(
            'Multiplying the resolution by "rfactor" must result in a positive resolution!', self.supersample, rfactor
        )

    return self.scale(clip, dst_width, dst_height, shift, **kwargs)

Gaussian

Gaussian(sigma: float = 0.5, taps: float = 2, **kwargs: Any)

Bases: CustomComplexTapsKernel

Gaussian resizer.

Sigma is the same as imagemagick's sigma scaling.

Methods:

Attributes:

  • kwargs (KwargsT) –

    Arguments passed to the internal scale function

  • taps
Source code
50
51
52
53
54
55
def __init__(self, sigma: float = 0.5, taps: float = 2, **kwargs: Any) -> None:
    """Sigma is the same as imagemagick's sigma scaling."""

    self._sigma = sigma

    super().__init__(taps, **kwargs)

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

taps instance-attribute

taps = taps

descale

descale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: ShiftT = (0, 0),
    *,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    field_based: FieldBased | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    blur: float = 1.0,
    ignore_mask: VideoNode | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
@inject_self.cached
@inject_kwargs_params
def descale(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: ShiftT = (0, 0),
    *,
    # `border_handling`, `sample_grid_model` and `field_based` from Descaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    field_based: FieldBased | None = None,
    # `linear` and `sigmoid` parameters from LinearDescaler
    linear: bool = False, sigmoid: bool | tuple[Slope, Center] = False,
    # `blur` and `ignore_mask` from CustomKernel
    blur: float = 1.0, ignore_mask: vs.VideoNode | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode
Source code
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def descale_function(
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode:
    kernel, support = self._modify_kernel_func(kwargs)

    clean_kwargs = {
        k: v for k, v in kwargs.items()
        if k not in Signature.from_callable(self._modify_kernel_func).parameters.keys()
    }

    try:
        return core.descale.Decustom(clip, width, height, kernel, ceil(support), *args, **clean_kwargs)
    except vs.Error as e:
        if 'Output dimension must be' in str(e):
            raise CustomValueError(
                f'Output dimension ({width}x{height}) must be less than or equal to '
                f'input dimension ({clip.width}x{clip.height}).', self.__class__
            )

        raise CustomValueError(e, self.__class__)

ensure_obj classmethod

ensure_obj(
    kernel: KernelT | None = ..., /, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: str | type[BaseScaler] | BaseScaler | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> BaseScaler
Source code
647
648
649
650
651
652
653
654
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: str | type[BaseScaler] | BaseScaler | None = None, /,
    func_except: FuncExceptT | None = None
) -> BaseScaler:
    return _base_ensure_obj(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = ..., /, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: str | type[BaseScaler] | BaseScaler | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> type[BaseScaler]
Source code
611
612
613
614
615
616
617
@classmethod
def from_param(
    cls, kernel: str | type[BaseScaler] | BaseScaler | None = None, /, func_except: FuncExceptT | None = None
) -> type[BaseScaler]:
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
216
217
def get_clean_kwargs(self, *funcs: Callable[..., Any] | None) -> KwargsT:
    return _clean_self_kwargs(funcs, self)

get_descale_args

get_descale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
673
674
675
676
677
678
679
680
681
682
683
@inject_kwargs_params
def get_descale_args(
    self, clip: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None, height: int | None = None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(src_top=shift[0], src_left=shift[1])
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(True, clip, width, height, **kwargs)
    )

get_implemented_funcs

get_implemented_funcs() -> tuple[Callable[..., Any], ...]
Source code
701
702
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )

get_params_args

get_params_args(
    is_descale: bool,
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]
Source code
85
86
87
88
89
90
91
92
93
94
def get_params_args(
    self, is_descale: bool, clip: vs.VideoNode, width: int | None = None, height: int | None = None, **kwargs: Any
) -> dict[str, Any]:
    args = super().get_params_args(is_descale, clip, width, height, **kwargs)

    if not is_descale:
        for key in ('border_handling', 'ignore_mask'):
            args.pop(key, None)

    return args

get_resample_args

get_resample_args(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None,
    matrix_in: MatrixT | None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
@inject_kwargs_params
def get_resample_args(
    self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None, matrix_in: MatrixT | None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(
            format=get_video_format(format).id,
            matrix=Matrix.from_param(matrix),
            matrix_in=Matrix.from_param(matrix_in)
        )
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(False, clip, **kwargs)
    )

get_scale_args

get_scale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
661
662
663
664
665
666
667
668
669
670
671
@inject_kwargs_params
def get_scale_args(
    self, clip: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None, height: int | None = None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(src_top=shift[0], src_left=shift[1])
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(False, clip, width, height, **kwargs)
    )

kernel

kernel(*, x: float) -> float
Source code
61
62
63
@inject_self.cached
def kernel(self, *, x: float) -> float:
    return 1 / (self._sigma * sqrt(2 * pi)) * exp(-x ** 2 / (2 * self._sigma ** 2))

kernel_radius

kernel_radius() -> int
Source code
287
288
289
@inject_self.cached.property
def kernel_radius(self) -> int:
    return ceil(self.taps)

multi

multi(
    clip: VideoNode,
    multi: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
272
273
274
275
276
277
278
279
280
281
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:

    import warnings

    warnings.warn('The "multi" method is deprecated. Use "supersample" instead.', DeprecationWarning)

    return self.supersample(clip, multi, shift, **kwargs)

pretty_string

pretty_string() -> str
Source code
225
226
227
@inject_self.cached.property
def pretty_string(self) -> str:
    return self._pretty_string()

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
438
439
440
441
442
443
444
445
446
@inject_self.cached
@inject_kwargs_params
def resample(
    self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None, matrix_in: MatrixT | None = None, **kwargs: Any
) -> ConstantFormatVideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

resample_function

resample_function(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    *args: Any,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
59
60
61
62
def resample_function(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode:
    return self.scale_function(clip, width, height, *args, **kwargs)  # type: ignore[return-value]

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
@inject_self.cached
@inject_kwargs_params
def scale(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    # `border_handling`, `sample_grid_model`, `sar`, `dar`, `dar_in` and `keep_ar` from KeepArScaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | float | bool | None = None, dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None, keep_ar: bool | None = None,
    # `linear` and `sigmoid` from LinearScaler
    linear: bool = False, sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> vs.VideoNode:
    width, height = Scaler._wh_norm(clip, width, height)
    return super().scale(
        clip, width, height, shift,
        border_handling=border_handling, sample_grid_model=sample_grid_model,
        sar=sar, dar=dar, dar_in=dar_in, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid,
        **kwargs
    )

scale_function

scale_function(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    *args: Any,
    **kwargs: Any
) -> VideoNode
Source code
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def scale_function(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None, *args: Any, **kwargs: Any
) -> vs.VideoNode:

    if not hasattr(core, 'resize2'):
        raise DependencyNotFoundError(
            self.__class__, 'resize2', 'Missing dependency \'resize2\'! '
            'You can find it here: https://github.com/Jaded-Encoding-Thaumaturgy/vapoursynth-resize2'
        )

    kernel, support = self._modify_kernel_func(kwargs)

    clean_kwargs = {
        k: v for k, v in kwargs.items()
        if k not in Signature.from_callable(self._modify_kernel_func).parameters.keys()
    }

    return core.resize2.Custom(clip, kernel, ceil(support), width, height, *args, **clean_kwargs)

shift

shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any,
) -> ConstantFormatVideoNode
Source code
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
@inject_self.cached
@inject_kwargs_params
def shift(
    self,
    clip: vs.VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any
) -> ConstantFormatVideoNode:
    assert check_variable_format(clip, self.shift)

    n_planes = clip.format.num_planes

    def _shift(src: VideoNodeT, shift: tuple[TopShift, LeftShift] = (0, 0)) -> VideoNodeT:
        return self.scale(src, src.width, src.height, shift, **kwargs)

    if not shifts_or_top and not shift_left:
        return _shift(clip)

    if isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)

    if isinstance(shifts_or_top, float) and isinstance(shift_left, float):
        return _shift(clip, (shifts_or_top, shift_left))

    if shifts_or_top is None:
        shifts_or_top = 0.0
    if shift_left is None:
        shift_left = 0.0

    shifts_top = shifts_or_top if isinstance(shifts_or_top, list) else [shifts_or_top]
    shifts_left = shift_left if isinstance(shift_left, list) else [shift_left]

    if not shifts_top:
        shifts_top = [0.0] * n_planes
    elif (ltop := len(shifts_top)) > n_planes:
        shifts_top = shifts_top[:n_planes]
    else:
        shifts_top += shifts_top[-1:] * (n_planes - ltop)

    if not shifts_left:
        shifts_left = [0.0] * n_planes
    elif (lleft := len(shifts_left)) > n_planes:
        shifts_left = shifts_left[:n_planes]
    else:
        shifts_left += shifts_left[-1:] * (n_planes - lleft)

    if len(set(shifts_top)) == len(set(shifts_left)) == 1 or n_planes == 1:
        return _shift(clip, (shifts_top[0], shifts_left[0]))

    planes = split(clip)

    shifted_planes = [
        plane if top == left == 0 else _shift(plane, (top, left))
        for plane, top, left in zip(planes, shifts_top, shifts_left)
    ]

    return core.std.ShufflePlanes(shifted_planes, [0, 0, 0], clip.format.color_family)

sigma

sigma() -> gauss_sigma
Source code
57
58
59
@inject_self.property
def sigma(self) -> gauss_sigma:
    return gauss_sigma(self._sigma)

supersample

supersample(
    clip: VideoNode,
    rfactor: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
257
258
259
260
261
262
263
264
265
266
267
268
269
270
@inject_self.cached
def supersample(
    self, clip: vs.VideoNode, rfactor: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

    dst_width, dst_height = ceil(clip.width * rfactor), ceil(clip.height * rfactor)

    if max(dst_width, dst_height) <= 0.0:
        raise CustomValueError(
            'Multiplying the resolution by "rfactor" must result in a positive resolution!', self.supersample, rfactor
        )

    return self.scale(clip, dst_width, dst_height, shift, **kwargs)

Hamming

Hamming(taps: float, **kwargs: Any)

Bases: CustomComplexTapsKernel

Hamming kernel.

Methods:

Attributes:

  • kwargs (KwargsT) –

    Arguments passed to the internal scale function

  • taps
Source code
283
284
285
def __init__(self, taps: float, **kwargs: Any) -> None:
    self.taps = taps
    super().__init__(**kwargs)

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

taps instance-attribute

taps = taps

descale

descale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: ShiftT = (0, 0),
    *,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    field_based: FieldBased | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    blur: float = 1.0,
    ignore_mask: VideoNode | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
@inject_self.cached
@inject_kwargs_params
def descale(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: ShiftT = (0, 0),
    *,
    # `border_handling`, `sample_grid_model` and `field_based` from Descaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    field_based: FieldBased | None = None,
    # `linear` and `sigmoid` parameters from LinearDescaler
    linear: bool = False, sigmoid: bool | tuple[Slope, Center] = False,
    # `blur` and `ignore_mask` from CustomKernel
    blur: float = 1.0, ignore_mask: vs.VideoNode | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode
Source code
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def descale_function(
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode:
    kernel, support = self._modify_kernel_func(kwargs)

    clean_kwargs = {
        k: v for k, v in kwargs.items()
        if k not in Signature.from_callable(self._modify_kernel_func).parameters.keys()
    }

    try:
        return core.descale.Decustom(clip, width, height, kernel, ceil(support), *args, **clean_kwargs)
    except vs.Error as e:
        if 'Output dimension must be' in str(e):
            raise CustomValueError(
                f'Output dimension ({width}x{height}) must be less than or equal to '
                f'input dimension ({clip.width}x{clip.height}).', self.__class__
            )

        raise CustomValueError(e, self.__class__)

ensure_obj classmethod

ensure_obj(
    kernel: KernelT | None = ..., /, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: str | type[BaseScaler] | BaseScaler | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> BaseScaler
Source code
647
648
649
650
651
652
653
654
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: str | type[BaseScaler] | BaseScaler | None = None, /,
    func_except: FuncExceptT | None = None
) -> BaseScaler:
    return _base_ensure_obj(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = ..., /, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: str | type[BaseScaler] | BaseScaler | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> type[BaseScaler]
Source code
611
612
613
614
615
616
617
@classmethod
def from_param(
    cls, kernel: str | type[BaseScaler] | BaseScaler | None = None, /, func_except: FuncExceptT | None = None
) -> type[BaseScaler]:
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
216
217
def get_clean_kwargs(self, *funcs: Callable[..., Any] | None) -> KwargsT:
    return _clean_self_kwargs(funcs, self)

get_descale_args

get_descale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
673
674
675
676
677
678
679
680
681
682
683
@inject_kwargs_params
def get_descale_args(
    self, clip: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None, height: int | None = None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(src_top=shift[0], src_left=shift[1])
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(True, clip, width, height, **kwargs)
    )

get_implemented_funcs

get_implemented_funcs() -> tuple[Callable[..., Any], ...]
Source code
701
702
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )

get_params_args

get_params_args(
    is_descale: bool,
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]
Source code
85
86
87
88
89
90
91
92
93
94
def get_params_args(
    self, is_descale: bool, clip: vs.VideoNode, width: int | None = None, height: int | None = None, **kwargs: Any
) -> dict[str, Any]:
    args = super().get_params_args(is_descale, clip, width, height, **kwargs)

    if not is_descale:
        for key in ('border_handling', 'ignore_mask'):
            args.pop(key, None)

    return args

get_resample_args

get_resample_args(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None,
    matrix_in: MatrixT | None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
@inject_kwargs_params
def get_resample_args(
    self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None, matrix_in: MatrixT | None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(
            format=get_video_format(format).id,
            matrix=Matrix.from_param(matrix),
            matrix_in=Matrix.from_param(matrix_in)
        )
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(False, clip, **kwargs)
    )

get_scale_args

get_scale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
661
662
663
664
665
666
667
668
669
670
671
@inject_kwargs_params
def get_scale_args(
    self, clip: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None, height: int | None = None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(src_top=shift[0], src_left=shift[1])
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(False, clip, width, height, **kwargs)
    )

kernel

kernel(*, x: float) -> float
Source code
132
133
134
135
136
137
@inject_self.cached
def kernel(self, *, x: float) -> float:
    if x >= self.kernel_radius:
        return 0.0

    return 0.54 + 0.46 * cos(pi * x)

kernel_radius

kernel_radius() -> int
Source code
287
288
289
@inject_self.cached.property
def kernel_radius(self) -> int:
    return ceil(self.taps)

multi

multi(
    clip: VideoNode,
    multi: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
272
273
274
275
276
277
278
279
280
281
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:

    import warnings

    warnings.warn('The "multi" method is deprecated. Use "supersample" instead.', DeprecationWarning)

    return self.supersample(clip, multi, shift, **kwargs)

pretty_string

pretty_string() -> str
Source code
225
226
227
@inject_self.cached.property
def pretty_string(self) -> str:
    return self._pretty_string()

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
438
439
440
441
442
443
444
445
446
@inject_self.cached
@inject_kwargs_params
def resample(
    self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None, matrix_in: MatrixT | None = None, **kwargs: Any
) -> ConstantFormatVideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

resample_function

resample_function(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    *args: Any,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
59
60
61
62
def resample_function(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode:
    return self.scale_function(clip, width, height, *args, **kwargs)  # type: ignore[return-value]

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
@inject_self.cached
@inject_kwargs_params
def scale(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    # `border_handling`, `sample_grid_model`, `sar`, `dar`, `dar_in` and `keep_ar` from KeepArScaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | float | bool | None = None, dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None, keep_ar: bool | None = None,
    # `linear` and `sigmoid` from LinearScaler
    linear: bool = False, sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> vs.VideoNode:
    width, height = Scaler._wh_norm(clip, width, height)
    return super().scale(
        clip, width, height, shift,
        border_handling=border_handling, sample_grid_model=sample_grid_model,
        sar=sar, dar=dar, dar_in=dar_in, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid,
        **kwargs
    )

scale_function

scale_function(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    *args: Any,
    **kwargs: Any
) -> VideoNode
Source code
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def scale_function(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None, *args: Any, **kwargs: Any
) -> vs.VideoNode:

    if not hasattr(core, 'resize2'):
        raise DependencyNotFoundError(
            self.__class__, 'resize2', 'Missing dependency \'resize2\'! '
            'You can find it here: https://github.com/Jaded-Encoding-Thaumaturgy/vapoursynth-resize2'
        )

    kernel, support = self._modify_kernel_func(kwargs)

    clean_kwargs = {
        k: v for k, v in kwargs.items()
        if k not in Signature.from_callable(self._modify_kernel_func).parameters.keys()
    }

    return core.resize2.Custom(clip, kernel, ceil(support), width, height, *args, **clean_kwargs)

shift

shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any,
) -> ConstantFormatVideoNode
Source code
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
@inject_self.cached
@inject_kwargs_params
def shift(
    self,
    clip: vs.VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any
) -> ConstantFormatVideoNode:
    assert check_variable_format(clip, self.shift)

    n_planes = clip.format.num_planes

    def _shift(src: VideoNodeT, shift: tuple[TopShift, LeftShift] = (0, 0)) -> VideoNodeT:
        return self.scale(src, src.width, src.height, shift, **kwargs)

    if not shifts_or_top and not shift_left:
        return _shift(clip)

    if isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)

    if isinstance(shifts_or_top, float) and isinstance(shift_left, float):
        return _shift(clip, (shifts_or_top, shift_left))

    if shifts_or_top is None:
        shifts_or_top = 0.0
    if shift_left is None:
        shift_left = 0.0

    shifts_top = shifts_or_top if isinstance(shifts_or_top, list) else [shifts_or_top]
    shifts_left = shift_left if isinstance(shift_left, list) else [shift_left]

    if not shifts_top:
        shifts_top = [0.0] * n_planes
    elif (ltop := len(shifts_top)) > n_planes:
        shifts_top = shifts_top[:n_planes]
    else:
        shifts_top += shifts_top[-1:] * (n_planes - ltop)

    if not shifts_left:
        shifts_left = [0.0] * n_planes
    elif (lleft := len(shifts_left)) > n_planes:
        shifts_left = shifts_left[:n_planes]
    else:
        shifts_left += shifts_left[-1:] * (n_planes - lleft)

    if len(set(shifts_top)) == len(set(shifts_left)) == 1 or n_planes == 1:
        return _shift(clip, (shifts_top[0], shifts_left[0]))

    planes = split(clip)

    shifted_planes = [
        plane if top == left == 0 else _shift(plane, (top, left))
        for plane, top, left in zip(planes, shifts_top, shifts_left)
    ]

    return core.std.ShufflePlanes(shifted_planes, [0, 0, 0], clip.format.color_family)

supersample

supersample(
    clip: VideoNode,
    rfactor: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
257
258
259
260
261
262
263
264
265
266
267
268
269
270
@inject_self.cached
def supersample(
    self, clip: vs.VideoNode, rfactor: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

    dst_width, dst_height = ceil(clip.width * rfactor), ceil(clip.height * rfactor)

    if max(dst_width, dst_height) <= 0.0:
        raise CustomValueError(
            'Multiplying the resolution by "rfactor" must result in a positive resolution!', self.supersample, rfactor
        )

    return self.scale(clip, dst_width, dst_height, shift, **kwargs)

Hann

Hann(taps: float, **kwargs: Any)

Bases: CustomComplexTapsKernel

Hann kernel.

Methods:

Attributes:

  • kwargs (KwargsT) –

    Arguments passed to the internal scale function

  • taps
Source code
283
284
285
def __init__(self, taps: float, **kwargs: Any) -> None:
    self.taps = taps
    super().__init__(**kwargs)

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

taps instance-attribute

taps = taps

descale

descale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: ShiftT = (0, 0),
    *,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    field_based: FieldBased | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    blur: float = 1.0,
    ignore_mask: VideoNode | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
@inject_self.cached
@inject_kwargs_params
def descale(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: ShiftT = (0, 0),
    *,
    # `border_handling`, `sample_grid_model` and `field_based` from Descaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    field_based: FieldBased | None = None,
    # `linear` and `sigmoid` parameters from LinearDescaler
    linear: bool = False, sigmoid: bool | tuple[Slope, Center] = False,
    # `blur` and `ignore_mask` from CustomKernel
    blur: float = 1.0, ignore_mask: vs.VideoNode | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode
Source code
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def descale_function(
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode:
    kernel, support = self._modify_kernel_func(kwargs)

    clean_kwargs = {
        k: v for k, v in kwargs.items()
        if k not in Signature.from_callable(self._modify_kernel_func).parameters.keys()
    }

    try:
        return core.descale.Decustom(clip, width, height, kernel, ceil(support), *args, **clean_kwargs)
    except vs.Error as e:
        if 'Output dimension must be' in str(e):
            raise CustomValueError(
                f'Output dimension ({width}x{height}) must be less than or equal to '
                f'input dimension ({clip.width}x{clip.height}).', self.__class__
            )

        raise CustomValueError(e, self.__class__)

ensure_obj classmethod

ensure_obj(
    kernel: KernelT | None = ..., /, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: str | type[BaseScaler] | BaseScaler | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> BaseScaler
Source code
647
648
649
650
651
652
653
654
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: str | type[BaseScaler] | BaseScaler | None = None, /,
    func_except: FuncExceptT | None = None
) -> BaseScaler:
    return _base_ensure_obj(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = ..., /, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: str | type[BaseScaler] | BaseScaler | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> type[BaseScaler]
Source code
611
612
613
614
615
616
617
@classmethod
def from_param(
    cls, kernel: str | type[BaseScaler] | BaseScaler | None = None, /, func_except: FuncExceptT | None = None
) -> type[BaseScaler]:
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
216
217
def get_clean_kwargs(self, *funcs: Callable[..., Any] | None) -> KwargsT:
    return _clean_self_kwargs(funcs, self)

get_descale_args

get_descale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
673
674
675
676
677
678
679
680
681
682
683
@inject_kwargs_params
def get_descale_args(
    self, clip: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None, height: int | None = None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(src_top=shift[0], src_left=shift[1])
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(True, clip, width, height, **kwargs)
    )

get_implemented_funcs

get_implemented_funcs() -> tuple[Callable[..., Any], ...]
Source code
701
702
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )

get_params_args

get_params_args(
    is_descale: bool,
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]
Source code
85
86
87
88
89
90
91
92
93
94
def get_params_args(
    self, is_descale: bool, clip: vs.VideoNode, width: int | None = None, height: int | None = None, **kwargs: Any
) -> dict[str, Any]:
    args = super().get_params_args(is_descale, clip, width, height, **kwargs)

    if not is_descale:
        for key in ('border_handling', 'ignore_mask'):
            args.pop(key, None)

    return args

get_resample_args

get_resample_args(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None,
    matrix_in: MatrixT | None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
@inject_kwargs_params
def get_resample_args(
    self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None, matrix_in: MatrixT | None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(
            format=get_video_format(format).id,
            matrix=Matrix.from_param(matrix),
            matrix_in=Matrix.from_param(matrix_in)
        )
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(False, clip, **kwargs)
    )

get_scale_args

get_scale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
661
662
663
664
665
666
667
668
669
670
671
@inject_kwargs_params
def get_scale_args(
    self, clip: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None, height: int | None = None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(src_top=shift[0], src_left=shift[1])
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(False, clip, width, height, **kwargs)
    )

kernel

kernel(*, x: float) -> float
Source code
121
122
123
124
125
126
@inject_self.cached
def kernel(self, *, x: float) -> float:
    if x >= self.kernel_radius:
        return 0.0

    return 0.5 + 0.5 * cos(pi * x)

kernel_radius

kernel_radius() -> int
Source code
287
288
289
@inject_self.cached.property
def kernel_radius(self) -> int:
    return ceil(self.taps)

multi

multi(
    clip: VideoNode,
    multi: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
272
273
274
275
276
277
278
279
280
281
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:

    import warnings

    warnings.warn('The "multi" method is deprecated. Use "supersample" instead.', DeprecationWarning)

    return self.supersample(clip, multi, shift, **kwargs)

pretty_string

pretty_string() -> str
Source code
225
226
227
@inject_self.cached.property
def pretty_string(self) -> str:
    return self._pretty_string()

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
438
439
440
441
442
443
444
445
446
@inject_self.cached
@inject_kwargs_params
def resample(
    self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None, matrix_in: MatrixT | None = None, **kwargs: Any
) -> ConstantFormatVideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

resample_function

resample_function(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    *args: Any,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
59
60
61
62
def resample_function(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode:
    return self.scale_function(clip, width, height, *args, **kwargs)  # type: ignore[return-value]

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
@inject_self.cached
@inject_kwargs_params
def scale(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    # `border_handling`, `sample_grid_model`, `sar`, `dar`, `dar_in` and `keep_ar` from KeepArScaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | float | bool | None = None, dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None, keep_ar: bool | None = None,
    # `linear` and `sigmoid` from LinearScaler
    linear: bool = False, sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> vs.VideoNode:
    width, height = Scaler._wh_norm(clip, width, height)
    return super().scale(
        clip, width, height, shift,
        border_handling=border_handling, sample_grid_model=sample_grid_model,
        sar=sar, dar=dar, dar_in=dar_in, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid,
        **kwargs
    )

scale_function

scale_function(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    *args: Any,
    **kwargs: Any
) -> VideoNode
Source code
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def scale_function(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None, *args: Any, **kwargs: Any
) -> vs.VideoNode:

    if not hasattr(core, 'resize2'):
        raise DependencyNotFoundError(
            self.__class__, 'resize2', 'Missing dependency \'resize2\'! '
            'You can find it here: https://github.com/Jaded-Encoding-Thaumaturgy/vapoursynth-resize2'
        )

    kernel, support = self._modify_kernel_func(kwargs)

    clean_kwargs = {
        k: v for k, v in kwargs.items()
        if k not in Signature.from_callable(self._modify_kernel_func).parameters.keys()
    }

    return core.resize2.Custom(clip, kernel, ceil(support), width, height, *args, **clean_kwargs)

shift

shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any,
) -> ConstantFormatVideoNode
Source code
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
@inject_self.cached
@inject_kwargs_params
def shift(
    self,
    clip: vs.VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any
) -> ConstantFormatVideoNode:
    assert check_variable_format(clip, self.shift)

    n_planes = clip.format.num_planes

    def _shift(src: VideoNodeT, shift: tuple[TopShift, LeftShift] = (0, 0)) -> VideoNodeT:
        return self.scale(src, src.width, src.height, shift, **kwargs)

    if not shifts_or_top and not shift_left:
        return _shift(clip)

    if isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)

    if isinstance(shifts_or_top, float) and isinstance(shift_left, float):
        return _shift(clip, (shifts_or_top, shift_left))

    if shifts_or_top is None:
        shifts_or_top = 0.0
    if shift_left is None:
        shift_left = 0.0

    shifts_top = shifts_or_top if isinstance(shifts_or_top, list) else [shifts_or_top]
    shifts_left = shift_left if isinstance(shift_left, list) else [shift_left]

    if not shifts_top:
        shifts_top = [0.0] * n_planes
    elif (ltop := len(shifts_top)) > n_planes:
        shifts_top = shifts_top[:n_planes]
    else:
        shifts_top += shifts_top[-1:] * (n_planes - ltop)

    if not shifts_left:
        shifts_left = [0.0] * n_planes
    elif (lleft := len(shifts_left)) > n_planes:
        shifts_left = shifts_left[:n_planes]
    else:
        shifts_left += shifts_left[-1:] * (n_planes - lleft)

    if len(set(shifts_top)) == len(set(shifts_left)) == 1 or n_planes == 1:
        return _shift(clip, (shifts_top[0], shifts_left[0]))

    planes = split(clip)

    shifted_planes = [
        plane if top == left == 0 else _shift(plane, (top, left))
        for plane, top, left in zip(planes, shifts_top, shifts_left)
    ]

    return core.std.ShufflePlanes(shifted_planes, [0, 0, 0], clip.format.color_family)

supersample

supersample(
    clip: VideoNode,
    rfactor: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
257
258
259
260
261
262
263
264
265
266
267
268
269
270
@inject_self.cached
def supersample(
    self, clip: vs.VideoNode, rfactor: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

    dst_width, dst_height = ceil(clip.width * rfactor), ceil(clip.height * rfactor)

    if max(dst_width, dst_height) <= 0.0:
        raise CustomValueError(
            'Multiplying the resolution by "rfactor" must result in a positive resolution!', self.supersample, rfactor
        )

    return self.scale(clip, dst_width, dst_height, shift, **kwargs)

Sinc

Sinc(taps: float = 4, **kwargs: Any)

Bases: CustomComplexTapsKernel

Sinc resizer.

Methods:

Attributes:

  • kwargs (KwargsT) –

    Arguments passed to the internal scale function

  • taps
Source code
107
108
def __init__(self, taps: float = 4, **kwargs: Any) -> None:
    super().__init__(taps, **kwargs)

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

taps instance-attribute

taps = taps

descale

descale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: ShiftT = (0, 0),
    *,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    field_based: FieldBased | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    blur: float = 1.0,
    ignore_mask: VideoNode | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
@inject_self.cached
@inject_kwargs_params
def descale(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: ShiftT = (0, 0),
    *,
    # `border_handling`, `sample_grid_model` and `field_based` from Descaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    field_based: FieldBased | None = None,
    # `linear` and `sigmoid` parameters from LinearDescaler
    linear: bool = False, sigmoid: bool | tuple[Slope, Center] = False,
    # `blur` and `ignore_mask` from CustomKernel
    blur: float = 1.0, ignore_mask: vs.VideoNode | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode
Source code
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def descale_function(
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode:
    kernel, support = self._modify_kernel_func(kwargs)

    clean_kwargs = {
        k: v for k, v in kwargs.items()
        if k not in Signature.from_callable(self._modify_kernel_func).parameters.keys()
    }

    try:
        return core.descale.Decustom(clip, width, height, kernel, ceil(support), *args, **clean_kwargs)
    except vs.Error as e:
        if 'Output dimension must be' in str(e):
            raise CustomValueError(
                f'Output dimension ({width}x{height}) must be less than or equal to '
                f'input dimension ({clip.width}x{clip.height}).', self.__class__
            )

        raise CustomValueError(e, self.__class__)

ensure_obj classmethod

ensure_obj(
    kernel: KernelT | None = ..., /, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: str | type[BaseScaler] | BaseScaler | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> BaseScaler
Source code
647
648
649
650
651
652
653
654
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: str | type[BaseScaler] | BaseScaler | None = None, /,
    func_except: FuncExceptT | None = None
) -> BaseScaler:
    return _base_ensure_obj(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = ..., /, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: str | type[BaseScaler] | BaseScaler | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> type[BaseScaler]
Source code
611
612
613
614
615
616
617
@classmethod
def from_param(
    cls, kernel: str | type[BaseScaler] | BaseScaler | None = None, /, func_except: FuncExceptT | None = None
) -> type[BaseScaler]:
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
216
217
def get_clean_kwargs(self, *funcs: Callable[..., Any] | None) -> KwargsT:
    return _clean_self_kwargs(funcs, self)

get_descale_args

get_descale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
673
674
675
676
677
678
679
680
681
682
683
@inject_kwargs_params
def get_descale_args(
    self, clip: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None, height: int | None = None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(src_top=shift[0], src_left=shift[1])
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(True, clip, width, height, **kwargs)
    )

get_implemented_funcs

get_implemented_funcs() -> tuple[Callable[..., Any], ...]
Source code
701
702
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )

get_params_args

get_params_args(
    is_descale: bool,
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]
Source code
85
86
87
88
89
90
91
92
93
94
def get_params_args(
    self, is_descale: bool, clip: vs.VideoNode, width: int | None = None, height: int | None = None, **kwargs: Any
) -> dict[str, Any]:
    args = super().get_params_args(is_descale, clip, width, height, **kwargs)

    if not is_descale:
        for key in ('border_handling', 'ignore_mask'):
            args.pop(key, None)

    return args

get_resample_args

get_resample_args(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None,
    matrix_in: MatrixT | None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
@inject_kwargs_params
def get_resample_args(
    self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None, matrix_in: MatrixT | None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(
            format=get_video_format(format).id,
            matrix=Matrix.from_param(matrix),
            matrix_in=Matrix.from_param(matrix_in)
        )
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(False, clip, **kwargs)
    )

get_scale_args

get_scale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
661
662
663
664
665
666
667
668
669
670
671
@inject_kwargs_params
def get_scale_args(
    self, clip: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None, height: int | None = None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(src_top=shift[0], src_left=shift[1])
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(False, clip, width, height, **kwargs)
    )

kernel

kernel(*, x: float) -> float
Source code
110
111
112
113
114
115
@inject_self.cached
def kernel(self, *, x: float) -> float:
    if x >= self.kernel_radius:
        return 0.0

    return sinc(x)

kernel_radius

kernel_radius() -> int
Source code
287
288
289
@inject_self.cached.property
def kernel_radius(self) -> int:
    return ceil(self.taps)

multi

multi(
    clip: VideoNode,
    multi: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
272
273
274
275
276
277
278
279
280
281
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:

    import warnings

    warnings.warn('The "multi" method is deprecated. Use "supersample" instead.', DeprecationWarning)

    return self.supersample(clip, multi, shift, **kwargs)

pretty_string

pretty_string() -> str
Source code
225
226
227
@inject_self.cached.property
def pretty_string(self) -> str:
    return self._pretty_string()

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
438
439
440
441
442
443
444
445
446
@inject_self.cached
@inject_kwargs_params
def resample(
    self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None, matrix_in: MatrixT | None = None, **kwargs: Any
) -> ConstantFormatVideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

resample_function

resample_function(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    *args: Any,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
59
60
61
62
def resample_function(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode:
    return self.scale_function(clip, width, height, *args, **kwargs)  # type: ignore[return-value]

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
@inject_self.cached
@inject_kwargs_params
def scale(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    # `border_handling`, `sample_grid_model`, `sar`, `dar`, `dar_in` and `keep_ar` from KeepArScaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | float | bool | None = None, dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None, keep_ar: bool | None = None,
    # `linear` and `sigmoid` from LinearScaler
    linear: bool = False, sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> vs.VideoNode:
    width, height = Scaler._wh_norm(clip, width, height)
    return super().scale(
        clip, width, height, shift,
        border_handling=border_handling, sample_grid_model=sample_grid_model,
        sar=sar, dar=dar, dar_in=dar_in, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid,
        **kwargs
    )

scale_function

scale_function(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    *args: Any,
    **kwargs: Any
) -> VideoNode
Source code
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def scale_function(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None, *args: Any, **kwargs: Any
) -> vs.VideoNode:

    if not hasattr(core, 'resize2'):
        raise DependencyNotFoundError(
            self.__class__, 'resize2', 'Missing dependency \'resize2\'! '
            'You can find it here: https://github.com/Jaded-Encoding-Thaumaturgy/vapoursynth-resize2'
        )

    kernel, support = self._modify_kernel_func(kwargs)

    clean_kwargs = {
        k: v for k, v in kwargs.items()
        if k not in Signature.from_callable(self._modify_kernel_func).parameters.keys()
    }

    return core.resize2.Custom(clip, kernel, ceil(support), width, height, *args, **clean_kwargs)

shift

shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any,
) -> ConstantFormatVideoNode
Source code
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
@inject_self.cached
@inject_kwargs_params
def shift(
    self,
    clip: vs.VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any
) -> ConstantFormatVideoNode:
    assert check_variable_format(clip, self.shift)

    n_planes = clip.format.num_planes

    def _shift(src: VideoNodeT, shift: tuple[TopShift, LeftShift] = (0, 0)) -> VideoNodeT:
        return self.scale(src, src.width, src.height, shift, **kwargs)

    if not shifts_or_top and not shift_left:
        return _shift(clip)

    if isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)

    if isinstance(shifts_or_top, float) and isinstance(shift_left, float):
        return _shift(clip, (shifts_or_top, shift_left))

    if shifts_or_top is None:
        shifts_or_top = 0.0
    if shift_left is None:
        shift_left = 0.0

    shifts_top = shifts_or_top if isinstance(shifts_or_top, list) else [shifts_or_top]
    shifts_left = shift_left if isinstance(shift_left, list) else [shift_left]

    if not shifts_top:
        shifts_top = [0.0] * n_planes
    elif (ltop := len(shifts_top)) > n_planes:
        shifts_top = shifts_top[:n_planes]
    else:
        shifts_top += shifts_top[-1:] * (n_planes - ltop)

    if not shifts_left:
        shifts_left = [0.0] * n_planes
    elif (lleft := len(shifts_left)) > n_planes:
        shifts_left = shifts_left[:n_planes]
    else:
        shifts_left += shifts_left[-1:] * (n_planes - lleft)

    if len(set(shifts_top)) == len(set(shifts_left)) == 1 or n_planes == 1:
        return _shift(clip, (shifts_top[0], shifts_left[0]))

    planes = split(clip)

    shifted_planes = [
        plane if top == left == 0 else _shift(plane, (top, left))
        for plane, top, left in zip(planes, shifts_top, shifts_left)
    ]

    return core.std.ShufflePlanes(shifted_planes, [0, 0, 0], clip.format.color_family)

supersample

supersample(
    clip: VideoNode,
    rfactor: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
257
258
259
260
261
262
263
264
265
266
267
268
269
270
@inject_self.cached
def supersample(
    self, clip: vs.VideoNode, rfactor: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

    dst_width, dst_height = ceil(clip.width * rfactor), ceil(clip.height * rfactor)

    if max(dst_width, dst_height) <= 0.0:
        raise CustomValueError(
            'Multiplying the resolution by "rfactor" must result in a positive resolution!', self.supersample, rfactor
        )

    return self.scale(clip, dst_width, dst_height, shift, **kwargs)

Welch

Welch(taps: float, **kwargs: Any)

Bases: CustomComplexTapsKernel

Welch kernel.

Methods:

Attributes:

  • kwargs (KwargsT) –

    Arguments passed to the internal scale function

  • taps
Source code
283
284
285
def __init__(self, taps: float, **kwargs: Any) -> None:
    self.taps = taps
    super().__init__(**kwargs)

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

taps instance-attribute

taps = taps

descale

descale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: ShiftT = (0, 0),
    *,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    field_based: FieldBased | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    blur: float = 1.0,
    ignore_mask: VideoNode | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
@inject_self.cached
@inject_kwargs_params
def descale(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: ShiftT = (0, 0),
    *,
    # `border_handling`, `sample_grid_model` and `field_based` from Descaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    field_based: FieldBased | None = None,
    # `linear` and `sigmoid` parameters from LinearDescaler
    linear: bool = False, sigmoid: bool | tuple[Slope, Center] = False,
    # `blur` and `ignore_mask` from CustomKernel
    blur: float = 1.0, ignore_mask: vs.VideoNode | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode
Source code
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def descale_function(
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode:
    kernel, support = self._modify_kernel_func(kwargs)

    clean_kwargs = {
        k: v for k, v in kwargs.items()
        if k not in Signature.from_callable(self._modify_kernel_func).parameters.keys()
    }

    try:
        return core.descale.Decustom(clip, width, height, kernel, ceil(support), *args, **clean_kwargs)
    except vs.Error as e:
        if 'Output dimension must be' in str(e):
            raise CustomValueError(
                f'Output dimension ({width}x{height}) must be less than or equal to '
                f'input dimension ({clip.width}x{clip.height}).', self.__class__
            )

        raise CustomValueError(e, self.__class__)

ensure_obj classmethod

ensure_obj(
    kernel: KernelT | None = ..., /, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: str | type[BaseScaler] | BaseScaler | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> BaseScaler
Source code
647
648
649
650
651
652
653
654
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: str | type[BaseScaler] | BaseScaler | None = None, /,
    func_except: FuncExceptT | None = None
) -> BaseScaler:
    return _base_ensure_obj(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = ..., /, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = ...,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: str | type[BaseScaler] | BaseScaler | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> type[BaseScaler]
Source code
611
612
613
614
615
616
617
@classmethod
def from_param(
    cls, kernel: str | type[BaseScaler] | BaseScaler | None = None, /, func_except: FuncExceptT | None = None
) -> type[BaseScaler]:
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
216
217
def get_clean_kwargs(self, *funcs: Callable[..., Any] | None) -> KwargsT:
    return _clean_self_kwargs(funcs, self)

get_descale_args

get_descale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
673
674
675
676
677
678
679
680
681
682
683
@inject_kwargs_params
def get_descale_args(
    self, clip: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None, height: int | None = None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(src_top=shift[0], src_left=shift[1])
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(True, clip, width, height, **kwargs)
    )

get_implemented_funcs

get_implemented_funcs() -> tuple[Callable[..., Any], ...]
Source code
701
702
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )

get_params_args

get_params_args(
    is_descale: bool,
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]
Source code
85
86
87
88
89
90
91
92
93
94
def get_params_args(
    self, is_descale: bool, clip: vs.VideoNode, width: int | None = None, height: int | None = None, **kwargs: Any
) -> dict[str, Any]:
    args = super().get_params_args(is_descale, clip, width, height, **kwargs)

    if not is_descale:
        for key in ('border_handling', 'ignore_mask'):
            args.pop(key, None)

    return args

get_resample_args

get_resample_args(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None,
    matrix_in: MatrixT | None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
@inject_kwargs_params
def get_resample_args(
    self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None, matrix_in: MatrixT | None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(
            format=get_video_format(format).id,
            matrix=Matrix.from_param(matrix),
            matrix_in=Matrix.from_param(matrix_in)
        )
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(False, clip, **kwargs)
    )

get_scale_args

get_scale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
661
662
663
664
665
666
667
668
669
670
671
@inject_kwargs_params
def get_scale_args(
    self, clip: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None, height: int | None = None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(src_top=shift[0], src_left=shift[1])
        | self.get_clean_kwargs(*funcs)
        | self.get_params_args(False, clip, width, height, **kwargs)
    )

kernel

kernel(*, x: float) -> float
Source code
143
144
145
146
147
148
@inject_self.cached
def kernel(self, *, x: float) -> float:
    if abs(x) >= 1.0:
        return 0.0

    return 1.0 - x * x

kernel_radius

kernel_radius() -> int
Source code
287
288
289
@inject_self.cached.property
def kernel_radius(self) -> int:
    return ceil(self.taps)

multi

multi(
    clip: VideoNode,
    multi: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
272
273
274
275
276
277
278
279
280
281
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:

    import warnings

    warnings.warn('The "multi" method is deprecated. Use "supersample" instead.', DeprecationWarning)

    return self.supersample(clip, multi, shift, **kwargs)

pretty_string

pretty_string() -> str
Source code
225
226
227
@inject_self.cached.property
def pretty_string(self) -> str:
    return self._pretty_string()

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
438
439
440
441
442
443
444
445
446
@inject_self.cached
@inject_kwargs_params
def resample(
    self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None, matrix_in: MatrixT | None = None, **kwargs: Any
) -> ConstantFormatVideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

resample_function

resample_function(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    *args: Any,
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
59
60
61
62
def resample_function(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None, *args: Any, **kwargs: Any
) -> ConstantFormatVideoNode:
    return self.scale_function(clip, width, height, *args, **kwargs)  # type: ignore[return-value]

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
@inject_self.cached
@inject_kwargs_params
def scale(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    # `border_handling`, `sample_grid_model`, `sar`, `dar`, `dar_in` and `keep_ar` from KeepArScaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | float | bool | None = None, dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None, keep_ar: bool | None = None,
    # `linear` and `sigmoid` from LinearScaler
    linear: bool = False, sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> vs.VideoNode:
    width, height = Scaler._wh_norm(clip, width, height)
    return super().scale(
        clip, width, height, shift,
        border_handling=border_handling, sample_grid_model=sample_grid_model,
        sar=sar, dar=dar, dar_in=dar_in, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid,
        **kwargs
    )

scale_function

scale_function(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    *args: Any,
    **kwargs: Any
) -> VideoNode
Source code
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def scale_function(
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None, *args: Any, **kwargs: Any
) -> vs.VideoNode:

    if not hasattr(core, 'resize2'):
        raise DependencyNotFoundError(
            self.__class__, 'resize2', 'Missing dependency \'resize2\'! '
            'You can find it here: https://github.com/Jaded-Encoding-Thaumaturgy/vapoursynth-resize2'
        )

    kernel, support = self._modify_kernel_func(kwargs)

    clean_kwargs = {
        k: v for k, v in kwargs.items()
        if k not in Signature.from_callable(self._modify_kernel_func).parameters.keys()
    }

    return core.resize2.Custom(clip, kernel, ceil(support), width, height, *args, **clean_kwargs)

shift

shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any,
) -> ConstantFormatVideoNode
Source code
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
@inject_self.cached
@inject_kwargs_params
def shift(
    self,
    clip: vs.VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any
) -> ConstantFormatVideoNode:
    assert check_variable_format(clip, self.shift)

    n_planes = clip.format.num_planes

    def _shift(src: VideoNodeT, shift: tuple[TopShift, LeftShift] = (0, 0)) -> VideoNodeT:
        return self.scale(src, src.width, src.height, shift, **kwargs)

    if not shifts_or_top and not shift_left:
        return _shift(clip)

    if isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)

    if isinstance(shifts_or_top, float) and isinstance(shift_left, float):
        return _shift(clip, (shifts_or_top, shift_left))

    if shifts_or_top is None:
        shifts_or_top = 0.0
    if shift_left is None:
        shift_left = 0.0

    shifts_top = shifts_or_top if isinstance(shifts_or_top, list) else [shifts_or_top]
    shifts_left = shift_left if isinstance(shift_left, list) else [shift_left]

    if not shifts_top:
        shifts_top = [0.0] * n_planes
    elif (ltop := len(shifts_top)) > n_planes:
        shifts_top = shifts_top[:n_planes]
    else:
        shifts_top += shifts_top[-1:] * (n_planes - ltop)

    if not shifts_left:
        shifts_left = [0.0] * n_planes
    elif (lleft := len(shifts_left)) > n_planes:
        shifts_left = shifts_left[:n_planes]
    else:
        shifts_left += shifts_left[-1:] * (n_planes - lleft)

    if len(set(shifts_top)) == len(set(shifts_left)) == 1 or n_planes == 1:
        return _shift(clip, (shifts_top[0], shifts_left[0]))

    planes = split(clip)

    shifted_planes = [
        plane if top == left == 0 else _shift(plane, (top, left))
        for plane, top, left in zip(planes, shifts_top, shifts_left)
    ]

    return core.std.ShufflePlanes(shifted_planes, [0, 0, 0], clip.format.color_family)

supersample

supersample(
    clip: VideoNode,
    rfactor: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
257
258
259
260
261
262
263
264
265
266
267
268
269
270
@inject_self.cached
def supersample(
    self, clip: vs.VideoNode, rfactor: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

    dst_width, dst_height = ceil(clip.width * rfactor), ceil(clip.height * rfactor)

    if max(dst_width, dst_height) <= 0.0:
        raise CustomValueError(
            'Multiplying the resolution by "rfactor" must result in a positive resolution!', self.supersample, rfactor
        )

    return self.scale(clip, dst_width, dst_height, shift, **kwargs)

gauss_sigma

Bases: float

Methods:

from_fmtc

from_fmtc(curve: float) -> float
Source code
26
27
28
29
def from_fmtc(self, curve: float) -> float:
    if not curve:
        return 0.0
    return sqrt(1.0 / (2.0 * (curve / 10.0) * log(2)))

from_libplacebo

from_libplacebo(sigma: float) -> float
Source code
36
37
38
39
def from_libplacebo(self, sigma: float) -> float:
    if not sigma:
        return 0.0
    return sqrt(sigma / 4)

to_fmtc

to_fmtc(sigma: float) -> float
Source code
31
32
33
34
def to_fmtc(self, sigma: float) -> float:
    if not sigma:
        return 0.0
    return 10 / (2 * log(2) * (sigma ** 2))

to_libplacebo

to_libplacebo(sigma: float) -> float
Source code
41
42
43
44
def to_libplacebo(self, sigma: float) -> float:
    if not sigma:
        return 0.0
    return 4 * (sigma ** 2)