Skip to content

various

Classes:

ClampScaler

ClampScaler(
    base_scaler: ScalerLike,
    reference: ScalerLike | VideoNode,
    strength: int = 80,
    overshoot: float | None = None,
    undershoot: float | None = None,
    limit: Mode | bool = True,
    operator: Literal[MAX, MIN] | None = MIN,
    masked: bool = True,
    *,
    kernel: KernelLike = Catrom,
    scaler: ScalerLike | None = None,
    shifter: KernelLike | None = None,
    **kwargs: Any
)

Bases: GenericScaler

Clamp a reference Scaler.

Parameters:

  • base_scaler

    (ScalerLike) –

    Scaler to clamp.

  • reference

    (ScalerLike | VideoNode) –

    Reference Scaler used to clamp base_scaler

  • strength

    (int, default: 80 ) –

    Strength of clamping. Default to 80. Must be between 0 and 100 (exclusive)

  • overshoot

    (float | None, default: None ) –

    Overshoot threshold within the 0.0 - 1.0 range.

  • undershoot

    (float | None, default: None ) –

    Undershoot threshold within the 0.0 - 1.0 range.

  • limit

    (Mode | bool, default: True ) –

    Whether to use under/overshoot limit (True) or a reference repaired clip for limiting.

  • operator

    (Literal[MAX, MIN] | None, default: MIN ) –

    Whether to take the brightest or darkest pixels in the merge. Defaults to ExprOp.MIN.

  • masked

    (bool, default: True ) –

    Whether to mask with a ringing mask or not. Defaults to True

  • kernel

    (KernelLike, default: Catrom ) –

    Base kernel to be used for certain scaling/shifting/resampling operations. Defaults to Catrom.

  • scaler

    (ScalerLike | None, default: None ) –

    Scaler used for scaling operations. Defaults to kernel.

  • shifter

    (KernelLike | None, default: None ) –

    Kernel used for shifting operations. Defaults to kernel.

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 vsscale/various.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
def __init__(
    self,
    base_scaler: ScalerLike,
    reference: ScalerLike | vs.VideoNode,
    strength: int = 80,
    overshoot: float | None = None,
    undershoot: float | None = None,
    limit: Repair.Mode | bool = True,
    operator: Literal[ExprOp.MAX, ExprOp.MIN] | None = ExprOp.MIN,
    masked: bool = True,
    *,
    kernel: KernelLike = Catrom,
    scaler: ScalerLike | None = None,
    shifter: KernelLike | None = None,
    **kwargs: Any,
) -> None:
    """
    Args:
        base_scaler: Scaler to clamp.
        reference: Reference Scaler used to clamp base_scaler
        strength: Strength of clamping. Default to 80. Must be between 0 and 100 (exclusive)
        overshoot: Overshoot threshold within the 0.0 - 1.0 range.
        undershoot: Undershoot threshold within the 0.0 - 1.0 range.
        limit: Whether to use under/overshoot limit (True) or a reference repaired clip for limiting.
        operator: Whether to take the brightest or darkest pixels in the merge. Defaults to ExprOp.MIN.
        masked: Whether to mask with a ringing mask or not. Defaults to True
        kernel: Base kernel to be used for certain scaling/shifting/resampling operations. Defaults to Catrom.
        scaler: Scaler used for scaling operations. Defaults to kernel.
        shifter: Kernel used for shifting operations. Defaults to kernel.
    """
    self.base_scaler = Scaler.ensure_obj(base_scaler, self.__class__)

    self.reference: Scaler | vs.VideoNode

    if not isinstance(reference, vs.VideoNode):
        self.reference = Scaler.ensure_obj(reference, self.__class__)
    else:
        self.reference = reference

    if not 0 < strength < 100:
        raise CustomOverflowError("`strength` must be between 0 and 100 (exclusive)!", self.__class__)

    self.strength = strength

    if overshoot is None:
        self.overshoot = self.strength / 100
    else:
        self.overshoot = overshoot

    if undershoot is None:
        self.undershoot = self.overshoot
    else:
        self.undershoot = undershoot

    self.limit = limit
    self.operator = operator
    self.masked = masked

    super().__init__(None, kernel=kernel, scaler=scaler, shifter=shifter, **kwargs)

base_scaler instance-attribute

base_scaler = ensure_obj(base_scaler, __class__)

func instance-attribute

func = _func_no_op if func is None else func

kernel instance-attribute

kernel = ensure_obj(kernel, __class__)

kwargs instance-attribute

kwargs: dict[str, Any] = kwargs

Arguments passed to the implemented funcs or internal scale function.

limit instance-attribute

limit = limit

masked instance-attribute

masked = masked

operator instance-attribute

operator = operator

overshoot instance-attribute

overshoot = strength / 100

pretty_string property

pretty_string: str

Cached property returning a user-friendly string representation.

Returns:

  • str

    Pretty-printed string with arguments.

reference instance-attribute

reference: Scaler | VideoNode

scale_function instance-attribute

scale_function: Callable[..., VideoNode]

Scale function called internally when performing scaling operations.

scaler instance-attribute

scaler = ensure_obj(scaler or kernel, __class__)

shifter instance-attribute

shifter = ensure_obj(shifter or kernel, __class__)

strength instance-attribute

strength = strength

undershoot instance-attribute

undershoot = overshoot

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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
@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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
@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
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
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
445
446
447
448
449
450
451
452
453
454
455
456
@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 vsscale/various.py
146
147
148
149
150
@Scaler.cachedproperty
def kernel_radius(self) -> int:
    if not isinstance(self.reference, vs.VideoNode):
        return max(self.reference.kernel_radius, self.base_scaler.kernel_radius)
    return self.base_scaler.kernel_radius

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[float, float] = (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 vsscale/various.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
def scale(
    self,
    clip: vs.VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[float, float] = (0, 0),
    **kwargs: Any,
) -> vs.VideoNode:
    width, height = self._wh_norm(clip, width, height)

    base = self.base_scaler.scale(clip, width, height, shift, **kwargs)

    if isinstance(self.reference, vs.VideoNode):
        smooth = self.reference

        if shift != (0, 0):
            smooth = self.kernel.shift(smooth, shift)
    else:
        smooth = self.reference.scale(clip, width, height, shift)

    check_ref_clip(base, smooth)

    merge_weight = self.strength / 100

    if self.limit is True:
        expression = "x {merge_weight} * y {ref_weight} * + a {undershoot} - z {overshoot} + clip"

        merged = norm_expr(
            [base, smooth, smooth.std.Maximum(), smooth.std.Minimum()],
            expression,
            merge_weight=merge_weight,
            ref_weight=1.0 - merge_weight,
            undershoot=scale_delta(self.undershoot, 32, clip),
            overshoot=scale_delta(self.overshoot, 32, clip),
            func=self.__class__,
        )
    else:
        merged = smooth.std.Merge(base, merge_weight)

        if isinstance(self.limit, Repair.Mode):
            merged = self.limit(merged, smooth)

    if self.operator is not None:
        merge2 = combine([smooth, base], self.operator)

        merged = merged.std.MaskedMerge(merge2, ringing_mask(smooth)) if self.masked else merge2
    elif self.masked:
        merged = merged.std.MaskedMerge(smooth, ringing_mask(smooth))

    return merged

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
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
535
536
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)

ComplexSuperSamplerProcess

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

Bases: MixedScalerProcess[_ComplexScalerWithLanczosDefaultT, Point], ComplexScaler

A utility ComplexScaler class that applies a given function to a supersampled clip, then downsamples it back using Point.

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

Example:

from vskernels import Lanczos

processed = ComplexSuperSamplerProcess[Lanczos](function=lambda clip: cool_function(clip, ...)).supersample(
    src, rfactor=2
)

Note

Depending on the source chroma location and subsampling, chroma planes may not align properly during processing. Avoid using this class if accurate chroma placement relative to luma is required.

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 the given resolution, with aspect ratio and linear light support.

  • supersample

    Supersample a clip by a given scaling factor.

Attributes:

  • default_scaler
  • function
  • kwargs

    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.

  • specializer (DefaultScalerT) –

    Returns the effective specializer.

Source code in vskernels/util.py
338
339
340
341
342
343
344
345
346
347
348
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 instance-attribute

default_scaler = Lanczos

function instance-attribute

function = function

kwargs instance-attribute

kwargs = 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.

specializer property

specializer: DefaultScalerT

Returns the effective specializer.

Returns:

  • DefaultScalerT

    The effective specializer.

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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
@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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
@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
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
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
445
446
447
448
449
450
451
452
453
454
455
456
@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
408
409
410
411
412
413
414
415
416
417
418
419
@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 | list[TopShift], LeftShift | list[LeftShift]] = (
        0,
        0,
    ),
    **kwargs: Any
) -> VideoNode

Scale a clip to the given resolution, with aspect ratio and linear light support.

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 | list[TopShift], LeftShift | list[LeftShift]], default: (0, 0) ) –

    Subpixel shift (top, left) applied during scaling. If a tuple is provided, it is used uniformly. If a list is given, the shift is applied per plane.

  • linear

    (bool | None, default: None ) –

    Whether to linearize the input before descaling. If None, inferred from sigmoid.

  • sigmoid

    (bool | tuple[Slope, Center], default: 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).

  • border_handling

    (BorderHandling, default: MIRROR ) –

    Method for handling image borders during sampling.

  • sample_grid_model

    (SampleGridModel, default: MATCH_EDGES ) –

    Model used to align sampling grid.

  • sar

    (Sar | float | bool | None, default: None ) –

    Sample aspect ratio to assume or convert to.

  • dar

    (Dar | float | bool | None, default: None ) –

    Desired display aspect ratio.

  • dar_in

    (Dar | bool | float | None, default: None ) –

    Input display aspect ratio, if different from clip's.

  • keep_ar

    (bool | None, default: None ) –

    Whether to adjust dimensions to preserve aspect ratio.

  • blur

    (float | None, default: None ) –

    Amount of blur to apply during scaling.

Returns:

  • VideoNode

    Scaled clip, optionally aspect-corrected and linearized.

Source code in vsscale/various.py
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
def scale(
    self,
    clip: vs.VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift | list[TopShift], LeftShift | list[LeftShift]] = (0, 0),
    **kwargs: Any,
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.scale)

    width, height = self._wh_norm(clip, width, height)
    rfactor_w, rfactor_h = (width / clip.width), (height / clip.height)

    if any(not rf.is_integer() for rf in (rfactor_w, rfactor_h)):
        raise CustomValueError(
            "The supersampling factor must yield an integer result.", self.__class__, (rfactor_w, rfactor_h)
        )

    shift_top, shift_left = shift

    point = self._others[0]

    if isinstance(shift_top, (int, float)) and isinstance(shift_left, (int, float)):
        upscaled = super().scale(
            ChromaLocation.TOP_LEFT.apply(clip),
            width,
            height,
            (shift_top + 0.5 - 0.5 / rfactor_h, shift_left + 0.5 - 0.5 / rfactor_w),
            **kwargs,
        )

        processed = self.function(upscaled)

        downscaled = point.scale(processed, clip.width, clip.height, (0.5 - 0.5 * rfactor_h, 0.5 - 0.5 * rfactor_w))
    else:
        shift_top = normalize_seq(shift_top, clip.format.num_planes)
        shift_left = normalize_seq(shift_left, clip.format.num_planes)

        upscaled = super().scale(
            ChromaLocation.CENTER.apply(clip),
            width,
            height,
            ([x + 0.5 - 0.5 / rfactor_h for x in shift_top], [x + 0.5 - 0.5 / rfactor_w for x in shift_left]),
            **kwargs,
        )

        processed = self.function(upscaled)

        downscaled = point.scale(
            processed, clip.width, clip.height, ([0.5 - 0.5 * rfactor_h] * 3, [0.5 - 0.5 * rfactor_w] * 3)
        )

    return ChromaLocation.from_video(clip).apply(downscaled)

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
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
535
536
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)