Skip to content

base

This module defines the base abstract interfaces for general scaling operations.

Type Aliases:

  • BobberLike

    Type alias for anything that can resolve to a Bobber.

  • DescalerLike

    Type alias for anything that can resolve to a Descaler.

  • KernelLike

    Type alias for anything that can resolve to a Kernel.

  • ResamplerLike

    Type alias for anything that can resolve to a Resampler.

  • ScalerLike

    Type alias for anything that can resolve to a Scaler.

Classes:

  • BaseScaler

    Base abstract scaling interface for VapourSynth scalers.

  • Bobber

    Abstract scaler class that applies bob deinterlacing.

  • Descaler

    Abstract descaling interface.

  • Kernel

    Abstract kernel interface combining scaling, descaling, resampling, and shifting functionality.

  • Resampler

    Abstract resampling interface.

  • Scaler

    Abstract scaling interface.

abstract_kernels module-attribute

abstract_kernels: list[BaseScalerMeta] = []

List of fully abstract kernel classes.

Used internally to track kernel base classes that should not be used directly.

logger module-attribute

logger = getLogger(__name__)

partial_abstract_kernels module-attribute

partial_abstract_kernels: list[BaseScalerMeta] = []

List of partially abstract kernel classes.

These may implement some but not all kernel functionality.

BobberLike

BobberLike = str | type[Bobber] | Bobber

Type alias for anything that can resolve to a Bobber.

This includes:

  • A string identifier.
  • A class type subclassing Bobber.
  • An instance of a Bobber.

DescalerLike

DescalerLike = str | type[Descaler] | Descaler

Type alias for anything that can resolve to a Descaler.

This includes:

  • A string identifier.
  • A class type subclassing Descaler.
  • An instance of a Descaler.

KernelLike

KernelLike = str | type[Kernel] | Kernel

Type alias for anything that can resolve to a Kernel.

This includes:

  • A string identifier.
  • A class type subclassing Kernel.
  • An instance of a Kernel.

ResamplerLike

ResamplerLike = str | type[Resampler] | Resampler

Type alias for anything that can resolve to a Resampler.

This includes:

ScalerLike

ScalerLike = str | type[Scaler] | Scaler

Type alias for anything that can resolve to a Scaler.

This includes:

  • A string identifier.
  • A class type subclassing Scaler.
  • An instance of a Scaler.

BaseScaler

BaseScaler(**kwargs: Any)

Bases: VSObjectABC

Base abstract scaling interface for VapourSynth scalers.

Initialize the scaler with optional keyword arguments.

These keyword arguments are automatically forwarded to the implemented_funcs methods but only if the method explicitly accepts them as named parameters. If the same keyword is passed to both __init__ and one of the implemented_funcs, the one passed to func takes precedence.

Parameters:

  • **kwargs

    (Any, default: {} ) –

    Keyword arguments that configure the internal scaling behavior.

Methods:

  • ensure_obj

    Ensure that the input is a scaler instance, resolving it if necessary.

  • from_param

    Resolve and return a scaler type from a given input (string, type, or instance).

  • implemented_funcs

    Returns a set of function names that are implemented in the current class and the parent classes.

  • is_abstract

    Return True if this class can't be instantiated.

  • kernel_radius

    Return the effective kernel radius for the scaler.

Attributes:

  • kwargs (dict[str, Any]) –

    Arguments passed to the implemented funcs or internal scale function.

  • pretty_string (str) –

    Cached property returning a user-friendly string representation.

Source code in vskernels/abstract/base.py
334
335
336
337
338
339
340
341
342
343
344
345
346
347
def __init__(self, **kwargs: Any) -> None:
    """
    Initialize the scaler with optional keyword arguments.

    These keyword arguments are automatically forwarded to
    the [implemented_funcs][vskernels.BaseScaler.implemented_funcs] methods but only
    if the method explicitly accepts them as named parameters.
    If the same keyword is passed to both `__init__` and one of the
    [implemented_funcs][vskernels.BaseScaler.implemented_funcs], the one passed to `func` takes precedence.

    Args:
        **kwargs: Keyword arguments that configure the internal scaling behavior.
    """
    self.kwargs = kwargs

kwargs instance-attribute

kwargs: dict[str, Any] = kwargs

Arguments passed to the implemented funcs or internal scale function.

pretty_string property

pretty_string: str

Cached property returning a user-friendly string representation.

Returns:

  • str

    Pretty-printed string with arguments.

ensure_obj classmethod

ensure_obj(
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> Self

Ensure that the input is a scaler instance, resolving it if necessary.

Parameters:

  • scaler

    (str | type[Self] | Self | None, default: None ) –

    Scaler identifier (string, class, or instance).

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

  • Self

    Scaler instance.

Source code in vskernels/abstract/base.py
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
@classmethod
def ensure_obj(
    cls,
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> Self:
    """
    Ensure that the input is a scaler instance, resolving it if necessary.

    Args:
        scaler: Scaler identifier (string, class, or instance).
        func_except: Function returned for custom error handling.

    Returns:
        Scaler instance.
    """
    return _base_ensure_obj(cls, scaler, func_except)

from_param classmethod

from_param(
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> type[Self]

Resolve and return a scaler type from a given input (string, type, or instance).

Parameters:

  • scaler

    (str | type[Self] | Self | None, default: None ) –

    Scaler identifier (string, class, or instance).

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

Source code in vskernels/abstract/base.py
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
@classmethod
def from_param(
    cls,
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> type[Self]:
    """
    Resolve and return a scaler type from a given input (string, type, or instance).

    Args:
        scaler: Scaler identifier (string, class, or instance).
        func_except: Function returned for custom error handling.

    Returns:
        Resolved scaler type.
    """
    return _base_from_param(cls, scaler, cls._err_class, func_except)

implemented_funcs classmethod

implemented_funcs() -> frozenset[str]

Returns a set of function names that are implemented in the current class and the parent classes.

These functions determine which keyword arguments will be extracted from the __init__ method.

Returns:

Source code in vskernels/abstract/base.py
460
461
462
463
464
465
466
467
468
469
470
471
@classproperty.cached
@classmethod
def implemented_funcs(cls) -> frozenset[str]:
    """
    Returns a set of function names that are implemented in the current class and the parent classes.

    These functions determine which keyword arguments will be extracted from the `__init__` method.

    Returns:
        Frozen set of function names.
    """
    return frozenset(func for klass in cls.mro() for func in getattr(klass, "_implemented_funcs", ()))

is_abstract classmethod

is_abstract() -> bool

Return True if this class can't be instantiated.

Source code in vskernels/abstract/base.py
454
455
456
457
458
@classproperty
@classmethod
def is_abstract(cls) -> bool:
    """Return True if this class can't be instantiated."""
    return _is_base_scaler_abstract(cls)

kernel_radius

kernel_radius() -> int

Return the effective kernel radius for the scaler.

Raises:

Returns:

  • int

    Kernel radius.

Source code in vskernels/abstract/base.py
417
418
419
420
421
422
423
424
425
426
427
428
@BaseScalerMeta.cachedproperty
def kernel_radius(self) -> int:
    """
    Return the effective kernel radius for the scaler.

    Raises:
        CustomNotImplementedError: If no kernel radius is defined.

    Returns:
        Kernel radius.
    """
    ...

BaseScalerMeta

Bases: VSObjectABCMeta

Metaclass for scaler classes.

This metaclass can be used to enforce abstraction rules by specifying abstract or partial_abstract as keyword arguments in the class definition.

  • If abstract=True: The class is marked as fully abstract and added to the abstract_kernels registry. It should not be instantiated.
  • If partial_abstract=True: The class is considered partially abstract, meaning it may lack certain implementations (e.g., kernel radius) but is still allowed to be instantiated. It is added to partial_abstract_kernels.

Classes:

Attributes:

cached_property class-attribute instance-attribute

cached_property = cachedproperty

cachedproperty

cachedproperty(func: Callable[Concatenate[BaseScalerT, P], R])

Bases: cachedproperty[R]

Read only version of jetpytools.cachedproperty.

Classes:

  • baseclass

    Inherit from this class to automatically set the cache dict.

Methods:

Attributes:

Source code in vskernels/abstract/base.py
219
220
221
def __init__[BaseScalerT: BaseScaler, **P](
    self, func: Callable[Concatenate[BaseScalerT, P], R]
) -> None: ...

cache_key class-attribute instance-attribute

cache_key = '_jetpt_cachedproperty_cache'

baseclass

Inherit from this class to automatically set the cache dict.

clear_cache classmethod

clear_cache(obj: object, names: str | Iterable[str] | None = None) -> None

Clear cached properties of an object instance.

Parameters:

  • obj
    (object) –

    The object whose cache should be cleared.

  • names
    (str | Iterable[str] | None, default: None ) –

    Specific property names to clear. If None, all cached properties are cleared.

Source code in jetpytools/types/utils.py
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
@classmethod
def clear_cache(cls, obj: object, names: str | Iterable[str] | None = None) -> None:
    """
    Clear cached properties of an object instance.

    Args:
        obj: The object whose cache should be cleared.
        names: Specific property names to clear. If None, all cached properties are cleared.
    """
    if names is None:
        obj.__dict__.get(cls.cache_key, {}).clear()
        return None

    from ..functions import to_arr

    cache = obj.__dict__.get(cls.cache_key, {})

    for name in to_arr(names):
        with suppress(KeyError):
            del cache[name]

deleter

deleter(fdel: Callable[..., None]) -> cachedproperty[_R_co, _T_Any]
Source code in jetpytools/types/utils.py
771
def deleter(self, fdel: Callable[..., None]) -> cachedproperty[_R_co, _T_Any]: ...

getter

getter(fget: Callable[..., _R_co]) -> cachedproperty[_R_co, _T_Any]
Source code in jetpytools/types/utils.py
767
def getter(self, fget: Callable[..., _R_co]) -> cachedproperty[_R_co, _T_Any]: ...

setter

setter(fset: Callable[[Any, _T_Any], None]) -> cachedproperty[_R_co, _T_Any]
Source code in jetpytools/types/utils.py
769
def setter(self, fset: Callable[[Any, _T_Any], None]) -> cachedproperty[_R_co, _T_Any]: ...

update_cache classmethod

update_cache(obj: object, name: str, value: Any) -> None

Update cached property of an object instance.

Parameters:

  • obj
    (object) –

    The object whose cache should be updated.

  • name
    (str) –

    Property name to update.

  • value
    (Any) –

    The value to assign.

Source code in jetpytools/types/utils.py
838
839
840
841
842
843
844
845
846
847
848
@classmethod
def update_cache(cls, obj: object, name: str, value: Any) -> None:
    """
    Update cached property of an object instance.

    Args:
        obj: The object whose cache should be updated.
        name: Property name to update.
        value: The value to assign.
    """
    obj.__dict__.setdefault(cls.cache_key, {})[name] = value

Bobber

Bobber(**kwargs: Any)

Bases: BaseScaler

Abstract scaler class that applies bob deinterlacing.

Initialize the scaler with optional keyword arguments.

These keyword arguments are automatically forwarded to the implemented_funcs methods but only if the method explicitly accepts them as named parameters. If the same keyword is passed to both __init__ and one of the implemented_funcs, the one passed to func takes precedence.

Parameters:

  • **kwargs

    (Any, default: {} ) –

    Keyword arguments that configure the internal scaling behavior.

Methods:

  • bob

    Apply bob deinterlacing to a given clip using the selected resizer.

  • deinterlace

    Apply deinterlacing to a given clip using the selected resizer.

  • ensure_obj

    Ensure that the input is a scaler instance, resolving it if necessary.

  • from_param

    Resolve and return a scaler type from a given input (string, type, or instance).

  • get_bob_args

    Generate the keyword arguments used for bobbing.

  • implemented_funcs

    Returns a set of function names that are implemented in the current class and the parent classes.

  • is_abstract

    Return True if this class can't be instantiated.

  • kernel_radius

    Return the effective kernel radius for the scaler.

Attributes:

  • bob_function (Callable[..., VideoNode]) –

    Bob function called internally when performing bobbing operations.

  • kwargs (dict[str, Any]) –

    Arguments passed to the implemented funcs or internal scale function.

  • pretty_string (str) –

    Cached property returning a user-friendly string representation.

Source code in vskernels/abstract/base.py
334
335
336
337
338
339
340
341
342
343
344
345
346
347
def __init__(self, **kwargs: Any) -> None:
    """
    Initialize the scaler with optional keyword arguments.

    These keyword arguments are automatically forwarded to
    the [implemented_funcs][vskernels.BaseScaler.implemented_funcs] methods but only
    if the method explicitly accepts them as named parameters.
    If the same keyword is passed to both `__init__` and one of the
    [implemented_funcs][vskernels.BaseScaler.implemented_funcs], the one passed to `func` takes precedence.

    Args:
        **kwargs: Keyword arguments that configure the internal scaling behavior.
    """
    self.kwargs = kwargs

bob_function instance-attribute

bob_function: Callable[..., VideoNode]

Bob function called internally when performing bobbing operations.

kwargs instance-attribute

kwargs: dict[str, Any] = kwargs

Arguments passed to the implemented funcs or internal scale function.

pretty_string property

pretty_string: str

Cached property returning a user-friendly string representation.

Returns:

  • str

    Pretty-printed string with arguments.

bob

bob(
    clip: VideoNode, *, tff: FieldBasedLike | bool | None = None, **kwargs: Any
) -> VideoNode

Apply bob deinterlacing to a given clip using the selected resizer.

Keyword arguments passed during initialization are automatically injected here, unless explicitly overridden by the arguments provided at call time. Only arguments that match named parameters in this method are injected.

Parameters:

  • clip

    (VideoNode) –

    The source clip

  • tff

    (FieldBasedLike | bool | None, default: None ) –

    Field order of the clip.

Returns:

  • VideoNode

    The bobbed clip.

Source code in vskernels/abstract/base.py
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
def bob(self, clip: vs.VideoNode, *, tff: FieldBasedLike | bool | None = None, **kwargs: Any) -> vs.VideoNode:
    """
    Apply bob deinterlacing to a given clip using the selected resizer.

    Keyword arguments passed during initialization are automatically injected here,
    unless explicitly overridden by the arguments provided at call time.
    Only arguments that match named parameters in this method are injected.

    Args:
        clip: The source clip
        tff: Field order of the clip.

    Returns:
        The bobbed clip.
    """
    clip_fieldbased = FieldBased.from_param_or_video(tff, clip, True, self.__class__)
    bob_args = self.get_bob_args(clip, tff=clip_fieldbased.is_tff, **kwargs)

    logger.debug("%s: Passing clip: %r; arguments: %s", self.bob, clip, bob_args)

    return self.bob_function(clip, **bob_args)

deinterlace

deinterlace(
    clip: VideoNode,
    *,
    tff: FieldBasedLike | bool | None = None,
    double_rate: bool = True,
    **kwargs: Any
) -> VideoNode

Apply deinterlacing to a given clip using the selected resizer.

Keyword arguments passed during initialization are automatically injected here, unless explicitly overridden by the arguments provided at call time. Only arguments that match named parameters in this method are injected.

Parameters:

  • clip

    (VideoNode) –

    The source clip

  • tff

    (FieldBasedLike | bool | None, default: None ) –

    Field order of the clip.

  • double_rate

    (bool, default: True ) –

    Whether to double the frame rate (True) or retain the original rate (False).

Returns:

  • VideoNode

    The bobbed clip.

Source code in vskernels/abstract/base.py
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
def deinterlace(
    self, clip: vs.VideoNode, *, tff: FieldBasedLike | bool | None = None, double_rate: bool = True, **kwargs: Any
) -> vs.VideoNode:
    """
    Apply deinterlacing to a given clip using the selected resizer.

    Keyword arguments passed during initialization are automatically injected here,
    unless explicitly overridden by the arguments provided at call time.
    Only arguments that match named parameters in this method are injected.

    Args:
        clip: The source clip
        tff: Field order of the clip.
        double_rate: Whether to double the frame rate (True) or retain the original rate (False).

    Returns:
        The bobbed clip.
    """
    bobbed = self.bob(clip, tff=tff, **kwargs)

    if not double_rate:
        return bobbed[::2]

    return bobbed

ensure_obj classmethod

ensure_obj(
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> Self

Ensure that the input is a scaler instance, resolving it if necessary.

Parameters:

  • scaler

    (str | type[Self] | Self | None, default: None ) –

    Scaler identifier (string, class, or instance).

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

  • Self

    Scaler instance.

Source code in vskernels/abstract/base.py
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
@classmethod
def ensure_obj(
    cls,
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> Self:
    """
    Ensure that the input is a scaler instance, resolving it if necessary.

    Args:
        scaler: Scaler identifier (string, class, or instance).
        func_except: Function returned for custom error handling.

    Returns:
        Scaler instance.
    """
    return _base_ensure_obj(cls, scaler, func_except)

from_param classmethod

from_param(
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> type[Self]

Resolve and return a scaler type from a given input (string, type, or instance).

Parameters:

  • scaler

    (str | type[Self] | Self | None, default: None ) –

    Scaler identifier (string, class, or instance).

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

Source code in vskernels/abstract/base.py
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
@classmethod
def from_param(
    cls,
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> type[Self]:
    """
    Resolve and return a scaler type from a given input (string, type, or instance).

    Args:
        scaler: Scaler identifier (string, class, or instance).
        func_except: Function returned for custom error handling.

    Returns:
        Resolved scaler type.
    """
    return _base_from_param(cls, scaler, cls._err_class, func_except)

get_bob_args

get_bob_args(
    clip: VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> dict[str, Any]

Generate the keyword arguments used for bobbing.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left).

  • **kwargs

    (Any, default: {} ) –

    Extra parameters to merge.

Returns:

  • dict[str, Any]

    Final dictionary of keyword arguments for the bob function.

Source code in vskernels/abstract/base.py
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
def get_bob_args(
    self, clip: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> dict[str, Any]:
    """
    Generate the keyword arguments used for bobbing.

    Args:
        clip: The source clip.
        shift: Subpixel shift (top, left).
        **kwargs: Extra parameters to merge.

    Returns:
        Final dictionary of keyword arguments for the bob function.
    """
    return self.kwargs | kwargs

implemented_funcs classmethod

implemented_funcs() -> frozenset[str]

Returns a set of function names that are implemented in the current class and the parent classes.

These functions determine which keyword arguments will be extracted from the __init__ method.

Returns:

Source code in vskernels/abstract/base.py
460
461
462
463
464
465
466
467
468
469
470
471
@classproperty.cached
@classmethod
def implemented_funcs(cls) -> frozenset[str]:
    """
    Returns a set of function names that are implemented in the current class and the parent classes.

    These functions determine which keyword arguments will be extracted from the `__init__` method.

    Returns:
        Frozen set of function names.
    """
    return frozenset(func for klass in cls.mro() for func in getattr(klass, "_implemented_funcs", ()))

is_abstract classmethod

is_abstract() -> bool

Return True if this class can't be instantiated.

Source code in vskernels/abstract/base.py
454
455
456
457
458
@classproperty
@classmethod
def is_abstract(cls) -> bool:
    """Return True if this class can't be instantiated."""
    return _is_base_scaler_abstract(cls)

kernel_radius

kernel_radius() -> int

Return the effective kernel radius for the scaler.

Raises:

Returns:

  • int

    Kernel radius.

Source code in vskernels/abstract/base.py
417
418
419
420
421
422
423
424
425
426
427
428
@BaseScalerMeta.cachedproperty
def kernel_radius(self) -> int:
    """
    Return the effective kernel radius for the scaler.

    Raises:
        CustomNotImplementedError: If no kernel radius is defined.

    Returns:
        Kernel radius.
    """
    ...

Descaler

Descaler(**kwargs: Any)

Bases: BaseScaler

Abstract descaling interface.

Subclasses must define the descale_function used to perform the descaling.

Initialize the scaler with optional keyword arguments.

These keyword arguments are automatically forwarded to the implemented_funcs methods but only if the method explicitly accepts them as named parameters. If the same keyword is passed to both __init__ and one of the implemented_funcs, the one passed to func takes precedence.

Parameters:

  • **kwargs

    (Any, default: {} ) –

    Keyword arguments that configure the internal scaling behavior.

Methods:

  • descale

    Descale a clip to the given resolution.

  • ensure_obj

    Ensure that the input is a scaler instance, resolving it if necessary.

  • from_param

    Resolve and return a scaler type from a given input (string, type, or instance).

  • get_descale_args

    Construct the argument dictionary used for descaling.

  • get_rescale_args

    Construct the argument dictionary used for upscaling.

  • implemented_funcs

    Returns a set of function names that are implemented in the current class and the parent classes.

  • is_abstract

    Return True if this class can't be instantiated.

  • kernel_radius

    Return the effective kernel radius for the scaler.

  • rescale

    Rescale a clip to the given resolution from a previously descaled clip.

Attributes:

  • descale_function (Callable[..., VideoNode]) –

    Descale function called internally when performing descaling operations.

  • kwargs (dict[str, Any]) –

    Arguments passed to the implemented funcs or internal scale function.

  • pretty_string (str) –

    Cached property returning a user-friendly string representation.

  • rescale_function (Callable[..., VideoNode]) –

    Rescale function called internally when performing upscaling operations.

Source code in vskernels/abstract/base.py
334
335
336
337
338
339
340
341
342
343
344
345
346
347
def __init__(self, **kwargs: Any) -> None:
    """
    Initialize the scaler with optional keyword arguments.

    These keyword arguments are automatically forwarded to
    the [implemented_funcs][vskernels.BaseScaler.implemented_funcs] methods but only
    if the method explicitly accepts them as named parameters.
    If the same keyword is passed to both `__init__` and one of the
    [implemented_funcs][vskernels.BaseScaler.implemented_funcs], the one passed to `func` takes precedence.

    Args:
        **kwargs: Keyword arguments that configure the internal scaling behavior.
    """
    self.kwargs = kwargs

descale_function instance-attribute

descale_function: Callable[..., VideoNode]

Descale function called internally when performing descaling operations.

kwargs instance-attribute

kwargs: dict[str, Any] = kwargs

Arguments passed to the implemented funcs or internal scale function.

pretty_string property

pretty_string: str

Cached property returning a user-friendly string representation.

Returns:

  • str

    Pretty-printed string with arguments.

rescale_function instance-attribute

rescale_function: Callable[..., VideoNode]

Rescale function called internally when performing upscaling operations.

descale

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

Descale a clip to the given resolution.

Keyword arguments passed during initialization are automatically injected here, unless explicitly overridden by the arguments provided at call time. Only arguments that match named parameters in this method are injected.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • width

    (int | None) –

    Target descaled width (defaults to clip width if None).

  • height

    (int | None) –

    Target descaled height (defaults to clip height if None).

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left) applied during scaling.

Returns:

  • VideoNode

    The descaled clip.

Source code in vskernels/abstract/base.py
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
def descale(
    self,
    clip: vs.VideoNode,
    width: int | None,
    height: int | None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any,
) -> vs.VideoNode:
    """
    Descale a clip to the given resolution.

    Keyword arguments passed during initialization are automatically injected here,
    unless explicitly overridden by the arguments provided at call time.
    Only arguments that match named parameters in this method are injected.

    Args:
        clip: The source clip.
        width: Target descaled width (defaults to clip width if None).
        height: Target descaled height (defaults to clip height if None).
        shift: Subpixel shift (top, left) applied during scaling.

    Returns:
        The descaled clip.
    """
    width, height = self._wh_norm(clip, width, height)

    descale_args = _norm_props_enums(self.get_descale_args(clip, shift, width, height, **kwargs))

    logger.debug("%s: Passing clip: %r; arguments: %s", self.descale, clip, descale_args)

    return self.descale_function(clip, **descale_args)

ensure_obj classmethod

ensure_obj(
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> Self

Ensure that the input is a scaler instance, resolving it if necessary.

Parameters:

  • scaler

    (str | type[Self] | Self | None, default: None ) –

    Scaler identifier (string, class, or instance).

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

  • Self

    Scaler instance.

Source code in vskernels/abstract/base.py
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
@classmethod
def ensure_obj(
    cls,
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> Self:
    """
    Ensure that the input is a scaler instance, resolving it if necessary.

    Args:
        scaler: Scaler identifier (string, class, or instance).
        func_except: Function returned for custom error handling.

    Returns:
        Scaler instance.
    """
    return _base_ensure_obj(cls, scaler, func_except)

from_param classmethod

from_param(
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> type[Self]

Resolve and return a scaler type from a given input (string, type, or instance).

Parameters:

  • scaler

    (str | type[Self] | Self | None, default: None ) –

    Scaler identifier (string, class, or instance).

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

Source code in vskernels/abstract/base.py
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
@classmethod
def from_param(
    cls,
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> type[Self]:
    """
    Resolve and return a scaler type from a given input (string, type, or instance).

    Args:
        scaler: Scaler identifier (string, class, or instance).
        func_except: Function returned for custom error handling.

    Returns:
        Resolved scaler type.
    """
    return _base_from_param(cls, scaler, cls._err_class, func_except)

get_descale_args

get_descale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]

Construct the argument dictionary used for descaling.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left).

  • width

    (int | None, default: None ) –

    Target width for descaling.

  • height

    (int | None, default: None ) –

    Target height for descaling.

  • **kwargs

    (Any, default: {} ) –

    Extra keyword arguments to merge.

Returns:

  • dict[str, Any]

    Combined keyword argument dictionary.

Source code in vskernels/abstract/base.py
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
def get_descale_args(
    self,
    clip: vs.VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any,
) -> dict[str, Any]:
    """
    Construct the argument dictionary used for descaling.

    Args:
        clip: The source clip.
        shift: Subpixel shift (top, left).
        width: Target width for descaling.
        height: Target height for descaling.
        **kwargs: Extra keyword arguments to merge.

    Returns:
        Combined keyword argument dictionary.
    """
    return {"width": width, "height": height, "src_top": shift[0], "src_left": shift[1]} | self.kwargs | kwargs

get_rescale_args

get_rescale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]

Construct the argument dictionary used for upscaling.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left).

  • width

    (int | None, default: None ) –

    Target width for upscaling.

  • height

    (int | None, default: None ) –

    Target height for upscaling.

  • **kwargs

    (Any, default: {} ) –

    Extra keyword arguments to merge.

Returns:

  • dict[str, Any]

    Combined keyword argument dictionary.

Source code in vskernels/abstract/base.py
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
def get_rescale_args(
    self,
    clip: vs.VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any,
) -> dict[str, Any]:
    """
    Construct the argument dictionary used for upscaling.

    Args:
        clip: The source clip.
        shift: Subpixel shift (top, left).
        width: Target width for upscaling.
        height: Target height for upscaling.
        **kwargs: Extra keyword arguments to merge.

    Returns:
        Combined keyword argument dictionary.
    """
    return {"width": width, "height": height, "src_top": shift[0], "src_left": shift[1]} | self.kwargs | kwargs

implemented_funcs classmethod

implemented_funcs() -> frozenset[str]

Returns a set of function names that are implemented in the current class and the parent classes.

These functions determine which keyword arguments will be extracted from the __init__ method.

Returns:

Source code in vskernels/abstract/base.py
460
461
462
463
464
465
466
467
468
469
470
471
@classproperty.cached
@classmethod
def implemented_funcs(cls) -> frozenset[str]:
    """
    Returns a set of function names that are implemented in the current class and the parent classes.

    These functions determine which keyword arguments will be extracted from the `__init__` method.

    Returns:
        Frozen set of function names.
    """
    return frozenset(func for klass in cls.mro() for func in getattr(klass, "_implemented_funcs", ()))

is_abstract classmethod

is_abstract() -> bool

Return True if this class can't be instantiated.

Source code in vskernels/abstract/base.py
454
455
456
457
458
@classproperty
@classmethod
def is_abstract(cls) -> bool:
    """Return True if this class can't be instantiated."""
    return _is_base_scaler_abstract(cls)

kernel_radius

kernel_radius() -> int

Return the effective kernel radius for the scaler.

Raises:

Returns:

  • int

    Kernel radius.

Source code in vskernels/abstract/base.py
417
418
419
420
421
422
423
424
425
426
427
428
@BaseScalerMeta.cachedproperty
def kernel_radius(self) -> int:
    """
    Return the effective kernel radius for the scaler.

    Raises:
        CustomNotImplementedError: If no kernel radius is defined.

    Returns:
        Kernel radius.
    """
    ...

rescale

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

Rescale a clip to the given resolution from a previously descaled clip.

Keyword arguments passed during initialization are automatically injected here, unless explicitly overridden by the arguments provided at call time. Only arguments that match named parameters in this method are injected.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • width

    (int | None) –

    Target scaled width (defaults to clip width if None).

  • height

    (int | None) –

    Target scaled height (defaults to clip height if None).

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left) applied during scaling.

Returns:

  • VideoNode

    The scaled clip.

Source code in vskernels/abstract/base.py
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
def rescale(
    self,
    clip: vs.VideoNode,
    width: int | None,
    height: int | None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any,
) -> vs.VideoNode:
    """
    Rescale a clip to the given resolution from a previously descaled clip.

    Keyword arguments passed during initialization are automatically injected here,
    unless explicitly overridden by the arguments provided at call time.
    Only arguments that match named parameters in this method are injected.

    Args:
        clip: The source clip.
        width: Target scaled width (defaults to clip width if None).
        height: Target scaled height (defaults to clip height if None).
        shift: Subpixel shift (top, left) applied during scaling.

    Returns:
        The scaled clip.
    """
    width, height = self._wh_norm(clip, width, height)

    rescale_args = _norm_props_enums(self.get_rescale_args(clip, shift, width, height, **kwargs))

    logger.debug("%s: Passing clip: %r; arguments: %s", self.rescale, clip, rescale_args)

    return self.rescale_function(clip, **rescale_args)

Kernel

Kernel(**kwargs: Any)

Bases: Scaler, Descaler, Resampler

Abstract kernel interface combining scaling, descaling, resampling, and shifting functionality.

Subclasses are expected to implement the actual transformation logic by overriding the methods or providing the respective *_function callables (scale_function, descale_function, resample_function).

This class is abstract and should not be used directly.

Initialize the scaler with optional keyword arguments.

These keyword arguments are automatically forwarded to the implemented_funcs methods but only if the method explicitly accepts them as named parameters. If the same keyword is passed to both __init__ and one of the implemented_funcs, the one passed to func takes precedence.

Parameters:

  • **kwargs

    (Any, default: {} ) –

    Keyword arguments that configure the internal scaling behavior.

Methods:

  • descale

    Descale a clip to the given resolution.

  • ensure_obj

    Ensure that the input is a scaler instance, resolving it if necessary.

  • from_param

    Resolve and return a scaler type from a given input (string, type, or instance).

  • get_descale_args

    Generate and normalize argument dictionary for a descale operation.

  • get_params_args

    Generate a base set of parameters to pass for scaling, descaling, or resampling.

  • get_resample_args

    Generate and normalize argument dictionary for a resample operation.

  • get_rescale_args

    Generate and normalize argument dictionary for a rescale operation.

  • get_scale_args

    Generate and normalize argument dictionary for a scale operation.

  • implemented_funcs

    Returns a set of function names that are implemented in the current class and the parent classes.

  • is_abstract

    Return True if this class can't be instantiated.

  • kernel_radius

    Return the effective kernel radius for the scaler.

  • resample

    Resample a video clip to the given format.

  • rescale

    Rescale a clip to the given resolution from a previously descaled clip.

  • scale

    Scale a clip to a specified resolution.

  • shift

    Apply a subpixel shift to the clip using the kernel's scaling logic.

  • supersample

    Supersample a clip by a given scaling factor.

Attributes:

  • descale_function (Callable[..., VideoNode]) –

    Descale function called internally when performing descaling operations.

  • kwargs (dict[str, Any]) –

    Arguments passed to the implemented funcs or internal scale function.

  • pretty_string (str) –

    Cached property returning a user-friendly string representation.

  • resample_function (Callable[..., VideoNode]) –

    Resample function called internally when performing resampling operations.

  • rescale_function (Callable[..., VideoNode]) –

    Rescale function called internally when performing upscaling operations.

  • scale_function (Callable[..., VideoNode]) –

    Scale function called internally when performing scaling operations.

Source code in vskernels/abstract/base.py
334
335
336
337
338
339
340
341
342
343
344
345
346
347
def __init__(self, **kwargs: Any) -> None:
    """
    Initialize the scaler with optional keyword arguments.

    These keyword arguments are automatically forwarded to
    the [implemented_funcs][vskernels.BaseScaler.implemented_funcs] methods but only
    if the method explicitly accepts them as named parameters.
    If the same keyword is passed to both `__init__` and one of the
    [implemented_funcs][vskernels.BaseScaler.implemented_funcs], the one passed to `func` takes precedence.

    Args:
        **kwargs: Keyword arguments that configure the internal scaling behavior.
    """
    self.kwargs = kwargs

descale_function instance-attribute

descale_function: Callable[..., VideoNode]

Descale function called internally when performing descaling operations.

kwargs instance-attribute

kwargs: dict[str, Any] = kwargs

Arguments passed to the implemented funcs or internal scale function.

pretty_string property

pretty_string: str

Cached property returning a user-friendly string representation.

Returns:

  • str

    Pretty-printed string with arguments.

resample_function instance-attribute

resample_function: Callable[..., VideoNode]

Resample function called internally when performing resampling operations.

rescale_function instance-attribute

rescale_function: Callable[..., VideoNode]

Rescale function called internally when performing upscaling operations.

scale_function instance-attribute

scale_function: Callable[..., VideoNode]

Scale function called internally when performing scaling operations.

descale

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

Descale a clip to the given resolution.

Keyword arguments passed during initialization are automatically injected here, unless explicitly overridden by the arguments provided at call time. Only arguments that match named parameters in this method are injected.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • width

    (int | None) –

    Target descaled width (defaults to clip width if None).

  • height

    (int | None) –

    Target descaled height (defaults to clip height if None).

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left) applied during scaling.

Returns:

  • VideoNode

    The descaled clip.

Source code in vskernels/abstract/base.py
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
def descale(
    self,
    clip: vs.VideoNode,
    width: int | None,
    height: int | None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any,
) -> vs.VideoNode:
    """
    Descale a clip to the given resolution.

    Keyword arguments passed during initialization are automatically injected here,
    unless explicitly overridden by the arguments provided at call time.
    Only arguments that match named parameters in this method are injected.

    Args:
        clip: The source clip.
        width: Target descaled width (defaults to clip width if None).
        height: Target descaled height (defaults to clip height if None).
        shift: Subpixel shift (top, left) applied during scaling.

    Returns:
        The descaled clip.
    """
    width, height = self._wh_norm(clip, width, height)

    descale_args = _norm_props_enums(self.get_descale_args(clip, shift, width, height, **kwargs))

    logger.debug("%s: Passing clip: %r; arguments: %s", self.descale, clip, descale_args)

    return self.descale_function(clip, **descale_args)

ensure_obj classmethod

ensure_obj(
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> Self

Ensure that the input is a scaler instance, resolving it if necessary.

Parameters:

  • scaler

    (str | type[Self] | Self | None, default: None ) –

    Scaler identifier (string, class, or instance).

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

  • Self

    Scaler instance.

Source code in vskernels/abstract/base.py
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
@classmethod
def ensure_obj(
    cls,
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> Self:
    """
    Ensure that the input is a scaler instance, resolving it if necessary.

    Args:
        scaler: Scaler identifier (string, class, or instance).
        func_except: Function returned for custom error handling.

    Returns:
        Scaler instance.
    """
    return _base_ensure_obj(cls, scaler, func_except)

from_param classmethod

from_param(
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> type[Self]

Resolve and return a scaler type from a given input (string, type, or instance).

Parameters:

  • scaler

    (str | type[Self] | Self | None, default: None ) –

    Scaler identifier (string, class, or instance).

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

Source code in vskernels/abstract/base.py
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
@classmethod
def from_param(
    cls,
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> type[Self]:
    """
    Resolve and return a scaler type from a given input (string, type, or instance).

    Args:
        scaler: Scaler identifier (string, class, or instance).
        func_except: Function returned for custom error handling.

    Returns:
        Resolved scaler type.
    """
    return _base_from_param(cls, scaler, cls._err_class, func_except)

get_descale_args

get_descale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]

Generate and normalize argument dictionary for a descale operation.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Vertical and horizontal shift to apply.

  • width

    (int | None, default: None ) –

    Target width.

  • height

    (int | None, default: None ) –

    Target height.

  • **kwargs

    (Any, default: {} ) –

    Additional arguments to pass to the descale function.

Returns:

  • dict[str, Any]

    Dictionary of keyword arguments for the descale function.

Source code in vskernels/abstract/base.py
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
def get_descale_args(
    self,
    clip: vs.VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any,
) -> dict[str, Any]:
    """
    Generate and normalize argument dictionary for a descale operation.

    Args:
        clip: The source clip.
        shift: Vertical and horizontal shift to apply.
        width: Target width.
        height: Target height.
        **kwargs: Additional arguments to pass to the descale function.

    Returns:
        Dictionary of keyword arguments for the descale function.
    """
    return {"src_top": shift[0], "src_left": shift[1]} | self.get_params_args(True, clip, width, height, **kwargs)

get_params_args

get_params_args(
    is_descale: bool,
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]

Generate a base set of parameters to pass for scaling, descaling, or resampling.

Parameters:

  • is_descale

    (bool) –

    Whether this is for a descale operation.

  • clip

    (VideoNode) –

    The source clip.

  • width

    (int | None, default: None ) –

    Target width.

  • height

    (int | None, default: None ) –

    Target height.

  • **kwargs

    (Any, default: {} ) –

    Additional keyword arguments to include.

Returns:

  • dict[str, Any]

    Dictionary of combined parameters.

Source code in vskernels/abstract/base.py
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
def get_params_args(
    self, is_descale: bool, clip: vs.VideoNode, width: int | None = None, height: int | None = None, **kwargs: Any
) -> dict[str, Any]:
    """
    Generate a base set of parameters to pass for scaling, descaling, or resampling.

    Args:
        is_descale: Whether this is for a descale operation.
        clip: The source clip.
        width: Target width.
        height: Target height.
        **kwargs: Additional keyword arguments to include.

    Returns:
        Dictionary of combined parameters.
    """
    return _resolve_video_spec_args(clip, **{"width": width, "height": height} | self.kwargs | kwargs)

get_resample_args

get_resample_args(
    clip: VideoNode,
    format: SupportsInt | VideoFormatLike | HoldsVideoFormat,
    matrix: MatrixLike | None,
    matrix_in: MatrixLike | None,
    transfer: TransferLike | None = None,
    transfer_in: TransferLike | None = None,
    primaries: PrimariesLike | None = None,
    primaries_in: PrimariesLike | None = None,
    **kwargs: Any
) -> dict[str, Any]

Generate and normalize argument dictionary for a resample operation.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • format

    (SupportsInt | VideoFormatLike | HoldsVideoFormat) –

    The target video format, which can either be:

    • an integer format ID,
    • a vs.PresetVideoFormat or vs.VideoFormat,
    • or a source from which a valid VideoFormat can be extracted.
  • matrix

    (MatrixLike | None) –

    Target color matrix.

  • matrix_in

    (MatrixLike | None) –

    Source color matrix.

  • transfer

    (TransferLike | None, default: None ) –

    Target color transfer.

  • transfer_in

    (TransferLike | None, default: None ) –

    Source color transfer.

  • primaries

    (PrimariesLike | None, default: None ) –

    Target color primaries.

  • primaries_in

    (PrimariesLike | None, default: None ) –

    Source color primaries.

  • **kwargs

    (Any, default: {} ) –

    Additional arguments to pass to the resample function.

Returns:

  • dict[str, Any]

    Dictionary of keyword arguments for the resample function.

Source code in vskernels/abstract/base.py
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
def get_resample_args(
    self,
    clip: vs.VideoNode,
    format: SupportsInt | VideoFormatLike | HoldsVideoFormat,
    matrix: MatrixLike | None,
    matrix_in: MatrixLike | None,
    transfer: TransferLike | None = None,
    transfer_in: TransferLike | None = None,
    primaries: PrimariesLike | None = None,
    primaries_in: PrimariesLike | None = None,
    **kwargs: Any,
) -> dict[str, Any]:
    """
    Generate and normalize argument dictionary for a resample operation.

    Args:
        clip: The source clip.
        format: The target video format, which can either be:

               - an integer format ID,
               - a `vs.PresetVideoFormat` or `vs.VideoFormat`,
               - or a source from which a valid `VideoFormat` can be extracted.
        matrix: Target color matrix.
        matrix_in: Source color matrix.
        transfer: Target color transfer.
        transfer_in: Source color transfer.
        primaries: Target color primaries.
        primaries_in: Source color primaries.
        **kwargs: Additional arguments to pass to the resample function.

    Returns:
        Dictionary of keyword arguments for the resample function.
    """
    return {
        "format": get_video_format(format),
        "matrix": Matrix.from_param_with_fallback(matrix),
        "matrix_in": Matrix.from_param_with_fallback(matrix_in),
        "transfer": Transfer.from_param_with_fallback(transfer),
        "transfer_in": Transfer.from_param_with_fallback(transfer_in),
        "primaries": Primaries.from_param_with_fallback(primaries),
        "primaries_in": Primaries.from_param_with_fallback(primaries_in),
    } | self.get_params_args(False, clip, **kwargs)

get_rescale_args

get_rescale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]

Generate and normalize argument dictionary for a rescale operation.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Vertical and horizontal shift to apply.

  • width

    (int | None, default: None ) –

    Target width.

  • height

    (int | None, default: None ) –

    Target height.

  • **kwargs

    (Any, default: {} ) –

    Additional arguments to pass to the rescale function.

Returns:

  • dict[str, Any]

    Dictionary of keyword arguments for the rescale function.

Source code in vskernels/abstract/base.py
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
def get_rescale_args(
    self,
    clip: vs.VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any,
) -> dict[str, Any]:
    """
    Generate and normalize argument dictionary for a rescale operation.

    Args:
        clip: The source clip.
        shift: Vertical and horizontal shift to apply.
        width: Target width.
        height: Target height.
        **kwargs: Additional arguments to pass to the rescale function.

    Returns:
        Dictionary of keyword arguments for the rescale function.
    """
    return {"src_top": shift[0], "src_left": shift[1]} | self.get_params_args(True, clip, width, height, **kwargs)

get_scale_args

get_scale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]

Generate and normalize argument dictionary for a scale operation.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Vertical and horizontal shift to apply.

  • width

    (int | None, default: None ) –

    Target width.

  • height

    (int | None, default: None ) –

    Target height.

  • **kwargs

    (Any, default: {} ) –

    Additional arguments to pass to the scale function.

Returns:

  • dict[str, Any]

    Dictionary of keyword arguments for the scale function.

Source code in vskernels/abstract/base.py
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
def get_scale_args(
    self,
    clip: vs.VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any,
) -> dict[str, Any]:
    """
    Generate and normalize argument dictionary for a scale operation.

    Args:
        clip: The source clip.
        shift: Vertical and horizontal shift to apply.
        width: Target width.
        height: Target height.
        **kwargs: Additional arguments to pass to the scale function.

    Returns:
        Dictionary of keyword arguments for the scale function.
    """
    return {"src_top": shift[0], "src_left": shift[1]} | self.get_params_args(False, clip, width, height, **kwargs)

implemented_funcs classmethod

implemented_funcs() -> frozenset[str]

Returns a set of function names that are implemented in the current class and the parent classes.

These functions determine which keyword arguments will be extracted from the __init__ method.

Returns:

Source code in vskernels/abstract/base.py
460
461
462
463
464
465
466
467
468
469
470
471
@classproperty.cached
@classmethod
def implemented_funcs(cls) -> frozenset[str]:
    """
    Returns a set of function names that are implemented in the current class and the parent classes.

    These functions determine which keyword arguments will be extracted from the `__init__` method.

    Returns:
        Frozen set of function names.
    """
    return frozenset(func for klass in cls.mro() for func in getattr(klass, "_implemented_funcs", ()))

is_abstract classmethod

is_abstract() -> bool

Return True if this class can't be instantiated.

Source code in vskernels/abstract/base.py
454
455
456
457
458
@classproperty
@classmethod
def is_abstract(cls) -> bool:
    """Return True if this class can't be instantiated."""
    return _is_base_scaler_abstract(cls)

kernel_radius

kernel_radius() -> int

Return the effective kernel radius for the scaler.

Raises:

Returns:

  • int

    Kernel radius.

Source code in vskernels/abstract/base.py
417
418
419
420
421
422
423
424
425
426
427
428
@BaseScalerMeta.cachedproperty
def kernel_radius(self) -> int:
    """
    Return the effective kernel radius for the scaler.

    Raises:
        CustomNotImplementedError: If no kernel radius is defined.

    Returns:
        Kernel radius.
    """
    ...

resample

resample(
    clip: VideoNode,
    format: SupportsInt | VideoFormatLike | HoldsVideoFormat,
    matrix: MatrixLike | None = None,
    matrix_in: MatrixLike | None = None,
    transfer: TransferLike | None = None,
    transfer_in: TransferLike | None = None,
    primaries: PrimariesLike | None = None,
    primaries_in: PrimariesLike | None = None,
    **kwargs: Any
) -> VideoNode

Resample a video clip to the given format.

Keyword arguments passed during initialization are automatically injected here, unless explicitly overridden by the arguments provided at call time. Only arguments that match named parameters in this method are injected.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • format

    (SupportsInt | VideoFormatLike | HoldsVideoFormat) –

    The target video format, which can either be:

    • an integer format ID,
    • a vs.PresetVideoFormat or vs.VideoFormat,
    • or a source from which a valid VideoFormat can be extracted.
  • matrix

    (MatrixLike | None, default: None ) –

    An optional color transformation matrix to apply.

  • matrix_in

    (MatrixLike | None, default: None ) –

    An optional input matrix for color transformations.

  • transfer

    (TransferLike | None, default: None ) –

    An optional color transformation transfer to apply.

  • transfer_in

    (TransferLike | None, default: None ) –

    An optional input transfer for color transformations.

  • primaries

    (PrimariesLike | None, default: None ) –

    Optional color transformation primaries to apply.

  • primaries_in

    (PrimariesLike | None, default: None ) –

    Optional input primaries for color transformations.

  • **kwargs

    (Any, default: {} ) –

    Additional keyword arguments passed to the resample_function.

Returns:

  • VideoNode

    The resampled clip.

Source code in vskernels/abstract/base.py
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
def resample(
    self,
    clip: vs.VideoNode,
    format: SupportsInt | VideoFormatLike | HoldsVideoFormat,
    matrix: MatrixLike | None = None,
    matrix_in: MatrixLike | None = None,
    transfer: TransferLike | None = None,
    transfer_in: TransferLike | None = None,
    primaries: PrimariesLike | None = None,
    primaries_in: PrimariesLike | None = None,
    **kwargs: Any,
) -> vs.VideoNode:
    """
    Resample a video clip to the given format.

    Keyword arguments passed during initialization are automatically injected here,
    unless explicitly overridden by the arguments provided at call time.
    Only arguments that match named parameters in this method are injected.

    Args:
        clip: The source clip.
        format: The target video format, which can either be:

               - an integer format ID,
               - a `vs.PresetVideoFormat` or `vs.VideoFormat`,
               - or a source from which a valid `VideoFormat` can be extracted.
        matrix: An optional color transformation matrix to apply.
        matrix_in: An optional input matrix for color transformations.
        transfer: An optional color transformation transfer to apply.
        transfer_in: An optional input transfer for color transformations.
        primaries: Optional color transformation primaries to apply.
        primaries_in: Optional input primaries for color transformations.
        **kwargs: Additional keyword arguments passed to the `resample_function`.

    Returns:
        The resampled clip.
    """

    resample_args = _norm_props_enums(
        self.get_resample_args(
            clip, format, matrix, matrix_in, transfer, transfer_in, primaries, primaries_in, **kwargs
        )
    )

    logger.debug("%s: Passing clip: %r; arguments: %s", self.resample, clip, resample_args)

    return self.resample_function(clip, **resample_args)

rescale

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

Rescale a clip to the given resolution from a previously descaled clip.

Keyword arguments passed during initialization are automatically injected here, unless explicitly overridden by the arguments provided at call time. Only arguments that match named parameters in this method are injected.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • width

    (int | None) –

    Target scaled width (defaults to clip width if None).

  • height

    (int | None) –

    Target scaled height (defaults to clip height if None).

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left) applied during scaling.

Returns:

  • VideoNode

    The scaled clip.

Source code in vskernels/abstract/base.py
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
def rescale(
    self,
    clip: vs.VideoNode,
    width: int | None,
    height: int | None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any,
) -> vs.VideoNode:
    """
    Rescale a clip to the given resolution from a previously descaled clip.

    Keyword arguments passed during initialization are automatically injected here,
    unless explicitly overridden by the arguments provided at call time.
    Only arguments that match named parameters in this method are injected.

    Args:
        clip: The source clip.
        width: Target scaled width (defaults to clip width if None).
        height: Target scaled height (defaults to clip height if None).
        shift: Subpixel shift (top, left) applied during scaling.

    Returns:
        The scaled clip.
    """
    width, height = self._wh_norm(clip, width, height)

    rescale_args = _norm_props_enums(self.get_rescale_args(clip, shift, width, height, **kwargs))

    logger.debug("%s: Passing clip: %r; arguments: %s", self.rescale, clip, rescale_args)

    return self.rescale_function(clip, **rescale_args)

scale

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

Scale a clip to a specified resolution.

Keyword arguments passed during initialization are automatically injected here, unless explicitly overridden by the arguments provided at call time. Only arguments that match named parameters in this method are injected.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • width

    (int | None, default: None ) –

    Target width (defaults to clip width if None).

  • height

    (int | None, default: None ) –

    Target height (defaults to clip height if None).

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left) applied during scaling.

  • **kwargs

    (Any, default: {} ) –

    Additional arguments forwarded to the scale function.

Returns:

  • VideoNode

    The scaled clip.

Source code in vskernels/abstract/base.py
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
def scale(
    self,
    clip: vs.VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any,
) -> vs.VideoNode:
    """
    Scale a clip to a specified resolution.

    Keyword arguments passed during initialization are automatically injected here,
    unless explicitly overridden by the arguments provided at call time.
    Only arguments that match named parameters in this method are injected.

    Args:
        clip: The source clip.
        width: Target width (defaults to clip width if None).
        height: Target height (defaults to clip height if None).
        shift: Subpixel shift (top, left) applied during scaling.
        **kwargs: Additional arguments forwarded to the scale function.

    Returns:
        The scaled clip.
    """
    width, height = self._wh_norm(clip, width, height)

    scale_args = _norm_props_enums(self.get_scale_args(clip, shift, width, height, **kwargs))

    logger.debug("%s: Passing clip: %r; arguments: %s", self.scale, clip, scale_args)

    return self.scale_function(clip, **scale_args)

shift

shift(
    clip: VideoNode, shift: tuple[TopShift, LeftShift], /, **kwargs: Any
) -> VideoNode
shift(
    clip: VideoNode,
    shift_top: float | list[float],
    shift_left: float | list[float],
    /,
    **kwargs: Any,
) -> VideoNode
shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float],
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any,
) -> VideoNode

Apply a subpixel shift to the clip using the kernel's scaling logic.

If a single float or tuple is provided, it is used uniformly. If a list is given, the shift is applied per plane.

Keyword arguments passed during initialization are automatically injected here, unless explicitly overridden by the arguments provided at call time. Only arguments that match named parameters in this method are injected.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • shifts_or_top

    (float | tuple[float, float] | list[float]) –

    Either a single vertical shift, a (top, left) tuple, or a list of vertical shifts.

  • shift_left

    (float | list[float] | None, default: None ) –

    Horizontal shift or list of horizontal shifts. Ignored if shifts_or_top is a tuple.

  • **kwargs

    (Any, default: {} ) –

    Additional arguments passed to the internal scale call.

Returns:

  • VideoNode

    A new clip with the applied shift.

Raises:

  • VariableFormatError

    If the input clip has variable format.

  • CustomValueError

    If the input clip is GRAY but lists of shift has been passed.

Source code in vskernels/abstract/base.py
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
def shift(
    self,
    clip: vs.VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float],
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any,
) -> vs.VideoNode:
    """
    Apply a subpixel shift to the clip using the kernel's scaling logic.

    If a single float or tuple is provided, it is used uniformly.
    If a list is given, the shift is applied per plane.

    Keyword arguments passed during initialization are automatically injected here,
    unless explicitly overridden by the arguments provided at call time.
    Only arguments that match named parameters in this method are injected.

    Args:
        clip: The source clip.
        shifts_or_top: Either a single vertical shift, a (top, left) tuple, or a list of vertical shifts.
        shift_left: Horizontal shift or list of horizontal shifts. Ignored if `shifts_or_top` is a tuple.
        **kwargs: Additional arguments passed to the internal `scale` call.

    Returns:
        A new clip with the applied shift.

    Raises:
        VariableFormatError: If the input clip has variable format.
        CustomValueError: If the input clip is GRAY but lists of shift has been passed.
    """

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

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

    if isinstance(shifts_or_top, (int, float)) and isinstance(shift_left, (int, float, NoneType)):
        return _shift(clip, (shifts_or_top, shift_left or 0))

    if shift_left is None:
        shift_left = 0.0

    shifts_top = normalize_seq(shifts_or_top, clip.format.num_planes)
    shifts_left = normalize_seq(shift_left, clip.format.num_planes)

    if clip.format.num_planes == 1:
        return _shift(clip, (shifts_top[0], shifts_left[0]))

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

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

supersample

supersample(
    clip: VideoNode,
    rfactor: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode

Supersample a clip by a given scaling factor.

Keyword arguments passed during initialization are automatically injected here, unless explicitly overridden by the arguments provided at call time. Only arguments that match named parameters in this method are injected.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • rfactor

    (float, default: 2.0 ) –

    Scaling factor for supersampling.

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left) applied during scaling.

  • **kwargs

    (Any, default: {} ) –

    Additional arguments forwarded to the scale function.

Raises:

Returns:

  • VideoNode

    The supersampled clip.

Source code in vskernels/abstract/base.py
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
def supersample(
    self, clip: vs.VideoNode, rfactor: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    """
    Supersample a clip by a given scaling factor.

    Keyword arguments passed during initialization are automatically injected here,
    unless explicitly overridden by the arguments provided at call time.
    Only arguments that match named parameters in this method are injected.

    Args:
        clip: The source clip.
        rfactor: Scaling factor for supersampling.
        shift: Subpixel shift (top, left) applied during scaling.
        **kwargs: Additional arguments forwarded to the scale function.

    Raises:
        CustomValueError: If resulting resolution is non-positive.

    Returns:
        The supersampled clip.
    """
    assert check_variable_resolution(clip, self.supersample)

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

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

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

Resampler

Resampler(**kwargs: Any)

Bases: BaseScaler

Abstract resampling interface.

Subclasses must define the resample_function used to perform the resampling.

Initialize the scaler with optional keyword arguments.

These keyword arguments are automatically forwarded to the implemented_funcs methods but only if the method explicitly accepts them as named parameters. If the same keyword is passed to both __init__ and one of the implemented_funcs, the one passed to func takes precedence.

Parameters:

  • **kwargs

    (Any, default: {} ) –

    Keyword arguments that configure the internal scaling behavior.

Methods:

  • ensure_obj

    Ensure that the input is a scaler instance, resolving it if necessary.

  • from_param

    Resolve and return a scaler type from a given input (string, type, or instance).

  • get_resample_args

    Construct the argument dictionary used for resampling.

  • implemented_funcs

    Returns a set of function names that are implemented in the current class and the parent classes.

  • is_abstract

    Return True if this class can't be instantiated.

  • kernel_radius

    Return the effective kernel radius for the scaler.

  • resample

    Resample a video clip to the given format.

Attributes:

  • kwargs (dict[str, Any]) –

    Arguments passed to the implemented funcs or internal scale function.

  • pretty_string (str) –

    Cached property returning a user-friendly string representation.

  • resample_function (Callable[..., VideoNode]) –

    Resample function called internally when performing resampling operations.

Source code in vskernels/abstract/base.py
334
335
336
337
338
339
340
341
342
343
344
345
346
347
def __init__(self, **kwargs: Any) -> None:
    """
    Initialize the scaler with optional keyword arguments.

    These keyword arguments are automatically forwarded to
    the [implemented_funcs][vskernels.BaseScaler.implemented_funcs] methods but only
    if the method explicitly accepts them as named parameters.
    If the same keyword is passed to both `__init__` and one of the
    [implemented_funcs][vskernels.BaseScaler.implemented_funcs], the one passed to `func` takes precedence.

    Args:
        **kwargs: Keyword arguments that configure the internal scaling behavior.
    """
    self.kwargs = kwargs

kwargs instance-attribute

kwargs: dict[str, Any] = kwargs

Arguments passed to the implemented funcs or internal scale function.

pretty_string property

pretty_string: str

Cached property returning a user-friendly string representation.

Returns:

  • str

    Pretty-printed string with arguments.

resample_function instance-attribute

resample_function: Callable[..., VideoNode]

Resample function called internally when performing resampling operations.

ensure_obj classmethod

ensure_obj(
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> Self

Ensure that the input is a scaler instance, resolving it if necessary.

Parameters:

  • scaler

    (str | type[Self] | Self | None, default: None ) –

    Scaler identifier (string, class, or instance).

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

  • Self

    Scaler instance.

Source code in vskernels/abstract/base.py
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
@classmethod
def ensure_obj(
    cls,
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> Self:
    """
    Ensure that the input is a scaler instance, resolving it if necessary.

    Args:
        scaler: Scaler identifier (string, class, or instance).
        func_except: Function returned for custom error handling.

    Returns:
        Scaler instance.
    """
    return _base_ensure_obj(cls, scaler, func_except)

from_param classmethod

from_param(
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> type[Self]

Resolve and return a scaler type from a given input (string, type, or instance).

Parameters:

  • scaler

    (str | type[Self] | Self | None, default: None ) –

    Scaler identifier (string, class, or instance).

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

Source code in vskernels/abstract/base.py
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
@classmethod
def from_param(
    cls,
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> type[Self]:
    """
    Resolve and return a scaler type from a given input (string, type, or instance).

    Args:
        scaler: Scaler identifier (string, class, or instance).
        func_except: Function returned for custom error handling.

    Returns:
        Resolved scaler type.
    """
    return _base_from_param(cls, scaler, cls._err_class, func_except)

get_resample_args

get_resample_args(
    clip: VideoNode,
    format: SupportsInt | VideoFormatLike | HoldsVideoFormat,
    matrix: MatrixLike | None,
    matrix_in: MatrixLike | None,
    transfer: TransferLike | None = None,
    transfer_in: TransferLike | None = None,
    primaries: PrimariesLike | None = None,
    primaries_in: PrimariesLike | None = None,
    **kwargs: Any
) -> dict[str, Any]

Construct the argument dictionary used for resampling.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • format

    (SupportsInt | VideoFormatLike | HoldsVideoFormat) –

    The target video format, which can either be:

    • an integer format ID,
    • a vs.PresetVideoFormat or vs.VideoFormat,
    • or a source from which a valid VideoFormat can be extracted.
  • matrix

    (MatrixLike | None) –

    The matrix for color transformation.

  • matrix_in

    (MatrixLike | None) –

    The input matrix for color transformation.

  • transfer

    (TransferLike | None, default: None ) –

    The transfer for color transformation.

  • transfer_in

    (TransferLike | None, default: None ) –

    The input transfer for color transformation.

  • primaries

    (PrimariesLike | None, default: None ) –

    The primaries for color transformation.

  • primaries_in

    (PrimariesLike | None, default: None ) –

    The input primaries for color transformation.

  • **kwargs

    (Any, default: {} ) –

    Additional keyword arguments for resampling.

Returns:

  • dict[str, Any]

    A dictionary containing the resampling arguments.

Source code in vskernels/abstract/base.py
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
def get_resample_args(
    self,
    clip: vs.VideoNode,
    format: SupportsInt | VideoFormatLike | HoldsVideoFormat,
    matrix: MatrixLike | None,
    matrix_in: MatrixLike | None,
    transfer: TransferLike | None = None,
    transfer_in: TransferLike | None = None,
    primaries: PrimariesLike | None = None,
    primaries_in: PrimariesLike | None = None,
    **kwargs: Any,
) -> dict[str, Any]:
    """
    Construct the argument dictionary used for resampling.

    Args:
        clip: The source clip.
        format: The target video format, which can either be:

               - an integer format ID,
               - a `vs.PresetVideoFormat` or `vs.VideoFormat`,
               - or a source from which a valid `VideoFormat` can be extracted.
        matrix: The matrix for color transformation.
        matrix_in: The input matrix for color transformation.
        transfer: The transfer for color transformation.
        transfer_in: The input transfer for color transformation.
        primaries: The primaries for color transformation.
        primaries_in: The input primaries for color transformation.
        **kwargs: Additional keyword arguments for resampling.

    Returns:
        A dictionary containing the resampling arguments.
    """
    return _resolve_video_spec_args(
        clip,
        **(
            {
                "format": get_video_format(format),
                "matrix": Matrix.from_param_with_fallback(matrix),
                "matrix_in": Matrix.from_param_with_fallback(matrix_in),
                "transfer": Transfer.from_param_with_fallback(transfer),
                "transfer_in": Transfer.from_param_with_fallback(transfer_in),
                "primaries": Primaries.from_param_with_fallback(primaries),
                "primaries_in": Primaries.from_param_with_fallback(primaries_in),
            }
            | self.kwargs
            | kwargs
        ),
    )

implemented_funcs classmethod

implemented_funcs() -> frozenset[str]

Returns a set of function names that are implemented in the current class and the parent classes.

These functions determine which keyword arguments will be extracted from the __init__ method.

Returns:

Source code in vskernels/abstract/base.py
460
461
462
463
464
465
466
467
468
469
470
471
@classproperty.cached
@classmethod
def implemented_funcs(cls) -> frozenset[str]:
    """
    Returns a set of function names that are implemented in the current class and the parent classes.

    These functions determine which keyword arguments will be extracted from the `__init__` method.

    Returns:
        Frozen set of function names.
    """
    return frozenset(func for klass in cls.mro() for func in getattr(klass, "_implemented_funcs", ()))

is_abstract classmethod

is_abstract() -> bool

Return True if this class can't be instantiated.

Source code in vskernels/abstract/base.py
454
455
456
457
458
@classproperty
@classmethod
def is_abstract(cls) -> bool:
    """Return True if this class can't be instantiated."""
    return _is_base_scaler_abstract(cls)

kernel_radius

kernel_radius() -> int

Return the effective kernel radius for the scaler.

Raises:

Returns:

  • int

    Kernel radius.

Source code in vskernels/abstract/base.py
417
418
419
420
421
422
423
424
425
426
427
428
@BaseScalerMeta.cachedproperty
def kernel_radius(self) -> int:
    """
    Return the effective kernel radius for the scaler.

    Raises:
        CustomNotImplementedError: If no kernel radius is defined.

    Returns:
        Kernel radius.
    """
    ...

resample

resample(
    clip: VideoNode,
    format: SupportsInt | VideoFormatLike | HoldsVideoFormat,
    matrix: MatrixLike | None = None,
    matrix_in: MatrixLike | None = None,
    transfer: TransferLike | None = None,
    transfer_in: TransferLike | None = None,
    primaries: PrimariesLike | None = None,
    primaries_in: PrimariesLike | None = None,
    **kwargs: Any
) -> VideoNode

Resample a video clip to the given format.

Keyword arguments passed during initialization are automatically injected here, unless explicitly overridden by the arguments provided at call time. Only arguments that match named parameters in this method are injected.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • format

    (SupportsInt | VideoFormatLike | HoldsVideoFormat) –

    The target video format, which can either be:

    • an integer format ID,
    • a vs.PresetVideoFormat or vs.VideoFormat,
    • or a source from which a valid VideoFormat can be extracted.
  • matrix

    (MatrixLike | None, default: None ) –

    An optional color transformation matrix to apply.

  • matrix_in

    (MatrixLike | None, default: None ) –

    An optional input matrix for color transformations.

  • transfer

    (TransferLike | None, default: None ) –

    An optional color transformation transfer to apply.

  • transfer_in

    (TransferLike | None, default: None ) –

    An optional input transfer for color transformations.

  • primaries

    (PrimariesLike | None, default: None ) –

    Optional color transformation primaries to apply.

  • primaries_in

    (PrimariesLike | None, default: None ) –

    Optional input primaries for color transformations.

  • **kwargs

    (Any, default: {} ) –

    Additional keyword arguments passed to the resample_function.

Returns:

  • VideoNode

    The resampled clip.

Source code in vskernels/abstract/base.py
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
def resample(
    self,
    clip: vs.VideoNode,
    format: SupportsInt | VideoFormatLike | HoldsVideoFormat,
    matrix: MatrixLike | None = None,
    matrix_in: MatrixLike | None = None,
    transfer: TransferLike | None = None,
    transfer_in: TransferLike | None = None,
    primaries: PrimariesLike | None = None,
    primaries_in: PrimariesLike | None = None,
    **kwargs: Any,
) -> vs.VideoNode:
    """
    Resample a video clip to the given format.

    Keyword arguments passed during initialization are automatically injected here,
    unless explicitly overridden by the arguments provided at call time.
    Only arguments that match named parameters in this method are injected.

    Args:
        clip: The source clip.
        format: The target video format, which can either be:

               - an integer format ID,
               - a `vs.PresetVideoFormat` or `vs.VideoFormat`,
               - or a source from which a valid `VideoFormat` can be extracted.
        matrix: An optional color transformation matrix to apply.
        matrix_in: An optional input matrix for color transformations.
        transfer: An optional color transformation transfer to apply.
        transfer_in: An optional input transfer for color transformations.
        primaries: Optional color transformation primaries to apply.
        primaries_in: Optional input primaries for color transformations.
        **kwargs: Additional keyword arguments passed to the `resample_function`.

    Returns:
        The resampled clip.
    """

    resample_args = _norm_props_enums(
        self.get_resample_args(
            clip, format, matrix, matrix_in, transfer, transfer_in, primaries, primaries_in, **kwargs
        )
    )

    logger.debug("%s: Passing clip: %r; arguments: %s", self.resample, clip, resample_args)

    return self.resample_function(clip, **resample_args)

Scaler

Scaler(**kwargs: Any)

Bases: BaseScaler

Abstract scaling interface.

Subclasses should define a scale_function to perform the actual scaling logic.

Initialize the scaler with optional keyword arguments.

These keyword arguments are automatically forwarded to the implemented_funcs methods but only if the method explicitly accepts them as named parameters. If the same keyword is passed to both __init__ and one of the implemented_funcs, the one passed to func takes precedence.

Parameters:

  • **kwargs

    (Any, default: {} ) –

    Keyword arguments that configure the internal scaling behavior.

Methods:

  • ensure_obj

    Ensure that the input is a scaler instance, resolving it if necessary.

  • from_param

    Resolve and return a scaler type from a given input (string, type, or instance).

  • get_scale_args

    Generate the keyword arguments used for scaling.

  • implemented_funcs

    Returns a set of function names that are implemented in the current class and the parent classes.

  • is_abstract

    Return True if this class can't be instantiated.

  • kernel_radius

    Return the effective kernel radius for the scaler.

  • scale

    Scale a clip to a specified resolution.

  • supersample

    Supersample a clip by a given scaling factor.

Attributes:

  • kwargs (dict[str, Any]) –

    Arguments passed to the implemented funcs or internal scale function.

  • pretty_string (str) –

    Cached property returning a user-friendly string representation.

  • scale_function (Callable[..., VideoNode]) –

    Scale function called internally when performing scaling operations.

Source code in vskernels/abstract/base.py
334
335
336
337
338
339
340
341
342
343
344
345
346
347
def __init__(self, **kwargs: Any) -> None:
    """
    Initialize the scaler with optional keyword arguments.

    These keyword arguments are automatically forwarded to
    the [implemented_funcs][vskernels.BaseScaler.implemented_funcs] methods but only
    if the method explicitly accepts them as named parameters.
    If the same keyword is passed to both `__init__` and one of the
    [implemented_funcs][vskernels.BaseScaler.implemented_funcs], the one passed to `func` takes precedence.

    Args:
        **kwargs: Keyword arguments that configure the internal scaling behavior.
    """
    self.kwargs = kwargs

kwargs instance-attribute

kwargs: dict[str, Any] = kwargs

Arguments passed to the implemented funcs or internal scale function.

pretty_string property

pretty_string: str

Cached property returning a user-friendly string representation.

Returns:

  • str

    Pretty-printed string with arguments.

scale_function instance-attribute

scale_function: Callable[..., VideoNode]

Scale function called internally when performing scaling operations.

ensure_obj classmethod

ensure_obj(
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> Self

Ensure that the input is a scaler instance, resolving it if necessary.

Parameters:

  • scaler

    (str | type[Self] | Self | None, default: None ) –

    Scaler identifier (string, class, or instance).

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

  • Self

    Scaler instance.

Source code in vskernels/abstract/base.py
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
@classmethod
def ensure_obj(
    cls,
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> Self:
    """
    Ensure that the input is a scaler instance, resolving it if necessary.

    Args:
        scaler: Scaler identifier (string, class, or instance).
        func_except: Function returned for custom error handling.

    Returns:
        Scaler instance.
    """
    return _base_ensure_obj(cls, scaler, func_except)

from_param classmethod

from_param(
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> type[Self]

Resolve and return a scaler type from a given input (string, type, or instance).

Parameters:

  • scaler

    (str | type[Self] | Self | None, default: None ) –

    Scaler identifier (string, class, or instance).

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

Source code in vskernels/abstract/base.py
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
@classmethod
def from_param(
    cls,
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> type[Self]:
    """
    Resolve and return a scaler type from a given input (string, type, or instance).

    Args:
        scaler: Scaler identifier (string, class, or instance).
        func_except: Function returned for custom error handling.

    Returns:
        Resolved scaler type.
    """
    return _base_from_param(cls, scaler, cls._err_class, func_except)

get_scale_args

get_scale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]

Generate the keyword arguments used for scaling.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left).

  • width

    (int | None, default: None ) –

    Target width.

  • height

    (int | None, default: None ) –

    Target height.

  • **kwargs

    (Any, default: {} ) –

    Extra parameters to merge.

Returns:

  • dict[str, Any]

    Final dictionary of keyword arguments for the scale function.

Source code in vskernels/abstract/base.py
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
def get_scale_args(
    self,
    clip: vs.VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any,
) -> dict[str, Any]:
    """
    Generate the keyword arguments used for scaling.

    Args:
        clip: The source clip.
        shift: Subpixel shift (top, left).
        width: Target width.
        height: Target height.
        **kwargs: Extra parameters to merge.

    Returns:
        Final dictionary of keyword arguments for the scale function.
    """
    return {"width": width, "height": height, "src_top": shift[0], "src_left": shift[1]} | self.kwargs | kwargs

implemented_funcs classmethod

implemented_funcs() -> frozenset[str]

Returns a set of function names that are implemented in the current class and the parent classes.

These functions determine which keyword arguments will be extracted from the __init__ method.

Returns:

Source code in vskernels/abstract/base.py
460
461
462
463
464
465
466
467
468
469
470
471
@classproperty.cached
@classmethod
def implemented_funcs(cls) -> frozenset[str]:
    """
    Returns a set of function names that are implemented in the current class and the parent classes.

    These functions determine which keyword arguments will be extracted from the `__init__` method.

    Returns:
        Frozen set of function names.
    """
    return frozenset(func for klass in cls.mro() for func in getattr(klass, "_implemented_funcs", ()))

is_abstract classmethod

is_abstract() -> bool

Return True if this class can't be instantiated.

Source code in vskernels/abstract/base.py
454
455
456
457
458
@classproperty
@classmethod
def is_abstract(cls) -> bool:
    """Return True if this class can't be instantiated."""
    return _is_base_scaler_abstract(cls)

kernel_radius

kernel_radius() -> int

Return the effective kernel radius for the scaler.

Raises:

Returns:

  • int

    Kernel radius.

Source code in vskernels/abstract/base.py
417
418
419
420
421
422
423
424
425
426
427
428
@BaseScalerMeta.cachedproperty
def kernel_radius(self) -> int:
    """
    Return the effective kernel radius for the scaler.

    Raises:
        CustomNotImplementedError: If no kernel radius is defined.

    Returns:
        Kernel radius.
    """
    ...

scale

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

Scale a clip to a specified resolution.

Keyword arguments passed during initialization are automatically injected here, unless explicitly overridden by the arguments provided at call time. Only arguments that match named parameters in this method are injected.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • width

    (int | None, default: None ) –

    Target width (defaults to clip width if None).

  • height

    (int | None, default: None ) –

    Target height (defaults to clip height if None).

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left) applied during scaling.

  • **kwargs

    (Any, default: {} ) –

    Additional arguments forwarded to the scale function.

Returns:

  • VideoNode

    The scaled clip.

Source code in vskernels/abstract/base.py
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
def scale(
    self,
    clip: vs.VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any,
) -> vs.VideoNode:
    """
    Scale a clip to a specified resolution.

    Keyword arguments passed during initialization are automatically injected here,
    unless explicitly overridden by the arguments provided at call time.
    Only arguments that match named parameters in this method are injected.

    Args:
        clip: The source clip.
        width: Target width (defaults to clip width if None).
        height: Target height (defaults to clip height if None).
        shift: Subpixel shift (top, left) applied during scaling.
        **kwargs: Additional arguments forwarded to the scale function.

    Returns:
        The scaled clip.
    """
    width, height = self._wh_norm(clip, width, height)

    scale_args = _norm_props_enums(self.get_scale_args(clip, shift, width, height, **kwargs))

    logger.debug("%s: Passing clip: %r; arguments: %s", self.scale, clip, scale_args)

    return self.scale_function(clip, **scale_args)

supersample

supersample(
    clip: VideoNode,
    rfactor: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode

Supersample a clip by a given scaling factor.

Keyword arguments passed during initialization are automatically injected here, unless explicitly overridden by the arguments provided at call time. Only arguments that match named parameters in this method are injected.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • rfactor

    (float, default: 2.0 ) –

    Scaling factor for supersampling.

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left) applied during scaling.

  • **kwargs

    (Any, default: {} ) –

    Additional arguments forwarded to the scale function.

Raises:

Returns:

  • VideoNode

    The supersampled clip.

Source code in vskernels/abstract/base.py
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
def supersample(
    self, clip: vs.VideoNode, rfactor: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    """
    Supersample a clip by a given scaling factor.

    Keyword arguments passed during initialization are automatically injected here,
    unless explicitly overridden by the arguments provided at call time.
    Only arguments that match named parameters in this method are injected.

    Args:
        clip: The source clip.
        rfactor: Scaling factor for supersampling.
        shift: Subpixel shift (top, left) applied during scaling.
        **kwargs: Additional arguments forwarded to the scale function.

    Raises:
        CustomValueError: If resulting resolution is non-positive.

    Returns:
        The supersampled clip.
    """
    assert check_variable_resolution(clip, self.supersample)

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

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

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