Skip to content

util

Type Aliases:

  • NoScaleLike

    Type alias for anything that can resolve to a NoScale scaler.

Classes:

  • BaseMixedScaler

    An abstract base class to provide mixed or chained scaling for BaseScaler-like classes.

  • BaseScalerSpecializer

    An abstract base class to provide specialization logic for BaseScaler-like classes.

  • LinearLight

    Utility class for processing a clip in linear format.

  • MixedScalerProcess

    An abstract class for chained scaling with an additional processing step.

  • NoScale

    A utility scaler class that performs no scaling on the input clip.

  • ScalerSpecializer

    An abstract base class to provide specialization logic for Scaler-like classes.

Functions:

NoScaleLike

NoScaleLike = str | type[NoScale[_ScalerT]] | NoScale[_ScalerT]

Type alias for anything that can resolve to a NoScale scaler.

This includes
  • A string identifier.
  • A class type subclassing NoScale.
  • An instance of NoScale.

BaseMixedScaler

BaseMixedScaler(**kwargs: Any)

Bases: BaseScalerSpecializer[DefaultScalerT]

An abstract base class to provide mixed or chained scaling for BaseScaler-like classes.

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.

  • kernel_radius

    Return the effective kernel radius for the scaler.

Attributes:

Source code in vskernels/util.py
126
127
128
129
130
131
132
133
def __init__(self, **kwargs: Any) -> None:
    super().__init__()

    for k in kwargs.copy():
        if hasattr(self, k):
            setattr(self, k, kwargs.pop(k))

    self.kwargs = kwargs

default_scaler class-attribute

default_scaler: type[BaseScaler]

kwargs instance-attribute

kwargs = kwargs

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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
@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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
@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
443
444
445
446
447
448
449
450
451
452
453
454
@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", ()))

kernel_radius

kernel_radius() -> int

Return the effective kernel radius for the scaler.

Raises:

  • CustomNotImplementedError

    If no kernel radius is defined.

Returns:

  • int

    Kernel radius.

Source code in vskernels/abstract/base.py
406
407
408
409
410
411
412
413
414
415
416
417
@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.
    """
    ...

BaseMixedScalerMeta

Bases: BaseScalerSpecializerMeta

Meta class for BaseMixedScaler to handle mixed scaling logic.

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.

Source code in vskernels/abstract/base.py
224
225
226
def __init__[_BaseScalerT: BaseScaler, **P](
    self, func: Callable[Concatenate[_BaseScalerT, P], R]
) -> None: ...

BaseScalerSpecializer

BaseScalerSpecializer(**kwargs: Any)

Bases: BaseScaler

An abstract base class to provide specialization logic for BaseScaler-like classes.

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.

  • kernel_radius

    Return the effective kernel radius for the scaler.

Attributes:

Source code in vskernels/util.py
126
127
128
129
130
131
132
133
def __init__(self, **kwargs: Any) -> None:
    super().__init__()

    for k in kwargs.copy():
        if hasattr(self, k):
            setattr(self, k, kwargs.pop(k))

    self.kwargs = kwargs

default_scaler class-attribute

default_scaler: type[BaseScaler]

kwargs instance-attribute

kwargs = kwargs

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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
@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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
@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
443
444
445
446
447
448
449
450
451
452
453
454
@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", ()))

kernel_radius

kernel_radius() -> int

Return the effective kernel radius for the scaler.

Raises:

  • CustomNotImplementedError

    If no kernel radius is defined.

Returns:

  • int

    Kernel radius.

Source code in vskernels/abstract/base.py
406
407
408
409
410
411
412
413
414
415
416
417
@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.
    """
    ...

BaseScalerSpecializerMeta

Bases: BaseScalerMeta

Meta class for BaseScalerSpecializer to handle specialization logic.

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.

Source code in vskernels/abstract/base.py
224
225
226
def __init__[_BaseScalerT: BaseScaler, **P](
    self, func: Callable[Concatenate[_BaseScalerT, P], R]
) -> None: ...

LinearLight dataclass

LinearLight(
    clip: VideoNode,
    sigmoid: bool | tuple[Slope, Center] = False,
    resampler: ResamplerLike = Catrom,
    out_fmt: int | VideoFormatLike | HoldsVideoFormat | None = None,
)

Bases: AbstractContextManager[LinearLightProcessing], VSObjectABC

Utility class for processing a clip in linear format.

Usage
with LinearLight(clip, ...) as ll:
    ll.linear = function(ll.linear, ...)
out = ll.out

Methods:

  • from_func

    Decorator version of LinearLight.

Attributes:

clip instance-attribute

clip: VideoNode

Input clip.

out_fmt class-attribute instance-attribute

out_fmt: int | VideoFormatLike | HoldsVideoFormat | None = None

Optional output format.

resampler class-attribute instance-attribute

resampler: ResamplerLike = Catrom

Resampler for converting to linear format and converting back to input clip format.

sigmoid class-attribute instance-attribute

sigmoid: bool | tuple[Slope, Center] = False

Whether to use sigmoid transfer curve. Can be True, False, or a tuple of (slope, center). True applies the defaults values (6.5, 0.75). Keep in mind sigmoid slope has to be in range 1.0-20.0. (inclusive) and sigmoid center has to be in range 0.0-1.0 (inclusive).

from_func classmethod

from_func(
    func: Callable[Concatenate[VideoNode, P], VideoNode],
    /,
    sigmoid: bool | tuple[Slope, Center] = False,
    resampler: ResamplerLike = Catrom,
    out_fmt: int | VideoFormatLike | HoldsVideoFormat | None = None,
) -> Callable[Concatenate[VideoNode, P], VideoNode]
from_func(
    *,
    sigmoid: bool | tuple[Slope, Center] = False,
    resampler: ResamplerLike = Catrom,
    out_fmt: int | VideoFormatLike | HoldsVideoFormat | None = None
) -> Callable[
    [Callable[Concatenate[VideoNode, P], VideoNode]],
    Callable[Concatenate[VideoNode, P], VideoNode],
]
from_func(
    func: Callable[Concatenate[VideoNode, P], VideoNode] | None = None,
    /,
    sigmoid: bool | tuple[Slope, Center] = False,
    resampler: ResamplerLike = Catrom,
    out_fmt: int | VideoFormatLike | HoldsVideoFormat | None = None,
) -> (
    Callable[Concatenate[VideoNode, P], VideoNode]
    | Callable[
        [Callable[Concatenate[VideoNode, P], VideoNode]],
        Callable[Concatenate[VideoNode, P], VideoNode],
    ]
)

Decorator version of LinearLight.

Source code in vskernels/util.py
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
@classmethod
def from_func[**P](
    cls,
    func: Callable[Concatenate[vs.VideoNode, P], vs.VideoNode] | None = None,
    /,
    sigmoid: bool | tuple[Slope, Center] = False,
    resampler: ResamplerLike = Catrom,
    out_fmt: int | VideoFormatLike | HoldsVideoFormat | None = None,
) -> (
    Callable[Concatenate[vs.VideoNode, P], vs.VideoNode]
    | Callable[
        [Callable[Concatenate[vs.VideoNode, P], vs.VideoNode]], Callable[Concatenate[vs.VideoNode, P], vs.VideoNode]
    ]
):
    """
    Decorator version of LinearLight.
    """

    if func is None:
        return partial(cls.from_func, sigmoid=sigmoid, resampler=resampler, out_fmt=out_fmt)

    @wraps(func)
    def _wrapped(clip: vs.VideoNode, *args: P.args, **kwargs: P.kwargs) -> vs.VideoNode:
        with cls(clip, sigmoid, resampler, out_fmt) as ll:
            ll.linear = func(clip, *args, **kwargs)
        return ll.out

    return _wrapped

LinearLightProcessing dataclass

LinearLightProcessing(ll: LinearLight)

Bases: VSObject

Methods:

Attributes:

linear class-attribute instance-attribute

linear = cachedproperty[VideoNode](get_linear, set_linear)

Cached property to use for linear light processing.

ll instance-attribute

get_linear

get_linear() -> VideoNode

Getter for linear cached property.

Source code in vskernels/util.py
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
def get_linear(self) -> vs.VideoNode:
    """
    Getter for `linear` cached property.
    """
    wclip = self.ll._resampler.resample(
        self.ll._wclip,
        vs.RGBS if self.ll._wclip.format.color_family in (vs.YUV, vs.RGB) else vs.GRAYS,
        matrix_in=self.ll._matrix,
        transfer_in=self.ll._curve,
        transfer=Transfer.LINEAR,
    )

    if self.ll.sigmoid:
        wclip = norm_expr(
            wclip,
            "{center} 1 {slope} / 1 x 0 max 1 min {scale} * {offset} + / 1 - log * -",
            center=self.ll._scenter,
            slope=self.ll._sslope,
            scale=self.ll._sscale,
            offset=self.ll._soffset,
            func=self.__class__,
        )

    return wclip

out

out() -> VideoNode
Source code in vskernels/util.py
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
@cachedproperty
def out(self) -> vs.VideoNode:
    if not self.ll._exited:
        raise CustomRuntimeError(
            "You can't get .out while still inside of the context manager!", func=self.__class__
        )

    if not hasattr(self, "_linear"):
        raise CustomValueError("You need to set .linear before getting .out!", self.__class__)

    if self.ll.sigmoid:
        processed = norm_expr(
            self._linear,
            "1 1 {slope} {center} x 0 max 1 min - * exp + / {offset} - {scale} /",
            slope=self.ll._sslope,
            center=self.ll._scenter,
            offset=self.ll._soffset,
            scale=self.ll._sscale,
            func=self.__class__,
        )
    else:
        processed = self._linear

    processed = vs.core.resize2.Point(processed, transfer_in=Transfer.LINEAR, transfer=self.ll._curve)

    return resample_to(processed, self.ll._fmt, self.ll._matrix, self.ll._resampler)

set_linear

set_linear(processed: VideoNode) -> None

Setter for linear cached property.

Source code in vskernels/util.py
366
367
368
369
370
371
372
373
374
def set_linear(self, processed: vs.VideoNode) -> None:
    """
    Setter for `linear` cached property.
    """
    if self.ll._exited:
        raise CustomRuntimeError(
            "You can't set .linear after going out of the context manager!", func=self.__class__
        )
    self._linear = processed

MixedScalerProcess

MixedScalerProcess(*, function: VSFunctionNoArgs, **kwargs: Any)

Bases: BaseMixedScaler[DefaultScalerT, *_BaseScalerTs], Scaler

An abstract class for chained scaling with an additional processing step.

Initialize the MixedScalerProcess.

Parameters:

  • function

    (VSFunctionNoArgs) –

    A function to apply on the scaling pipeline.

  • **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.

  • 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:

Source code in vskernels/util.py
324
325
326
327
328
329
330
331
332
333
334
def __init__(self, *, function: VSFunctionNoArgs, **kwargs: Any) -> None:
    """
    Initialize the MixedScalerProcess.

    Args:
        function: A function to apply on the scaling pipeline.
        **kwargs: Keyword arguments that configure the internal scaling behavior.
    """
    super().__init__(**kwargs)

    self.function = function

default_scaler class-attribute

default_scaler: type[BaseScaler]

function instance-attribute

function = function

kwargs instance-attribute

kwargs = kwargs

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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
@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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
@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
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
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
443
444
445
446
447
448
449
450
451
452
453
454
@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", ()))

kernel_radius

kernel_radius() -> int

Return the effective kernel radius for the scaler.

Raises:

  • CustomNotImplementedError

    If no kernel radius is defined.

Returns:

  • int

    Kernel radius.

Source code in vskernels/abstract/base.py
406
407
408
409
410
411
412
413
414
415
416
417
@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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
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)
    check_correct_subsampling(clip, width, height)

    return self.scale_function(clip, **_norm_props_enums(self.get_scale_args(clip, shift, width, height, **kwargs)))

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:

  • CustomValueError

    If resulting resolution is non-positive.

Returns:

  • VideoNode

    The supersampled clip.

Source code in vskernels/abstract/base.py
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
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)

NoScale

NoScale(**kwargs: Any)

Bases: ScalerSpecializer[_ScalerWithCatromDefaultT]

A utility scaler class that performs no scaling on the input clip.

If used without a specified scaler, it defaults to inheriting from Catrom.

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).

  • from_scaler

    Create a specialized NoScale class using a specific scaler.

  • 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.

  • kernel_radius

    Return the effective kernel radius for the scaler.

  • scale

    Return the input clip unscaled, validating that the dimensions are consistent.

  • supersample

    Supersample a clip by a given scaling factor.

Attributes:

Source code in vskernels/util.py
126
127
128
129
130
131
132
133
def __init__(self, **kwargs: Any) -> None:
    super().__init__()

    for k in kwargs.copy():
        if hasattr(self, k):
            setattr(self, k, kwargs.pop(k))

    self.kwargs = kwargs

default_scaler class-attribute instance-attribute

default_scaler = Catrom

kwargs instance-attribute

kwargs = kwargs

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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
@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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
@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)

from_scaler classmethod

from_scaler(scaler: ScalerLike) -> type[NoScale[Scaler]]

Create a specialized NoScale class using a specific scaler.

Parameters:

  • scaler

    (ScalerLike) –

    A Scaler instance, type or string used as a base for specialization.

Returns:

  • type[NoScale[Scaler]]

    A dynamically created NoScale subclass based on the given scaler.

Source code in vskernels/util.py
213
214
215
216
217
218
219
220
221
222
223
224
@classmethod
def from_scaler(cls, scaler: ScalerLike) -> type[NoScale[Scaler]]:
    """
    Create a specialized NoScale class using a specific scaler.

    Args:
        scaler: A Scaler instance, type or string used as a base for specialization.

    Returns:
        A dynamically created NoScale subclass based on the given scaler.
    """
    return NoScale[Scaler.from_param(scaler)]  # type: ignore[return-value,misc]

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
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
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
443
444
445
446
447
448
449
450
451
452
453
454
@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", ()))

kernel_radius

kernel_radius() -> int

Return the effective kernel radius for the scaler.

Raises:

  • CustomNotImplementedError

    If no kernel radius is defined.

Returns:

  • int

    Kernel radius.

Source code in vskernels/abstract/base.py
406
407
408
409
410
411
412
413
414
415
416
417
@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

Return the input clip unscaled, validating that the dimensions are consistent.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • width

    (int | None, default: None ) –

    Optional width to validate against the clip's width.

  • height

    (int | None, default: None ) –

    Optional height to validate against the clip's height.

  • shift

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

    Subpixel shift (top, left).

  • **kwargs

    (Any, default: {} ) –

    Additional arguments forwarded to the scale function.

Raises:

  • CustomValueError

    If width or height differ from the clip's dimensions.

Source code in vskernels/util.py
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
def scale(
    self,
    clip: vs.VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any,
) -> vs.VideoNode:
    """
    Return the input clip unscaled, validating that the dimensions are consistent.

    Args:
        clip: The source clip.
        width: Optional width to validate against the clip's width.
        height: Optional height to validate against the clip's height.
        shift: Subpixel shift (top, left).
        **kwargs: Additional arguments forwarded to the scale function.

    Raises:
        CustomValueError: If `width` or `height` differ from the clip's dimensions.
    """
    width, height = self._wh_norm(clip, width, height)

    if width != clip.width or height != clip.height:
        raise CustomValueError(
            "When using NoScale, `width` and `height` must match the clip's dimensions.",
            self.__class__,
            (width, height),
        )

    if shift == (0, 0) and not kwargs and not self.kwargs:
        return clip

    return super().scale(clip, width, height, shift, **kwargs)

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:

  • CustomValueError

    If resulting resolution is non-positive.

Returns:

  • VideoNode

    The supersampled clip.

Source code in vskernels/abstract/base.py
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
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)

ScalerSpecializer

ScalerSpecializer(**kwargs: Any)

Bases: BaseScalerSpecializer[DefaultScalerT], Scaler

An abstract base class to provide specialization logic for Scaler-like classes.

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.

  • 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:

Source code in vskernels/util.py
126
127
128
129
130
131
132
133
def __init__(self, **kwargs: Any) -> None:
    super().__init__()

    for k in kwargs.copy():
        if hasattr(self, k):
            setattr(self, k, kwargs.pop(k))

    self.kwargs = kwargs

default_scaler class-attribute

default_scaler: type[BaseScaler]

kwargs instance-attribute

kwargs = kwargs

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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
@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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
@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
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
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
443
444
445
446
447
448
449
450
451
452
453
454
@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", ()))

kernel_radius

kernel_radius() -> int

Return the effective kernel radius for the scaler.

Raises:

  • CustomNotImplementedError

    If no kernel radius is defined.

Returns:

  • int

    Kernel radius.

Source code in vskernels/abstract/base.py
406
407
408
409
410
411
412
413
414
415
416
417
@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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
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)
    check_correct_subsampling(clip, width, height)

    return self.scale_function(clip, **_norm_props_enums(self.get_scale_args(clip, shift, width, height, **kwargs)))

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:

  • CustomValueError

    If resulting resolution is non-positive.

Returns:

  • VideoNode

    The supersampled clip.

Source code in vskernels/abstract/base.py
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
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)

is_bobber_like

is_bobber_like(obj: Any) -> TypeIs[BobberLike]

Returns true if obj is a BobberLike

Source code in vskernels/util.py
597
598
599
def is_bobber_like(obj: Any) -> TypeIs[BobberLike]:
    """Returns true if obj is a BobberLike"""
    return _is_base_scaler_like(obj, Bobber)

is_complex_descaler_like

is_complex_descaler_like(obj: Any) -> TypeIs[ComplexDescalerLike]

Returns true if obj is a ComplexDescalerLike

Source code in vskernels/util.py
607
608
609
def is_complex_descaler_like(obj: Any) -> TypeIs[ComplexDescalerLike]:
    """Returns true if obj is a ComplexDescalerLike"""
    return _is_base_scaler_like(obj, ComplexDescaler)

is_complex_kernel_like

is_complex_kernel_like(obj: Any) -> TypeIs[ComplexKernelLike]

Returns true if obj is a ComplexKernelLike

Source code in vskernels/util.py
612
613
614
def is_complex_kernel_like(obj: Any) -> TypeIs[ComplexKernelLike]:
    """Returns true if obj is a ComplexKernelLike"""
    return _is_base_scaler_like(obj, ComplexKernel)

is_complex_scaler_like

is_complex_scaler_like(obj: Any) -> TypeIs[ComplexScalerLike]

Returns true if obj is a ComplexScalerLike

Source code in vskernels/util.py
602
603
604
def is_complex_scaler_like(obj: Any) -> TypeIs[ComplexScalerLike]:
    """Returns true if obj is a ComplexScalerLike"""
    return _is_base_scaler_like(obj, ComplexScaler)

is_custom_complex_kernel_like

is_custom_complex_kernel_like(obj: Any) -> TypeIs[CustomComplexKernelLike]

Returns true if obj is a CustomComplexKernelLike

Source code in vskernels/util.py
617
618
619
def is_custom_complex_kernel_like(obj: Any) -> TypeIs[CustomComplexKernelLike]:
    """Returns true if obj is a CustomComplexKernelLike"""
    return _is_base_scaler_like(obj, CustomComplexKernel)

is_descaler_like

is_descaler_like(obj: Any) -> TypeIs[DescalerLike]

Returns true if obj is a DescalerLike

Source code in vskernels/util.py
582
583
584
def is_descaler_like(obj: Any) -> TypeIs[DescalerLike]:
    """Returns true if obj is a DescalerLike"""
    return _is_base_scaler_like(obj, Descaler)

is_kernel_like

is_kernel_like(obj: Any) -> TypeIs[KernelLike]

Returns true if obj is a KernelLike

Source code in vskernels/util.py
592
593
594
def is_kernel_like(obj: Any) -> TypeIs[KernelLike]:
    """Returns true if obj is a KernelLike"""
    return _is_base_scaler_like(obj, Kernel)

is_noscale_like

is_noscale_like(obj: Any) -> TypeIs[NoScaleLike[Scaler]]

Returns true if obj is a NoScaleLike

Source code in vskernels/util.py
622
623
624
def is_noscale_like(obj: Any) -> TypeIs[NoScaleLike[Scaler]]:
    """Returns true if obj is a NoScaleLike"""
    return _is_base_scaler_like(obj, NoScale)

is_resampler_like

is_resampler_like(obj: Any) -> TypeIs[ResamplerLike]

Returns true if obj is a ResamplerLike

Source code in vskernels/util.py
587
588
589
def is_resampler_like(obj: Any) -> TypeIs[ResamplerLike]:
    """Returns true if obj is a ResamplerLike"""
    return _is_base_scaler_like(obj, Resampler)

is_scaler_like

is_scaler_like(obj: Any) -> TypeIs[ScalerLike]

Returns true if obj is a ScalerLike

Source code in vskernels/util.py
577
578
579
def is_scaler_like(obj: Any) -> TypeIs[ScalerLike]:
    """Returns true if obj is a ScalerLike"""
    return _is_base_scaler_like(obj, Scaler)

resample_to

resample_to(
    clip: VideoNode,
    out_fmt: int | VideoFormatLike | HoldsVideoFormat,
    matrix: MatrixLike | None = None,
    resampler: ResamplerLike = Catrom,
) -> VideoNode
Source code in vskernels/util.py
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
def resample_to(
    clip: vs.VideoNode,
    out_fmt: int | VideoFormatLike | HoldsVideoFormat,
    matrix: MatrixLike | None = None,
    resampler: ResamplerLike = Catrom,
) -> vs.VideoNode:
    out_fmt = get_video_format(out_fmt)
    assert clip.format

    resampler = Resampler.from_param(resampler)

    if out_fmt == clip.format:
        return clip

    if out_fmt.color_family is clip.format.color_family:
        return depth(clip, out_fmt)

    if out_fmt.subsampling_w == out_fmt.subsampling_h == 0:
        return Point().resample(clip, out_fmt, matrix)

    return resampler().resample(clip, out_fmt, matrix)