Skip to content

bicubic

AdobeBicubic

AdobeBicubic(**kwargs: Any)

Bases: Bicubic

Bicubic b=0, c=0.75; Adobe's "Bicubic" interpolation preset

Source code
101
102
def __init__(self, **kwargs: Any) -> None:
    super().__init__(b=0, c=3 / 4, **kwargs)

b instance-attribute

b = b

c instance-attribute

c = c

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

resample_function class-attribute instance-attribute

resample_function = scale_function

descale

descale(
    clip: VideoNode,
    width: int,
    height: int,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    blur: float = 1.0,
    border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    ignore_mask: VideoNode | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
@inject_kwargs_params
def descale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, shift: tuple[TopShift, LeftShift] = (0, 0),
    *, blur: float = 1.0, border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    ignore_mask: vs.VideoNode | None = None, linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False, **kwargs: Any
) -> vs.VideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> VideoNode
Source code
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@inject_self
def descale_function(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> vs.VideoNode:
    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 = None, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler | Descaler | Resampler | Kernel
Source code
548
549
550
551
552
553
554
555
556
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> Scaler | Descaler | Resampler | Kernel:
    from ..util import abstract_kernels
    return _base_ensure_obj(  # type: ignore
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = None, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]
Source code
510
511
512
513
514
515
516
517
518
@classmethod
def from_param(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]:
    from ..util import abstract_kernels
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except  # type: ignore
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
199
200
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
575
576
577
578
579
580
581
582
583
584
585
@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
603
604
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )  # type: ignore

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
84
85
86
87
88
89
90
91
92
93
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
@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
563
564
565
566
567
568
569
570
571
572
573
@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
44
45
46
47
48
49
50
51
52
53
54
@inject_self.cached
def kernel(self, *, x: float) -> float:
    x, b, c = abs(x), self.b, self.c

    if (x < 1.0):
        return poly3(x, bic_vals.p0(b, c), 0.0, bic_vals.p2(b, c), bic_vals.p3(b, c))

    if (x < 2.0):
        return poly3(x, bic_vals.q0(b, c), bic_vals.q1(b, c), bic_vals.q2(b, c), bic_vals.q3(b, c))

    return 0.0

kernel_radius

kernel_radius() -> int
Source code
56
57
58
59
60
@inject_self.cached.property
def kernel_radius(self) -> int:  # type: ignore
    if (self.b, self.c) == (0, 0):
        return 1
    return 2

multi

multi(
    clip: VideoNode,
    multi: float = 2,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
239
240
241
242
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

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

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

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

pretty_string

pretty_string() -> str
Source code
202
203
204
205
206
207
208
209
210
211
212
213
214
@inject_self.cached.property
def pretty_string(self) -> str:
    attrs = {}

    if hasattr(self, 'b'):
        attrs.update(b=self.b, c=self.c)
    elif hasattr(self, 'taps'):
        attrs['taps'] = self.taps

    if hasattr(self, 'kwargs'):
        attrs.update(self.kwargs)

    return f"{self.__class__.__name__}{' (' + ', '.join(f'{k}={v}' for k, v in attrs.items()) + ')' if attrs else ''}"

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> VideoNode
Source code
376
377
378
379
380
381
382
383
384
@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
) -> vs.VideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

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 | bool | float | None = None,
    dar: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
@inject_self.cached
@inject_kwargs_params
def scale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | bool | float | None = None, dar: Dar | bool | float | None = None, keep_ar: bool | None = None,
    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, sar=sar, dar=dar, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid, border_handling=border_handling,
        sample_grid_model=sample_grid_model, **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
58
@inject_self
def scale_function(  # type: ignore[override]
    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, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shift_top: float | list[float] = 0.0,
    shift_left: float | list[float] = 0.0,
    **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    **kwargs: Any
) -> VideoNode
Source code
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
@inject_self.cached  # type: ignore
@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
) -> vs.VideoNode:
    assert clip.format

    n_planes = clip.format.num_planes

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

    if not shifts_or_top and not shift_left:
        return _shift(clip)
    elif isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)
    elif 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 = cast(list[vs.VideoNode], clip.std.SplitPlanes())

    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)

AdobeBicubicSharper

AdobeBicubicSharper(**kwargs: Any)

Bases: Bicubic

Bicubic b=0, c=1, blur=1.05; Adobe's "Bicubic Sharper" interpolation preset.

Source code
108
109
def __init__(self, **kwargs: Any) -> None:
    super().__init__(b=0, c=1, blur=1.05, **kwargs)

b instance-attribute

b = b

c instance-attribute

c = c

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

resample_function class-attribute instance-attribute

resample_function = scale_function

descale

descale(
    clip: VideoNode,
    width: int,
    height: int,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    blur: float = 1.0,
    border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    ignore_mask: VideoNode | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
@inject_kwargs_params
def descale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, shift: tuple[TopShift, LeftShift] = (0, 0),
    *, blur: float = 1.0, border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    ignore_mask: vs.VideoNode | None = None, linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False, **kwargs: Any
) -> vs.VideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> VideoNode
Source code
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@inject_self
def descale_function(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> vs.VideoNode:
    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 = None, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler | Descaler | Resampler | Kernel
Source code
548
549
550
551
552
553
554
555
556
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> Scaler | Descaler | Resampler | Kernel:
    from ..util import abstract_kernels
    return _base_ensure_obj(  # type: ignore
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = None, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]
Source code
510
511
512
513
514
515
516
517
518
@classmethod
def from_param(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]:
    from ..util import abstract_kernels
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except  # type: ignore
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
199
200
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
575
576
577
578
579
580
581
582
583
584
585
@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
603
604
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )  # type: ignore

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
84
85
86
87
88
89
90
91
92
93
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
@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
563
564
565
566
567
568
569
570
571
572
573
@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
44
45
46
47
48
49
50
51
52
53
54
@inject_self.cached
def kernel(self, *, x: float) -> float:
    x, b, c = abs(x), self.b, self.c

    if (x < 1.0):
        return poly3(x, bic_vals.p0(b, c), 0.0, bic_vals.p2(b, c), bic_vals.p3(b, c))

    if (x < 2.0):
        return poly3(x, bic_vals.q0(b, c), bic_vals.q1(b, c), bic_vals.q2(b, c), bic_vals.q3(b, c))

    return 0.0

kernel_radius

kernel_radius() -> int
Source code
56
57
58
59
60
@inject_self.cached.property
def kernel_radius(self) -> int:  # type: ignore
    if (self.b, self.c) == (0, 0):
        return 1
    return 2

multi

multi(
    clip: VideoNode,
    multi: float = 2,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
239
240
241
242
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

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

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

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

pretty_string

pretty_string() -> str
Source code
202
203
204
205
206
207
208
209
210
211
212
213
214
@inject_self.cached.property
def pretty_string(self) -> str:
    attrs = {}

    if hasattr(self, 'b'):
        attrs.update(b=self.b, c=self.c)
    elif hasattr(self, 'taps'):
        attrs['taps'] = self.taps

    if hasattr(self, 'kwargs'):
        attrs.update(self.kwargs)

    return f"{self.__class__.__name__}{' (' + ', '.join(f'{k}={v}' for k, v in attrs.items()) + ')' if attrs else ''}"

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> VideoNode
Source code
376
377
378
379
380
381
382
383
384
@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
) -> vs.VideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

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 | bool | float | None = None,
    dar: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
@inject_self.cached
@inject_kwargs_params
def scale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | bool | float | None = None, dar: Dar | bool | float | None = None, keep_ar: bool | None = None,
    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, sar=sar, dar=dar, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid, border_handling=border_handling,
        sample_grid_model=sample_grid_model, **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
58
@inject_self
def scale_function(  # type: ignore[override]
    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, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shift_top: float | list[float] = 0.0,
    shift_left: float | list[float] = 0.0,
    **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    **kwargs: Any
) -> VideoNode
Source code
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
@inject_self.cached  # type: ignore
@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
) -> vs.VideoNode:
    assert clip.format

    n_planes = clip.format.num_planes

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

    if not shifts_or_top and not shift_left:
        return _shift(clip)
    elif isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)
    elif 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 = cast(list[vs.VideoNode], clip.std.SplitPlanes())

    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)

AdobeBicubicSmoother

AdobeBicubicSmoother(**kwargs: Any)

Bases: Bicubic

Bicubic b=0, c=0.625, blur=1.15; Adobe's "Bicubic Smoother" interpolation preset.

Source code
115
116
def __init__(self, **kwargs: Any) -> None:
    super().__init__(b=0, c=5 / 8, blur=1.15, **kwargs)

b instance-attribute

b = b

c instance-attribute

c = c

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

resample_function class-attribute instance-attribute

resample_function = scale_function

descale

descale(
    clip: VideoNode,
    width: int,
    height: int,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    blur: float = 1.0,
    border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    ignore_mask: VideoNode | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
@inject_kwargs_params
def descale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, shift: tuple[TopShift, LeftShift] = (0, 0),
    *, blur: float = 1.0, border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    ignore_mask: vs.VideoNode | None = None, linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False, **kwargs: Any
) -> vs.VideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> VideoNode
Source code
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@inject_self
def descale_function(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> vs.VideoNode:
    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 = None, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler | Descaler | Resampler | Kernel
Source code
548
549
550
551
552
553
554
555
556
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> Scaler | Descaler | Resampler | Kernel:
    from ..util import abstract_kernels
    return _base_ensure_obj(  # type: ignore
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = None, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]
Source code
510
511
512
513
514
515
516
517
518
@classmethod
def from_param(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]:
    from ..util import abstract_kernels
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except  # type: ignore
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
199
200
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
575
576
577
578
579
580
581
582
583
584
585
@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
603
604
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )  # type: ignore

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
84
85
86
87
88
89
90
91
92
93
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
@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
563
564
565
566
567
568
569
570
571
572
573
@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
44
45
46
47
48
49
50
51
52
53
54
@inject_self.cached
def kernel(self, *, x: float) -> float:
    x, b, c = abs(x), self.b, self.c

    if (x < 1.0):
        return poly3(x, bic_vals.p0(b, c), 0.0, bic_vals.p2(b, c), bic_vals.p3(b, c))

    if (x < 2.0):
        return poly3(x, bic_vals.q0(b, c), bic_vals.q1(b, c), bic_vals.q2(b, c), bic_vals.q3(b, c))

    return 0.0

kernel_radius

kernel_radius() -> int
Source code
56
57
58
59
60
@inject_self.cached.property
def kernel_radius(self) -> int:  # type: ignore
    if (self.b, self.c) == (0, 0):
        return 1
    return 2

multi

multi(
    clip: VideoNode,
    multi: float = 2,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
239
240
241
242
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

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

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

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

pretty_string

pretty_string() -> str
Source code
202
203
204
205
206
207
208
209
210
211
212
213
214
@inject_self.cached.property
def pretty_string(self) -> str:
    attrs = {}

    if hasattr(self, 'b'):
        attrs.update(b=self.b, c=self.c)
    elif hasattr(self, 'taps'):
        attrs['taps'] = self.taps

    if hasattr(self, 'kwargs'):
        attrs.update(self.kwargs)

    return f"{self.__class__.__name__}{' (' + ', '.join(f'{k}={v}' for k, v in attrs.items()) + ')' if attrs else ''}"

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> VideoNode
Source code
376
377
378
379
380
381
382
383
384
@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
) -> vs.VideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

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 | bool | float | None = None,
    dar: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
@inject_self.cached
@inject_kwargs_params
def scale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | bool | float | None = None, dar: Dar | bool | float | None = None, keep_ar: bool | None = None,
    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, sar=sar, dar=dar, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid, border_handling=border_handling,
        sample_grid_model=sample_grid_model, **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
58
@inject_self
def scale_function(  # type: ignore[override]
    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, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shift_top: float | list[float] = 0.0,
    shift_left: float | list[float] = 0.0,
    **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    **kwargs: Any
) -> VideoNode
Source code
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
@inject_self.cached  # type: ignore
@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
) -> vs.VideoNode:
    assert clip.format

    n_planes = clip.format.num_planes

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

    if not shifts_or_top and not shift_left:
        return _shift(clip)
    elif isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)
    elif 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 = cast(list[vs.VideoNode], clip.std.SplitPlanes())

    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)

BSpline

BSpline(**kwargs: Any)

Bases: Bicubic

Bicubic b=1, c=0

Source code
66
67
def __init__(self, **kwargs: Any) -> None:
    super().__init__(b=1, c=0, **kwargs)

b instance-attribute

b = b

c instance-attribute

c = c

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

resample_function class-attribute instance-attribute

resample_function = scale_function

descale

descale(
    clip: VideoNode,
    width: int,
    height: int,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    blur: float = 1.0,
    border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    ignore_mask: VideoNode | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
@inject_kwargs_params
def descale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, shift: tuple[TopShift, LeftShift] = (0, 0),
    *, blur: float = 1.0, border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    ignore_mask: vs.VideoNode | None = None, linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False, **kwargs: Any
) -> vs.VideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> VideoNode
Source code
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@inject_self
def descale_function(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> vs.VideoNode:
    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 = None, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler | Descaler | Resampler | Kernel
Source code
548
549
550
551
552
553
554
555
556
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> Scaler | Descaler | Resampler | Kernel:
    from ..util import abstract_kernels
    return _base_ensure_obj(  # type: ignore
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = None, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]
Source code
510
511
512
513
514
515
516
517
518
@classmethod
def from_param(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]:
    from ..util import abstract_kernels
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except  # type: ignore
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
199
200
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
575
576
577
578
579
580
581
582
583
584
585
@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
603
604
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )  # type: ignore

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
84
85
86
87
88
89
90
91
92
93
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
@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
563
564
565
566
567
568
569
570
571
572
573
@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
44
45
46
47
48
49
50
51
52
53
54
@inject_self.cached
def kernel(self, *, x: float) -> float:
    x, b, c = abs(x), self.b, self.c

    if (x < 1.0):
        return poly3(x, bic_vals.p0(b, c), 0.0, bic_vals.p2(b, c), bic_vals.p3(b, c))

    if (x < 2.0):
        return poly3(x, bic_vals.q0(b, c), bic_vals.q1(b, c), bic_vals.q2(b, c), bic_vals.q3(b, c))

    return 0.0

kernel_radius

kernel_radius() -> int
Source code
56
57
58
59
60
@inject_self.cached.property
def kernel_radius(self) -> int:  # type: ignore
    if (self.b, self.c) == (0, 0):
        return 1
    return 2

multi

multi(
    clip: VideoNode,
    multi: float = 2,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
239
240
241
242
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

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

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

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

pretty_string

pretty_string() -> str
Source code
202
203
204
205
206
207
208
209
210
211
212
213
214
@inject_self.cached.property
def pretty_string(self) -> str:
    attrs = {}

    if hasattr(self, 'b'):
        attrs.update(b=self.b, c=self.c)
    elif hasattr(self, 'taps'):
        attrs['taps'] = self.taps

    if hasattr(self, 'kwargs'):
        attrs.update(self.kwargs)

    return f"{self.__class__.__name__}{' (' + ', '.join(f'{k}={v}' for k, v in attrs.items()) + ')' if attrs else ''}"

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> VideoNode
Source code
376
377
378
379
380
381
382
383
384
@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
) -> vs.VideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

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 | bool | float | None = None,
    dar: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
@inject_self.cached
@inject_kwargs_params
def scale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | bool | float | None = None, dar: Dar | bool | float | None = None, keep_ar: bool | None = None,
    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, sar=sar, dar=dar, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid, border_handling=border_handling,
        sample_grid_model=sample_grid_model, **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
58
@inject_self
def scale_function(  # type: ignore[override]
    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, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shift_top: float | list[float] = 0.0,
    shift_left: float | list[float] = 0.0,
    **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    **kwargs: Any
) -> VideoNode
Source code
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
@inject_self.cached  # type: ignore
@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
) -> vs.VideoNode:
    assert clip.format

    n_planes = clip.format.num_planes

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

    if not shifts_or_top and not shift_left:
        return _shift(clip)
    elif isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)
    elif 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 = cast(list[vs.VideoNode], clip.std.SplitPlanes())

    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)

Bicubic

Bicubic(b: float = 0, c: float = 1 / 2, **kwargs: Any)

Bases: CustomComplexKernel

Built-in bicubic resizer.

Default: b=0, c=0.5

Parameters:

  • b

    (float, default: 0 ) –

    B-param for bicubic kernel

  • c

    (float, default: 1 / 2 ) –

    C-param for bicubic kernel

Source code
39
40
41
42
def __init__(self, b: float = 0, c: float = 1 / 2, **kwargs: Any) -> None:
    self.b = b
    self.c = c
    super().__init__(**kwargs)

b instance-attribute

b = b

c instance-attribute

c = c

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

resample_function class-attribute instance-attribute

resample_function = scale_function

descale

descale(
    clip: VideoNode,
    width: int,
    height: int,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    blur: float = 1.0,
    border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    ignore_mask: VideoNode | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
@inject_kwargs_params
def descale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, shift: tuple[TopShift, LeftShift] = (0, 0),
    *, blur: float = 1.0, border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    ignore_mask: vs.VideoNode | None = None, linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False, **kwargs: Any
) -> vs.VideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> VideoNode
Source code
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@inject_self
def descale_function(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> vs.VideoNode:
    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 = None, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler | Descaler | Resampler | Kernel
Source code
548
549
550
551
552
553
554
555
556
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> Scaler | Descaler | Resampler | Kernel:
    from ..util import abstract_kernels
    return _base_ensure_obj(  # type: ignore
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = None, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]
Source code
510
511
512
513
514
515
516
517
518
@classmethod
def from_param(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]:
    from ..util import abstract_kernels
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except  # type: ignore
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
199
200
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
575
576
577
578
579
580
581
582
583
584
585
@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
603
604
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )  # type: ignore

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
84
85
86
87
88
89
90
91
92
93
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
@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
563
564
565
566
567
568
569
570
571
572
573
@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
44
45
46
47
48
49
50
51
52
53
54
@inject_self.cached
def kernel(self, *, x: float) -> float:
    x, b, c = abs(x), self.b, self.c

    if (x < 1.0):
        return poly3(x, bic_vals.p0(b, c), 0.0, bic_vals.p2(b, c), bic_vals.p3(b, c))

    if (x < 2.0):
        return poly3(x, bic_vals.q0(b, c), bic_vals.q1(b, c), bic_vals.q2(b, c), bic_vals.q3(b, c))

    return 0.0

kernel_radius

kernel_radius() -> int
Source code
56
57
58
59
60
@inject_self.cached.property
def kernel_radius(self) -> int:  # type: ignore
    if (self.b, self.c) == (0, 0):
        return 1
    return 2

multi

multi(
    clip: VideoNode,
    multi: float = 2,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
239
240
241
242
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

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

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

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

pretty_string

pretty_string() -> str
Source code
202
203
204
205
206
207
208
209
210
211
212
213
214
@inject_self.cached.property
def pretty_string(self) -> str:
    attrs = {}

    if hasattr(self, 'b'):
        attrs.update(b=self.b, c=self.c)
    elif hasattr(self, 'taps'):
        attrs['taps'] = self.taps

    if hasattr(self, 'kwargs'):
        attrs.update(self.kwargs)

    return f"{self.__class__.__name__}{' (' + ', '.join(f'{k}={v}' for k, v in attrs.items()) + ')' if attrs else ''}"

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> VideoNode
Source code
376
377
378
379
380
381
382
383
384
@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
) -> vs.VideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

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 | bool | float | None = None,
    dar: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
@inject_self.cached
@inject_kwargs_params
def scale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | bool | float | None = None, dar: Dar | bool | float | None = None, keep_ar: bool | None = None,
    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, sar=sar, dar=dar, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid, border_handling=border_handling,
        sample_grid_model=sample_grid_model, **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
58
@inject_self
def scale_function(  # type: ignore[override]
    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, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shift_top: float | list[float] = 0.0,
    shift_left: float | list[float] = 0.0,
    **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    **kwargs: Any
) -> VideoNode
Source code
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
@inject_self.cached  # type: ignore
@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
) -> vs.VideoNode:
    assert clip.format

    n_planes = clip.format.num_planes

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

    if not shifts_or_top and not shift_left:
        return _shift(clip)
    elif isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)
    elif 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 = cast(list[vs.VideoNode], clip.std.SplitPlanes())

    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)

BicubicAuto

BicubicAuto(b: float | None = None, c: float | None = None, **kwargs: Any)

Bases: Bicubic

Kernel that follows the rule of: b + 2c = target

Source code
159
160
161
162
163
164
165
def __init__(self, b: float | None = None, c: float | None = None, **kwargs: Any) -> None:
    if None not in {b, c}:
        raise CustomValueError("You can't specify both b and c!", self.__class__)

    self.b, self.c = self._get_bc_args(b, c)

    super().__init__(**kwargs)

b instance-attribute

b = b

c instance-attribute

c = c

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

resample_function class-attribute instance-attribute

resample_function = scale_function

descale

descale(
    clip: VideoNode,
    width: int,
    height: int,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    blur: float = 1.0,
    border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    ignore_mask: VideoNode | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
@inject_kwargs_params
def descale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, shift: tuple[TopShift, LeftShift] = (0, 0),
    *, blur: float = 1.0, border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    ignore_mask: vs.VideoNode | None = None, linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False, **kwargs: Any
) -> vs.VideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> VideoNode
Source code
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@inject_self
def descale_function(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> vs.VideoNode:
    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 = None, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler | Descaler | Resampler | Kernel
Source code
548
549
550
551
552
553
554
555
556
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> Scaler | Descaler | Resampler | Kernel:
    from ..util import abstract_kernels
    return _base_ensure_obj(  # type: ignore
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = None, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]
Source code
510
511
512
513
514
515
516
517
518
@classmethod
def from_param(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]:
    from ..util import abstract_kernels
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except  # type: ignore
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
199
200
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
575
576
577
578
579
580
581
582
583
584
585
@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
603
604
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )  # type: ignore

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
84
85
86
87
88
89
90
91
92
93
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
@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
563
564
565
566
567
568
569
570
571
572
573
@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
44
45
46
47
48
49
50
51
52
53
54
@inject_self.cached
def kernel(self, *, x: float) -> float:
    x, b, c = abs(x), self.b, self.c

    if (x < 1.0):
        return poly3(x, bic_vals.p0(b, c), 0.0, bic_vals.p2(b, c), bic_vals.p3(b, c))

    if (x < 2.0):
        return poly3(x, bic_vals.q0(b, c), bic_vals.q1(b, c), bic_vals.q2(b, c), bic_vals.q3(b, c))

    return 0.0

kernel_radius

kernel_radius() -> int
Source code
56
57
58
59
60
@inject_self.cached.property
def kernel_radius(self) -> int:  # type: ignore
    if (self.b, self.c) == (0, 0):
        return 1
    return 2

multi

multi(
    clip: VideoNode,
    multi: float = 2,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
239
240
241
242
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

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

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

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

pretty_string

pretty_string() -> str
Source code
202
203
204
205
206
207
208
209
210
211
212
213
214
@inject_self.cached.property
def pretty_string(self) -> str:
    attrs = {}

    if hasattr(self, 'b'):
        attrs.update(b=self.b, c=self.c)
    elif hasattr(self, 'taps'):
        attrs['taps'] = self.taps

    if hasattr(self, 'kwargs'):
        attrs.update(self.kwargs)

    return f"{self.__class__.__name__}{' (' + ', '.join(f'{k}={v}' for k, v in attrs.items()) + ')' if attrs else ''}"

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> VideoNode
Source code
376
377
378
379
380
381
382
383
384
@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
) -> vs.VideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

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 | bool | float | None = None,
    dar: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
@inject_self.cached
@inject_kwargs_params
def scale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | bool | float | None = None, dar: Dar | bool | float | None = None, keep_ar: bool | None = None,
    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, sar=sar, dar=dar, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid, border_handling=border_handling,
        sample_grid_model=sample_grid_model, **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
58
@inject_self
def scale_function(  # type: ignore[override]
    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, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shift_top: float | list[float] = 0.0,
    shift_left: float | list[float] = 0.0,
    **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    **kwargs: Any
) -> VideoNode
Source code
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
@inject_self.cached  # type: ignore
@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
) -> vs.VideoNode:
    assert clip.format

    n_planes = clip.format.num_planes

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

    if not shifts_or_top and not shift_left:
        return _shift(clip)
    elif isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)
    elif 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 = cast(list[vs.VideoNode], clip.std.SplitPlanes())

    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)

BicubicSharp

BicubicSharp(**kwargs: Any)

Bases: Bicubic

Bicubic b=0, c=1

Source code
122
123
def __init__(self, **kwargs: Any) -> None:
    super().__init__(b=0, c=1, **kwargs)

b instance-attribute

b = b

c instance-attribute

c = c

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

resample_function class-attribute instance-attribute

resample_function = scale_function

descale

descale(
    clip: VideoNode,
    width: int,
    height: int,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    blur: float = 1.0,
    border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    ignore_mask: VideoNode | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
@inject_kwargs_params
def descale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, shift: tuple[TopShift, LeftShift] = (0, 0),
    *, blur: float = 1.0, border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    ignore_mask: vs.VideoNode | None = None, linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False, **kwargs: Any
) -> vs.VideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> VideoNode
Source code
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@inject_self
def descale_function(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> vs.VideoNode:
    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 = None, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler | Descaler | Resampler | Kernel
Source code
548
549
550
551
552
553
554
555
556
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> Scaler | Descaler | Resampler | Kernel:
    from ..util import abstract_kernels
    return _base_ensure_obj(  # type: ignore
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = None, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]
Source code
510
511
512
513
514
515
516
517
518
@classmethod
def from_param(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]:
    from ..util import abstract_kernels
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except  # type: ignore
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
199
200
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
575
576
577
578
579
580
581
582
583
584
585
@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
603
604
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )  # type: ignore

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
84
85
86
87
88
89
90
91
92
93
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
@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
563
564
565
566
567
568
569
570
571
572
573
@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
44
45
46
47
48
49
50
51
52
53
54
@inject_self.cached
def kernel(self, *, x: float) -> float:
    x, b, c = abs(x), self.b, self.c

    if (x < 1.0):
        return poly3(x, bic_vals.p0(b, c), 0.0, bic_vals.p2(b, c), bic_vals.p3(b, c))

    if (x < 2.0):
        return poly3(x, bic_vals.q0(b, c), bic_vals.q1(b, c), bic_vals.q2(b, c), bic_vals.q3(b, c))

    return 0.0

kernel_radius

kernel_radius() -> int
Source code
56
57
58
59
60
@inject_self.cached.property
def kernel_radius(self) -> int:  # type: ignore
    if (self.b, self.c) == (0, 0):
        return 1
    return 2

multi

multi(
    clip: VideoNode,
    multi: float = 2,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
239
240
241
242
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

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

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

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

pretty_string

pretty_string() -> str
Source code
202
203
204
205
206
207
208
209
210
211
212
213
214
@inject_self.cached.property
def pretty_string(self) -> str:
    attrs = {}

    if hasattr(self, 'b'):
        attrs.update(b=self.b, c=self.c)
    elif hasattr(self, 'taps'):
        attrs['taps'] = self.taps

    if hasattr(self, 'kwargs'):
        attrs.update(self.kwargs)

    return f"{self.__class__.__name__}{' (' + ', '.join(f'{k}={v}' for k, v in attrs.items()) + ')' if attrs else ''}"

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> VideoNode
Source code
376
377
378
379
380
381
382
383
384
@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
) -> vs.VideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

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 | bool | float | None = None,
    dar: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
@inject_self.cached
@inject_kwargs_params
def scale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | bool | float | None = None, dar: Dar | bool | float | None = None, keep_ar: bool | None = None,
    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, sar=sar, dar=dar, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid, border_handling=border_handling,
        sample_grid_model=sample_grid_model, **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
58
@inject_self
def scale_function(  # type: ignore[override]
    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, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shift_top: float | list[float] = 0.0,
    shift_left: float | list[float] = 0.0,
    **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    **kwargs: Any
) -> VideoNode
Source code
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
@inject_self.cached  # type: ignore
@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
) -> vs.VideoNode:
    assert clip.format

    n_planes = clip.format.num_planes

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

    if not shifts_or_top and not shift_left:
        return _shift(clip)
    elif isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)
    elif 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 = cast(list[vs.VideoNode], clip.std.SplitPlanes())

    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)

Catrom

Catrom(**kwargs: Any)

Bases: Bicubic

Bicubic b=0, c=0.5

Source code
87
88
def __init__(self, **kwargs: Any) -> None:
    super().__init__(b=0, c=1 / 2, **kwargs)

b instance-attribute

b = b

c instance-attribute

c = c

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

resample_function class-attribute instance-attribute

resample_function = scale_function

descale

descale(
    clip: VideoNode,
    width: int,
    height: int,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    blur: float = 1.0,
    border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    ignore_mask: VideoNode | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
@inject_kwargs_params
def descale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, shift: tuple[TopShift, LeftShift] = (0, 0),
    *, blur: float = 1.0, border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    ignore_mask: vs.VideoNode | None = None, linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False, **kwargs: Any
) -> vs.VideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> VideoNode
Source code
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@inject_self
def descale_function(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> vs.VideoNode:
    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 = None, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler | Descaler | Resampler | Kernel
Source code
548
549
550
551
552
553
554
555
556
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> Scaler | Descaler | Resampler | Kernel:
    from ..util import abstract_kernels
    return _base_ensure_obj(  # type: ignore
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = None, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]
Source code
510
511
512
513
514
515
516
517
518
@classmethod
def from_param(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]:
    from ..util import abstract_kernels
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except  # type: ignore
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
199
200
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
575
576
577
578
579
580
581
582
583
584
585
@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
603
604
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )  # type: ignore

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
84
85
86
87
88
89
90
91
92
93
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
@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
563
564
565
566
567
568
569
570
571
572
573
@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
44
45
46
47
48
49
50
51
52
53
54
@inject_self.cached
def kernel(self, *, x: float) -> float:
    x, b, c = abs(x), self.b, self.c

    if (x < 1.0):
        return poly3(x, bic_vals.p0(b, c), 0.0, bic_vals.p2(b, c), bic_vals.p3(b, c))

    if (x < 2.0):
        return poly3(x, bic_vals.q0(b, c), bic_vals.q1(b, c), bic_vals.q2(b, c), bic_vals.q3(b, c))

    return 0.0

kernel_radius

kernel_radius() -> int
Source code
56
57
58
59
60
@inject_self.cached.property
def kernel_radius(self) -> int:  # type: ignore
    if (self.b, self.c) == (0, 0):
        return 1
    return 2

multi

multi(
    clip: VideoNode,
    multi: float = 2,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
239
240
241
242
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

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

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

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

pretty_string

pretty_string() -> str
Source code
202
203
204
205
206
207
208
209
210
211
212
213
214
@inject_self.cached.property
def pretty_string(self) -> str:
    attrs = {}

    if hasattr(self, 'b'):
        attrs.update(b=self.b, c=self.c)
    elif hasattr(self, 'taps'):
        attrs['taps'] = self.taps

    if hasattr(self, 'kwargs'):
        attrs.update(self.kwargs)

    return f"{self.__class__.__name__}{' (' + ', '.join(f'{k}={v}' for k, v in attrs.items()) + ')' if attrs else ''}"

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> VideoNode
Source code
376
377
378
379
380
381
382
383
384
@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
) -> vs.VideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

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 | bool | float | None = None,
    dar: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
@inject_self.cached
@inject_kwargs_params
def scale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | bool | float | None = None, dar: Dar | bool | float | None = None, keep_ar: bool | None = None,
    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, sar=sar, dar=dar, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid, border_handling=border_handling,
        sample_grid_model=sample_grid_model, **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
58
@inject_self
def scale_function(  # type: ignore[override]
    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, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shift_top: float | list[float] = 0.0,
    shift_left: float | list[float] = 0.0,
    **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    **kwargs: Any
) -> VideoNode
Source code
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
@inject_self.cached  # type: ignore
@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
) -> vs.VideoNode:
    assert clip.format

    n_planes = clip.format.num_planes

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

    if not shifts_or_top and not shift_left:
        return _shift(clip)
    elif isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)
    elif 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 = cast(list[vs.VideoNode], clip.std.SplitPlanes())

    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)

FFmpegBicubic

FFmpegBicubic(**kwargs: Any)

Bases: Bicubic

Bicubic b=0, c=0.6; FFmpeg's swscale default

Source code
94
95
def __init__(self, **kwargs: Any) -> None:
    super().__init__(b=0, c=0.6, **kwargs)

b instance-attribute

b = b

c instance-attribute

c = c

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

resample_function class-attribute instance-attribute

resample_function = scale_function

descale

descale(
    clip: VideoNode,
    width: int,
    height: int,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    blur: float = 1.0,
    border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    ignore_mask: VideoNode | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
@inject_kwargs_params
def descale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, shift: tuple[TopShift, LeftShift] = (0, 0),
    *, blur: float = 1.0, border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    ignore_mask: vs.VideoNode | None = None, linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False, **kwargs: Any
) -> vs.VideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> VideoNode
Source code
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@inject_self
def descale_function(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> vs.VideoNode:
    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 = None, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler | Descaler | Resampler | Kernel
Source code
548
549
550
551
552
553
554
555
556
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> Scaler | Descaler | Resampler | Kernel:
    from ..util import abstract_kernels
    return _base_ensure_obj(  # type: ignore
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = None, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]
Source code
510
511
512
513
514
515
516
517
518
@classmethod
def from_param(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]:
    from ..util import abstract_kernels
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except  # type: ignore
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
199
200
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
575
576
577
578
579
580
581
582
583
584
585
@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
603
604
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )  # type: ignore

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
84
85
86
87
88
89
90
91
92
93
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
@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
563
564
565
566
567
568
569
570
571
572
573
@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
44
45
46
47
48
49
50
51
52
53
54
@inject_self.cached
def kernel(self, *, x: float) -> float:
    x, b, c = abs(x), self.b, self.c

    if (x < 1.0):
        return poly3(x, bic_vals.p0(b, c), 0.0, bic_vals.p2(b, c), bic_vals.p3(b, c))

    if (x < 2.0):
        return poly3(x, bic_vals.q0(b, c), bic_vals.q1(b, c), bic_vals.q2(b, c), bic_vals.q3(b, c))

    return 0.0

kernel_radius

kernel_radius() -> int
Source code
56
57
58
59
60
@inject_self.cached.property
def kernel_radius(self) -> int:  # type: ignore
    if (self.b, self.c) == (0, 0):
        return 1
    return 2

multi

multi(
    clip: VideoNode,
    multi: float = 2,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
239
240
241
242
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

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

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

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

pretty_string

pretty_string() -> str
Source code
202
203
204
205
206
207
208
209
210
211
212
213
214
@inject_self.cached.property
def pretty_string(self) -> str:
    attrs = {}

    if hasattr(self, 'b'):
        attrs.update(b=self.b, c=self.c)
    elif hasattr(self, 'taps'):
        attrs['taps'] = self.taps

    if hasattr(self, 'kwargs'):
        attrs.update(self.kwargs)

    return f"{self.__class__.__name__}{' (' + ', '.join(f'{k}={v}' for k, v in attrs.items()) + ')' if attrs else ''}"

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> VideoNode
Source code
376
377
378
379
380
381
382
383
384
@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
) -> vs.VideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

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 | bool | float | None = None,
    dar: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
@inject_self.cached
@inject_kwargs_params
def scale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | bool | float | None = None, dar: Dar | bool | float | None = None, keep_ar: bool | None = None,
    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, sar=sar, dar=dar, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid, border_handling=border_handling,
        sample_grid_model=sample_grid_model, **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
58
@inject_self
def scale_function(  # type: ignore[override]
    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, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shift_top: float | list[float] = 0.0,
    shift_left: float | list[float] = 0.0,
    **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    **kwargs: Any
) -> VideoNode
Source code
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
@inject_self.cached  # type: ignore
@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
) -> vs.VideoNode:
    assert clip.format

    n_planes = clip.format.num_planes

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

    if not shifts_or_top and not shift_left:
        return _shift(clip)
    elif isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)
    elif 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 = cast(list[vs.VideoNode], clip.std.SplitPlanes())

    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)

Hermite

Hermite(**kwargs: Any)

Bases: Bicubic

Bicubic b=0, c=0

Source code
73
74
def __init__(self, **kwargs: Any) -> None:
    super().__init__(b=0, c=0, **kwargs)

b instance-attribute

b = b

c instance-attribute

c = c

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

resample_function class-attribute instance-attribute

resample_function = scale_function

descale

descale(
    clip: VideoNode,
    width: int,
    height: int,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    blur: float = 1.0,
    border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    ignore_mask: VideoNode | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
@inject_kwargs_params
def descale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, shift: tuple[TopShift, LeftShift] = (0, 0),
    *, blur: float = 1.0, border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    ignore_mask: vs.VideoNode | None = None, linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False, **kwargs: Any
) -> vs.VideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> VideoNode
Source code
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@inject_self
def descale_function(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> vs.VideoNode:
    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 = None, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler | Descaler | Resampler | Kernel
Source code
548
549
550
551
552
553
554
555
556
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> Scaler | Descaler | Resampler | Kernel:
    from ..util import abstract_kernels
    return _base_ensure_obj(  # type: ignore
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = None, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]
Source code
510
511
512
513
514
515
516
517
518
@classmethod
def from_param(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]:
    from ..util import abstract_kernels
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except  # type: ignore
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
199
200
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
575
576
577
578
579
580
581
582
583
584
585
@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
603
604
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )  # type: ignore

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
84
85
86
87
88
89
90
91
92
93
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
@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
563
564
565
566
567
568
569
570
571
572
573
@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
44
45
46
47
48
49
50
51
52
53
54
@inject_self.cached
def kernel(self, *, x: float) -> float:
    x, b, c = abs(x), self.b, self.c

    if (x < 1.0):
        return poly3(x, bic_vals.p0(b, c), 0.0, bic_vals.p2(b, c), bic_vals.p3(b, c))

    if (x < 2.0):
        return poly3(x, bic_vals.q0(b, c), bic_vals.q1(b, c), bic_vals.q2(b, c), bic_vals.q3(b, c))

    return 0.0

kernel_radius

kernel_radius() -> int
Source code
56
57
58
59
60
@inject_self.cached.property
def kernel_radius(self) -> int:  # type: ignore
    if (self.b, self.c) == (0, 0):
        return 1
    return 2

multi

multi(
    clip: VideoNode,
    multi: float = 2,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
239
240
241
242
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

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

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

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

pretty_string

pretty_string() -> str
Source code
202
203
204
205
206
207
208
209
210
211
212
213
214
@inject_self.cached.property
def pretty_string(self) -> str:
    attrs = {}

    if hasattr(self, 'b'):
        attrs.update(b=self.b, c=self.c)
    elif hasattr(self, 'taps'):
        attrs['taps'] = self.taps

    if hasattr(self, 'kwargs'):
        attrs.update(self.kwargs)

    return f"{self.__class__.__name__}{' (' + ', '.join(f'{k}={v}' for k, v in attrs.items()) + ')' if attrs else ''}"

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> VideoNode
Source code
376
377
378
379
380
381
382
383
384
@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
) -> vs.VideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

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 | bool | float | None = None,
    dar: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
@inject_self.cached
@inject_kwargs_params
def scale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | bool | float | None = None, dar: Dar | bool | float | None = None, keep_ar: bool | None = None,
    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, sar=sar, dar=dar, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid, border_handling=border_handling,
        sample_grid_model=sample_grid_model, **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
58
@inject_self
def scale_function(  # type: ignore[override]
    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, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shift_top: float | list[float] = 0.0,
    shift_left: float | list[float] = 0.0,
    **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    **kwargs: Any
) -> VideoNode
Source code
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
@inject_self.cached  # type: ignore
@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
) -> vs.VideoNode:
    assert clip.format

    n_planes = clip.format.num_planes

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

    if not shifts_or_top and not shift_left:
        return _shift(clip)
    elif isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)
    elif 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 = cast(list[vs.VideoNode], clip.std.SplitPlanes())

    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)

Mitchell

Mitchell(**kwargs: Any)

Bases: Bicubic

Bicubic b=1/3, c=1/3

Source code
80
81
def __init__(self, **kwargs: Any) -> None:
    super().__init__(b=1 / 3, c=1 / 3, **kwargs)

b instance-attribute

b = b

c instance-attribute

c = c

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

resample_function class-attribute instance-attribute

resample_function = scale_function

descale

descale(
    clip: VideoNode,
    width: int,
    height: int,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    blur: float = 1.0,
    border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    ignore_mask: VideoNode | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
@inject_kwargs_params
def descale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, shift: tuple[TopShift, LeftShift] = (0, 0),
    *, blur: float = 1.0, border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    ignore_mask: vs.VideoNode | None = None, linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False, **kwargs: Any
) -> vs.VideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> VideoNode
Source code
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@inject_self
def descale_function(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> vs.VideoNode:
    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 = None, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler | Descaler | Resampler | Kernel
Source code
548
549
550
551
552
553
554
555
556
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> Scaler | Descaler | Resampler | Kernel:
    from ..util import abstract_kernels
    return _base_ensure_obj(  # type: ignore
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = None, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]
Source code
510
511
512
513
514
515
516
517
518
@classmethod
def from_param(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]:
    from ..util import abstract_kernels
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except  # type: ignore
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
199
200
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
575
576
577
578
579
580
581
582
583
584
585
@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
603
604
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )  # type: ignore

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
84
85
86
87
88
89
90
91
92
93
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
@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
563
564
565
566
567
568
569
570
571
572
573
@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
44
45
46
47
48
49
50
51
52
53
54
@inject_self.cached
def kernel(self, *, x: float) -> float:
    x, b, c = abs(x), self.b, self.c

    if (x < 1.0):
        return poly3(x, bic_vals.p0(b, c), 0.0, bic_vals.p2(b, c), bic_vals.p3(b, c))

    if (x < 2.0):
        return poly3(x, bic_vals.q0(b, c), bic_vals.q1(b, c), bic_vals.q2(b, c), bic_vals.q3(b, c))

    return 0.0

kernel_radius

kernel_radius() -> int
Source code
56
57
58
59
60
@inject_self.cached.property
def kernel_radius(self) -> int:  # type: ignore
    if (self.b, self.c) == (0, 0):
        return 1
    return 2

multi

multi(
    clip: VideoNode,
    multi: float = 2,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
239
240
241
242
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

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

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

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

pretty_string

pretty_string() -> str
Source code
202
203
204
205
206
207
208
209
210
211
212
213
214
@inject_self.cached.property
def pretty_string(self) -> str:
    attrs = {}

    if hasattr(self, 'b'):
        attrs.update(b=self.b, c=self.c)
    elif hasattr(self, 'taps'):
        attrs['taps'] = self.taps

    if hasattr(self, 'kwargs'):
        attrs.update(self.kwargs)

    return f"{self.__class__.__name__}{' (' + ', '.join(f'{k}={v}' for k, v in attrs.items()) + ')' if attrs else ''}"

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> VideoNode
Source code
376
377
378
379
380
381
382
383
384
@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
) -> vs.VideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

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 | bool | float | None = None,
    dar: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
@inject_self.cached
@inject_kwargs_params
def scale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | bool | float | None = None, dar: Dar | bool | float | None = None, keep_ar: bool | None = None,
    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, sar=sar, dar=dar, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid, border_handling=border_handling,
        sample_grid_model=sample_grid_model, **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
58
@inject_self
def scale_function(  # type: ignore[override]
    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, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shift_top: float | list[float] = 0.0,
    shift_left: float | list[float] = 0.0,
    **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    **kwargs: Any
) -> VideoNode
Source code
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
@inject_self.cached  # type: ignore
@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
) -> vs.VideoNode:
    assert clip.format

    n_planes = clip.format.num_planes

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

    if not shifts_or_top and not shift_left:
        return _shift(clip)
    elif isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)
    elif 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 = cast(list[vs.VideoNode], clip.std.SplitPlanes())

    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)

Robidoux

Robidoux(**kwargs: Any)

Bases: Bicubic

Bicubic b=0.37822, c=0.31089

Source code
138
139
140
141
def __init__(self, **kwargs: Any) -> None:
    b = 12 / (19 + 9 * sqrt(2))
    c = 113 / (58 + 216 * sqrt(2))
    super().__init__(b=b, c=c, **kwargs)

b instance-attribute

b = b

c instance-attribute

c = c

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

resample_function class-attribute instance-attribute

resample_function = scale_function

descale

descale(
    clip: VideoNode,
    width: int,
    height: int,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    blur: float = 1.0,
    border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    ignore_mask: VideoNode | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
@inject_kwargs_params
def descale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, shift: tuple[TopShift, LeftShift] = (0, 0),
    *, blur: float = 1.0, border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    ignore_mask: vs.VideoNode | None = None, linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False, **kwargs: Any
) -> vs.VideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> VideoNode
Source code
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@inject_self
def descale_function(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> vs.VideoNode:
    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 = None, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler | Descaler | Resampler | Kernel
Source code
548
549
550
551
552
553
554
555
556
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> Scaler | Descaler | Resampler | Kernel:
    from ..util import abstract_kernels
    return _base_ensure_obj(  # type: ignore
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = None, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]
Source code
510
511
512
513
514
515
516
517
518
@classmethod
def from_param(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]:
    from ..util import abstract_kernels
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except  # type: ignore
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
199
200
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
575
576
577
578
579
580
581
582
583
584
585
@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
603
604
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )  # type: ignore

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
84
85
86
87
88
89
90
91
92
93
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
@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
563
564
565
566
567
568
569
570
571
572
573
@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
44
45
46
47
48
49
50
51
52
53
54
@inject_self.cached
def kernel(self, *, x: float) -> float:
    x, b, c = abs(x), self.b, self.c

    if (x < 1.0):
        return poly3(x, bic_vals.p0(b, c), 0.0, bic_vals.p2(b, c), bic_vals.p3(b, c))

    if (x < 2.0):
        return poly3(x, bic_vals.q0(b, c), bic_vals.q1(b, c), bic_vals.q2(b, c), bic_vals.q3(b, c))

    return 0.0

kernel_radius

kernel_radius() -> int
Source code
56
57
58
59
60
@inject_self.cached.property
def kernel_radius(self) -> int:  # type: ignore
    if (self.b, self.c) == (0, 0):
        return 1
    return 2

multi

multi(
    clip: VideoNode,
    multi: float = 2,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
239
240
241
242
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

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

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

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

pretty_string

pretty_string() -> str
Source code
202
203
204
205
206
207
208
209
210
211
212
213
214
@inject_self.cached.property
def pretty_string(self) -> str:
    attrs = {}

    if hasattr(self, 'b'):
        attrs.update(b=self.b, c=self.c)
    elif hasattr(self, 'taps'):
        attrs['taps'] = self.taps

    if hasattr(self, 'kwargs'):
        attrs.update(self.kwargs)

    return f"{self.__class__.__name__}{' (' + ', '.join(f'{k}={v}' for k, v in attrs.items()) + ')' if attrs else ''}"

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> VideoNode
Source code
376
377
378
379
380
381
382
383
384
@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
) -> vs.VideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

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 | bool | float | None = None,
    dar: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
@inject_self.cached
@inject_kwargs_params
def scale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | bool | float | None = None, dar: Dar | bool | float | None = None, keep_ar: bool | None = None,
    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, sar=sar, dar=dar, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid, border_handling=border_handling,
        sample_grid_model=sample_grid_model, **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
58
@inject_self
def scale_function(  # type: ignore[override]
    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, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shift_top: float | list[float] = 0.0,
    shift_left: float | list[float] = 0.0,
    **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    **kwargs: Any
) -> VideoNode
Source code
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
@inject_self.cached  # type: ignore
@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
) -> vs.VideoNode:
    assert clip.format

    n_planes = clip.format.num_planes

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

    if not shifts_or_top and not shift_left:
        return _shift(clip)
    elif isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)
    elif 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 = cast(list[vs.VideoNode], clip.std.SplitPlanes())

    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)

RobidouxSharp

RobidouxSharp(**kwargs: Any)

Bases: Bicubic

Bicubic b=0.26201, c=0.36899

Source code
147
148
149
150
def __init__(self, **kwargs: Any) -> None:
    b = 6 / (13 + 7 * sqrt(2))
    c = 7 / (2 + 12 * sqrt(2))
    super().__init__(b=b, c=c, **kwargs)

b instance-attribute

b = b

c instance-attribute

c = c

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

resample_function class-attribute instance-attribute

resample_function = scale_function

descale

descale(
    clip: VideoNode,
    width: int,
    height: int,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    blur: float = 1.0,
    border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    ignore_mask: VideoNode | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
@inject_kwargs_params
def descale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, shift: tuple[TopShift, LeftShift] = (0, 0),
    *, blur: float = 1.0, border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    ignore_mask: vs.VideoNode | None = None, linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False, **kwargs: Any
) -> vs.VideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> VideoNode
Source code
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@inject_self
def descale_function(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> vs.VideoNode:
    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 = None, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler | Descaler | Resampler | Kernel
Source code
548
549
550
551
552
553
554
555
556
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> Scaler | Descaler | Resampler | Kernel:
    from ..util import abstract_kernels
    return _base_ensure_obj(  # type: ignore
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = None, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]
Source code
510
511
512
513
514
515
516
517
518
@classmethod
def from_param(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]:
    from ..util import abstract_kernels
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except  # type: ignore
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
199
200
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
575
576
577
578
579
580
581
582
583
584
585
@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
603
604
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )  # type: ignore

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
84
85
86
87
88
89
90
91
92
93
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
@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
563
564
565
566
567
568
569
570
571
572
573
@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
44
45
46
47
48
49
50
51
52
53
54
@inject_self.cached
def kernel(self, *, x: float) -> float:
    x, b, c = abs(x), self.b, self.c

    if (x < 1.0):
        return poly3(x, bic_vals.p0(b, c), 0.0, bic_vals.p2(b, c), bic_vals.p3(b, c))

    if (x < 2.0):
        return poly3(x, bic_vals.q0(b, c), bic_vals.q1(b, c), bic_vals.q2(b, c), bic_vals.q3(b, c))

    return 0.0

kernel_radius

kernel_radius() -> int
Source code
56
57
58
59
60
@inject_self.cached.property
def kernel_radius(self) -> int:  # type: ignore
    if (self.b, self.c) == (0, 0):
        return 1
    return 2

multi

multi(
    clip: VideoNode,
    multi: float = 2,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
239
240
241
242
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

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

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

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

pretty_string

pretty_string() -> str
Source code
202
203
204
205
206
207
208
209
210
211
212
213
214
@inject_self.cached.property
def pretty_string(self) -> str:
    attrs = {}

    if hasattr(self, 'b'):
        attrs.update(b=self.b, c=self.c)
    elif hasattr(self, 'taps'):
        attrs['taps'] = self.taps

    if hasattr(self, 'kwargs'):
        attrs.update(self.kwargs)

    return f"{self.__class__.__name__}{' (' + ', '.join(f'{k}={v}' for k, v in attrs.items()) + ')' if attrs else ''}"

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> VideoNode
Source code
376
377
378
379
380
381
382
383
384
@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
) -> vs.VideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

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 | bool | float | None = None,
    dar: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
@inject_self.cached
@inject_kwargs_params
def scale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | bool | float | None = None, dar: Dar | bool | float | None = None, keep_ar: bool | None = None,
    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, sar=sar, dar=dar, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid, border_handling=border_handling,
        sample_grid_model=sample_grid_model, **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
58
@inject_self
def scale_function(  # type: ignore[override]
    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, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shift_top: float | list[float] = 0.0,
    shift_left: float | list[float] = 0.0,
    **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    **kwargs: Any
) -> VideoNode
Source code
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
@inject_self.cached  # type: ignore
@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
) -> vs.VideoNode:
    assert clip.format

    n_planes = clip.format.num_planes

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

    if not shifts_or_top and not shift_left:
        return _shift(clip)
    elif isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)
    elif 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 = cast(list[vs.VideoNode], clip.std.SplitPlanes())

    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)

RobidouxSoft

RobidouxSoft(**kwargs: Any)

Bases: Bicubic

Bicubic b=0.67962, c=0.16019

Source code
129
130
131
132
def __init__(self, **kwargs: Any) -> None:
    b = (9 - 3 * sqrt(2)) / 7
    c = (1 - b) / 2
    super().__init__(b=b, c=c, **kwargs)

b instance-attribute

b = b

c instance-attribute

c = c

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

resample_function class-attribute instance-attribute

resample_function = scale_function

descale

descale(
    clip: VideoNode,
    width: int,
    height: int,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    blur: float = 1.0,
    border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    ignore_mask: VideoNode | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
@inject_kwargs_params
def descale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, shift: tuple[TopShift, LeftShift] = (0, 0),
    *, blur: float = 1.0, border_handling: BorderHandling,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    ignore_mask: vs.VideoNode | None = None, linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False, **kwargs: Any
) -> vs.VideoNode:
    ...

descale_function

descale_function(
    clip: VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> VideoNode
Source code
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@inject_self
def descale_function(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int, height: int, *args: Any, **kwargs: Any
) -> vs.VideoNode:
    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 = None, func_except: FuncExceptT | None = None
) -> Kernel
ensure_obj(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler
ensure_obj(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Descaler
ensure_obj(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Resampler
ensure_obj(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> Scaler | Descaler | Resampler | Kernel
Source code
548
549
550
551
552
553
554
555
556
@classmethod
def ensure_obj(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> Scaler | Descaler | Resampler | Kernel:
    from ..util import abstract_kernels
    return _base_ensure_obj(  # type: ignore
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except
    )

from_param classmethod

from_param(
    kernel: KernelT | None = None, func_except: FuncExceptT | None = None
) -> type[Kernel]
from_param(
    kernel: ScalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler]
from_param(
    kernel: DescalerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Descaler]
from_param(
    kernel: ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Resampler]
from_param(
    kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None,
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]
Source code
510
511
512
513
514
515
516
517
518
@classmethod
def from_param(
    cls: type[Kernel], kernel: ScalerT | DescalerT | ResamplerT | KernelT | None = None,
    func_except: FuncExceptT | None = None
) -> type[Scaler] | type[Descaler] | type[Resampler] | type[Kernel]:
    from ..util import abstract_kernels
    return _base_from_param(
        cls, Kernel, kernel, UnknownKernelError, abstract_kernels, func_except  # type: ignore
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
199
200
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
575
576
577
578
579
580
581
582
583
584
585
@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
603
604
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.shift, )  # type: ignore

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
84
85
86
87
88
89
90
91
92
93
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
@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
563
564
565
566
567
568
569
570
571
572
573
@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
44
45
46
47
48
49
50
51
52
53
54
@inject_self.cached
def kernel(self, *, x: float) -> float:
    x, b, c = abs(x), self.b, self.c

    if (x < 1.0):
        return poly3(x, bic_vals.p0(b, c), 0.0, bic_vals.p2(b, c), bic_vals.p3(b, c))

    if (x < 2.0):
        return poly3(x, bic_vals.q0(b, c), bic_vals.q1(b, c), bic_vals.q2(b, c), bic_vals.q3(b, c))

    return 0.0

kernel_radius

kernel_radius() -> int
Source code
56
57
58
59
60
@inject_self.cached.property
def kernel_radius(self) -> int:  # type: ignore
    if (self.b, self.c) == (0, 0):
        return 1
    return 2

multi

multi(
    clip: VideoNode,
    multi: float = 2,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
239
240
241
242
243
244
245
246
247
248
249
250
251
252
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

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

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

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

pretty_string

pretty_string() -> str
Source code
202
203
204
205
206
207
208
209
210
211
212
213
214
@inject_self.cached.property
def pretty_string(self) -> str:
    attrs = {}

    if hasattr(self, 'b'):
        attrs.update(b=self.b, c=self.c)
    elif hasattr(self, 'taps'):
        attrs['taps'] = self.taps

    if hasattr(self, 'kwargs'):
        attrs.update(self.kwargs)

    return f"{self.__class__.__name__}{' (' + ', '.join(f'{k}={v}' for k, v in attrs.items()) + ')' if attrs else ''}"

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> VideoNode
Source code
376
377
378
379
380
381
382
383
384
@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
) -> vs.VideoNode:
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

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 | bool | float | None = None,
    dar: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    linear: bool = False,
    sigmoid: bool | tuple[Slope, Center] = False,
    **kwargs: Any
) -> VideoNode
Source code
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
@inject_self.cached
@inject_kwargs_params
def scale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    *,
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | bool | float | None = None, dar: Dar | bool | float | None = None, keep_ar: bool | None = None,
    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, sar=sar, dar=dar, keep_ar=keep_ar,
        linear=linear, sigmoid=sigmoid, border_handling=border_handling,
        sample_grid_model=sample_grid_model, **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
58
@inject_self
def scale_function(  # type: ignore[override]
    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, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shift_top: float | list[float] = 0.0,
    shift_left: float | list[float] = 0.0,
    **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float] | None = None,
    shift_left: float | list[float] | None = None,
    **kwargs: Any
) -> VideoNode
Source code
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
@inject_self.cached  # type: ignore
@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
) -> vs.VideoNode:
    assert clip.format

    n_planes = clip.format.num_planes

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

    if not shifts_or_top and not shift_left:
        return _shift(clip)
    elif isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)
    elif 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 = cast(list[vs.VideoNode], clip.std.SplitPlanes())

    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)