Skip to content

docs

Example

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

Bases: Kernel

Example Kernel class for documentation purposes.

Source code
17
18
19
20
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

descale_function instance-attribute

descale_function: GenericVSFunction

Descale function called internally when descaling

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

resample_function instance-attribute

resample_function: GenericVSFunction

Resample function called internally when resampling

scale_function instance-attribute

scale_function: GenericVSFunction

Scale function called internally when scaling

descale

descale(
    clip: VideoNode,
    width: int | None,
    height: int | None,
    shift: tuple[float, float] = (0, 0),
    **kwargs: Any
) -> VideoNode

Perform a regular descaling operation.

Parameters:

  • clip

    (VideoNode) –

    Input clip

  • width

    (int | None) –

    Output width

  • height

    (int | None) –

    Output height

  • shift

    (tuple[float, float], default: (0, 0) ) –

    Shift clip during the operation. Expects a tuple of (src_top, src_left).

Source code
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
@inject_self.cached
def descale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int | None, height: int | None,
    shift: tuple[float, float] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    """
    Perform a regular descaling operation.

    :param clip:        Input clip
    :param width:       Output width
    :param height:      Output height
    :param shift:       Shift clip during the operation.
                        Expects a tuple of (src_top, src_left).

    :rtype:             ``VideoNode``
    """
    width, height = self._wh_norm(clip, width, height)
    return depth(core.descale.Debicubic(
        depth(clip, 32), width, height, b=self.b, c=self.c, src_top=shift[0], src_left=shift[1], **kwargs
    ), clip)

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
) -> KwargsT
Source code
558
559
560
561
def get_params_args(
    self, is_descale: bool, clip: vs.VideoNode, width: int | None = None, height: int | None = None, **kwargs: Any
) -> KwargsT:
    return dict(width=width, height=height) | kwargs

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_radius

kernel_radius() -> int
Source code
195
196
197
@inject_self.cached.property
def kernel_radius(self) -> int:
    return _default_kernel_radius(__class__, self)  # type: ignore

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

Perform a regular resampling operation.

Parameters:

  • clip

    (VideoNode) –

    Input clip

  • format

    (int | VideoFormatT | HoldsVideoFormatT) –

    Output format

  • matrix

    (MatrixT | None, default: None ) –

    Output matrix. If None, will take the matrix from the input clip's frameprops.

  • matrix_in

    (MatrixT | None, default: None ) –

    Input matrix. If None, will take the matrix from the input clip's frameprops.

Source code
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
@inject_self.cached
def resample(  # type: ignore[override]
    self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None, matrix_in: MatrixT | None = None, **kwargs: Any
) -> vs.VideoNode:
    """
    Perform a regular resampling operation.

    :param clip:        Input clip
    :param format:      Output format
    :param matrix:      Output matrix. If `None`, will take the matrix from the input clip's frameprops.
    :param matrix_in:   Input matrix. If `None`, will take the matrix from the input clip's frameprops.

    :rtype:             ``VideoNode``
    """
    return core.resize.Bicubic(
        clip, format=get_video_format(format).id,
        filter_param_a=self.b, filter_param_b=self.c,
        matrix=matrix, matrix_in=matrix_in, **self.kwargs, **kwargs  # type: ignore
    )

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[float, float] = (0, 0),
    **kwargs: Any
) -> VideoNode

Perform a regular scaling operation.

Parameters:

  • clip

    (VideoNode) –

    Input clip

  • width

    (int | None, default: None ) –

    Output width

  • height

    (int | None, default: None ) –

    Output height

  • shift

    (tuple[float, float], default: (0, 0) ) –

    Shift clip during the operation. Expects a tuple of (src_top, src_left).

Source code
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@inject_self.cached
def scale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[float, float] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    """
    Perform a regular scaling operation.

    :param clip:        Input clip
    :param width:       Output width
    :param height:      Output height
    :param shift:       Shift clip during the operation.
                        Expects a tuple of (src_top, src_left).

    :rtype:             ``VideoNode``
    """
    width, height = self._wh_norm(clip, width, height)
    return core.resize.Bicubic(
        clip, width, height, src_top=shift[0], src_left=shift[1],
        filter_param_a=self.b, filter_param_b=self.c, **self.kwargs, **kwargs
    )

shift

shift(
    clip: VideoNode, shift: tuple[float, float] = (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

Perform a regular shifting operation.

Parameters:

  • clip

    (VideoNode) –

    Input clip

  • shift

    Shift clip during the operation. Expects a tuple of (src_top, src_left) or two top, left arrays for shifting planes individually.

Source code
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
def shift(  # type: ignore
    self, clip: vs.VideoNode,
    shift_top: float | list[float] = 0.0, shift_left: float | list[float] = 0.0, **kwargs: Any
) -> vs.VideoNode:
    """
    Perform a regular shifting operation.

    :param clip:        Input clip
    :param shift:       Shift clip during the operation.\n
                        Expects a tuple of (src_top, src_left)\n
                        or two top, left arrays for shifting planes individually.

    :rtype:             ``VideoNode``
    """
    return core.resize.Bicubic(
        clip, src_top=shift_top, src_left=shift_left,  # type: ignore
        filter_param_a=self.b, filter_param_b=self.c,
        **self.kwargs, **kwargs
    )