Skip to content

placebo

Classes:

EwaBicubic

EwaBicubic(
    b: float = 0.0, c: float = 0.5, radius: int | None = None, **kwargs: Any
)

Bases: Placebo

Ewa Bicubic resizer.

Initialize the scaler with specific 'b' and 'c' parameters and optional 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:

  • b

    (float, default: 0.0 ) –

    The 'b' parameter for bicubic interpolation.

  • c

    (float, default: 0.5 ) –

    The 'c' parameter for bicubic interpolation.

  • radius

    (int | None, default: None ) –

    Overrides the filter kernel radius.

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

Source code in vskernels/kernels/placebo.py
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
def __init__(self, b: float = 0.0, c: float = 0.5, radius: int | None = None, **kwargs: Any) -> None:
    """
    Initialize the scaler with specific 'b' and 'c' parameters and optional 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:
        b: The 'b' parameter for bicubic interpolation.
        c: The 'c' parameter for bicubic interpolation.
        radius: Overrides the filter kernel radius.
        **kwargs: Keyword arguments that configure the internal scaling behavior.
    """
    if radius is None:
        radius = 1 if (b, c) == (0, 0) else 2

    super().__init__(radius, b, c, **kwargs)

antiring instance-attribute

antiring = antiring

b instance-attribute

b = b

blur instance-attribute

blur = blur

c instance-attribute

c = c

clamp instance-attribute

clamp = clamp

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.

radius instance-attribute

radius = radius

scale_function class-attribute instance-attribute

scale_function = Resample

Scale function called internally when performing scaling operations.

taper instance-attribute

taper = taper

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/kernels/placebo.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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]:
    kwargs.pop("format", None)

    return (
        {
            "sx": kwargs.pop("src_left", shift[1]),
            "sy": kwargs.pop("src_top", shift[0]),
            "width": width,
            "height": height,
            "filter": self._kernel,
            "radius": self.radius,
            "param1": self.b,
            "param2": self.c,
            "clamp": self.clamp,
            "taper": self.taper,
            "blur": self.blur,
            "antiring": self.antiring,
        }
        | self.kwargs
        | kwargs
        | {"linearize": False, "sigmoidize": False}
    )

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
454
455
456
457
458
459
460
461
462
463
464
465
@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/kernels/placebo.py
192
193
194
195
196
197
198
199
200
201
202
203
@ComplexScaler.cachedproperty
def kernel_radius(self) -> int:
    if self.radius:
        return ceil(self.radius)

    if self.b or self.c:
        b, c = fallback(self.b, 0), fallback(self.c, 0.5)

        if (b, c) == (0, 0):
            return 1

    return 2

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift | list[TopShift], LeftShift | list[LeftShift]] = (
        0,
        0,
    ),
    *,
    linear: bool | None = None,
    sigmoid: bool | tuple[Slope, Center] = False,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    blur: float | None = None,
    **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.

If a format is provided, only a change in chroma subsampling is allowed. Other format characteristics (bit depth, sample type, color family, etc.) must match the source clip.

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 vskernels/kernels/placebo.py
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def scale(
    self,
    clip: vs.VideoNode,
    width: int | None = None,
    height: int | None = None,
    # ComplexScaler adds shift per planes
    shift: tuple[TopShift | list[TopShift], LeftShift | list[LeftShift]] = (0, 0),
    *,
    # `linear` and `sigmoid` from LinearScaler
    linear: bool | None = None,
    sigmoid: bool | tuple[Slope, Center] = False,
    # `border_handling`, `sample_grid_model`, `sar`, `dar`, `dar_in` and `keep_ar` from KeepArScaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    # ComplexScaler adds blur
    blur: float | None = None,
    **kwargs: Any,
) -> vs.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.

    If a `format` is provided, only a change in chroma subsampling is allowed.
    Other format characteristics (bit depth, sample type, color family, etc.) must match the source clip.

    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. If a tuple is provided, it is used uniformly. If a
            list is given, the shift is applied per plane.
        linear: Whether to linearize the input before descaling. If None, inferred from sigmoid.
        sigmoid: 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: Method for handling image borders during sampling.
        sample_grid_model: Model used to align sampling grid.
        sar: Sample aspect ratio to assume or convert to.
        dar: Desired display aspect ratio.
        dar_in: Input display aspect ratio, if different from clip's.
        keep_ar: Whether to adjust dimensions to preserve aspect ratio.
        blur: Amount of blur to apply during scaling.

    Returns:
        Scaled clip, optionally aspect-corrected and linearized.
    """
    if fmt := fallback(kwargs.get("format"), self.kwargs.get("format"), False):
        fmt = get_video_format(fmt)

        if (
            clip.format.color_family != fmt.color_family
            or clip.format.num_planes != fmt.num_planes
            or clip.format.sample_type != fmt.sample_type
            or clip.format.bits_per_sample != fmt.bits_per_sample
        ):
            raise CustomValueError("Only YUV subsampling scaling is supported.", self.__class__, fmt.name)

        shift = (to_arr(shift[0]), to_arr(shift[1]))

    return super().scale(
        clip,
        width,
        height,
        shift,
        linear=linear,
        sigmoid=sigmoid,
        border_handling=border_handling,
        sample_grid_model=sample_grid_model,
        sar=sar,
        dar=dar,
        dar_in=dar_in,
        keep_ar=keep_ar,
        blur=blur,
        **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
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
537
538
539
540
541
542
543
544
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)

EwaGinseng

EwaGinseng(radius: float = 3.238315484166236, **kwargs: Any)

Bases: Placebo

Ewa Ginseng resizer.

Initialize the kernel with a specific radius and 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:

  • radius

    (float, default: 3.238315484166236 ) –

    Overrides the filter kernel radius. Has no effect if the filter kernel is not resizeable.

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

Source code in vskernels/kernels/placebo.py
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
def __init__(self, radius: float = 3.2383154841662362076499, **kwargs: Any) -> None:
    """
    Initialize the kernel with a specific radius and 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:
        radius: Overrides the filter kernel radius. Has no effect if the filter kernel is not resizeable.
        **kwargs: Keyword arguments that configure the internal scaling behavior.
    """
    super().__init__(radius, None, None, **kwargs)

antiring instance-attribute

antiring = antiring

b instance-attribute

b = b

blur instance-attribute

blur = blur

c instance-attribute

c = c

clamp instance-attribute

clamp = clamp

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.

radius instance-attribute

radius = radius

scale_function class-attribute instance-attribute

scale_function = Resample

Scale function called internally when performing scaling operations.

taper instance-attribute

taper = taper

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/kernels/placebo.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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]:
    kwargs.pop("format", None)

    return (
        {
            "sx": kwargs.pop("src_left", shift[1]),
            "sy": kwargs.pop("src_top", shift[0]),
            "width": width,
            "height": height,
            "filter": self._kernel,
            "radius": self.radius,
            "param1": self.b,
            "param2": self.c,
            "clamp": self.clamp,
            "taper": self.taper,
            "blur": self.blur,
            "antiring": self.antiring,
        }
        | self.kwargs
        | kwargs
        | {"linearize": False, "sigmoidize": False}
    )

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
454
455
456
457
458
459
460
461
462
463
464
465
@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/kernels/placebo.py
192
193
194
195
196
197
198
199
200
201
202
203
@ComplexScaler.cachedproperty
def kernel_radius(self) -> int:
    if self.radius:
        return ceil(self.radius)

    if self.b or self.c:
        b, c = fallback(self.b, 0), fallback(self.c, 0.5)

        if (b, c) == (0, 0):
            return 1

    return 2

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift | list[TopShift], LeftShift | list[LeftShift]] = (
        0,
        0,
    ),
    *,
    linear: bool | None = None,
    sigmoid: bool | tuple[Slope, Center] = False,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    blur: float | None = None,
    **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.

If a format is provided, only a change in chroma subsampling is allowed. Other format characteristics (bit depth, sample type, color family, etc.) must match the source clip.

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 vskernels/kernels/placebo.py
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def scale(
    self,
    clip: vs.VideoNode,
    width: int | None = None,
    height: int | None = None,
    # ComplexScaler adds shift per planes
    shift: tuple[TopShift | list[TopShift], LeftShift | list[LeftShift]] = (0, 0),
    *,
    # `linear` and `sigmoid` from LinearScaler
    linear: bool | None = None,
    sigmoid: bool | tuple[Slope, Center] = False,
    # `border_handling`, `sample_grid_model`, `sar`, `dar`, `dar_in` and `keep_ar` from KeepArScaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    # ComplexScaler adds blur
    blur: float | None = None,
    **kwargs: Any,
) -> vs.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.

    If a `format` is provided, only a change in chroma subsampling is allowed.
    Other format characteristics (bit depth, sample type, color family, etc.) must match the source clip.

    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. If a tuple is provided, it is used uniformly. If a
            list is given, the shift is applied per plane.
        linear: Whether to linearize the input before descaling. If None, inferred from sigmoid.
        sigmoid: 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: Method for handling image borders during sampling.
        sample_grid_model: Model used to align sampling grid.
        sar: Sample aspect ratio to assume or convert to.
        dar: Desired display aspect ratio.
        dar_in: Input display aspect ratio, if different from clip's.
        keep_ar: Whether to adjust dimensions to preserve aspect ratio.
        blur: Amount of blur to apply during scaling.

    Returns:
        Scaled clip, optionally aspect-corrected and linearized.
    """
    if fmt := fallback(kwargs.get("format"), self.kwargs.get("format"), False):
        fmt = get_video_format(fmt)

        if (
            clip.format.color_family != fmt.color_family
            or clip.format.num_planes != fmt.num_planes
            or clip.format.sample_type != fmt.sample_type
            or clip.format.bits_per_sample != fmt.bits_per_sample
        ):
            raise CustomValueError("Only YUV subsampling scaling is supported.", self.__class__, fmt.name)

        shift = (to_arr(shift[0]), to_arr(shift[1]))

    return super().scale(
        clip,
        width,
        height,
        shift,
        linear=linear,
        sigmoid=sigmoid,
        border_handling=border_handling,
        sample_grid_model=sample_grid_model,
        sar=sar,
        dar=dar,
        dar_in=dar_in,
        keep_ar=keep_ar,
        blur=blur,
        **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
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
537
538
539
540
541
542
543
544
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)

EwaHann

EwaHann(radius: float = 3.238315484166236, **kwargs: Any)

Bases: Placebo

Ewa Hann resizer.

Initialize the kernel with a specific radius and 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:

  • radius

    (float, default: 3.238315484166236 ) –

    Overrides the filter kernel radius. Has no effect if the filter kernel is not resizeable.

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

Source code in vskernels/kernels/placebo.py
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
def __init__(self, radius: float = 3.2383154841662362076499, **kwargs: Any) -> None:
    """
    Initialize the kernel with a specific radius and 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:
        radius: Overrides the filter kernel radius. Has no effect if the filter kernel is not resizeable.
        **kwargs: Keyword arguments that configure the internal scaling behavior.
    """
    super().__init__(radius, None, None, **kwargs)

antiring instance-attribute

antiring = antiring

b instance-attribute

b = b

blur instance-attribute

blur = blur

c instance-attribute

c = c

clamp instance-attribute

clamp = clamp

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.

radius instance-attribute

radius = radius

scale_function class-attribute instance-attribute

scale_function = Resample

Scale function called internally when performing scaling operations.

taper instance-attribute

taper = taper

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/kernels/placebo.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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]:
    kwargs.pop("format", None)

    return (
        {
            "sx": kwargs.pop("src_left", shift[1]),
            "sy": kwargs.pop("src_top", shift[0]),
            "width": width,
            "height": height,
            "filter": self._kernel,
            "radius": self.radius,
            "param1": self.b,
            "param2": self.c,
            "clamp": self.clamp,
            "taper": self.taper,
            "blur": self.blur,
            "antiring": self.antiring,
        }
        | self.kwargs
        | kwargs
        | {"linearize": False, "sigmoidize": False}
    )

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
454
455
456
457
458
459
460
461
462
463
464
465
@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/kernels/placebo.py
192
193
194
195
196
197
198
199
200
201
202
203
@ComplexScaler.cachedproperty
def kernel_radius(self) -> int:
    if self.radius:
        return ceil(self.radius)

    if self.b or self.c:
        b, c = fallback(self.b, 0), fallback(self.c, 0.5)

        if (b, c) == (0, 0):
            return 1

    return 2

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift | list[TopShift], LeftShift | list[LeftShift]] = (
        0,
        0,
    ),
    *,
    linear: bool | None = None,
    sigmoid: bool | tuple[Slope, Center] = False,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    blur: float | None = None,
    **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.

If a format is provided, only a change in chroma subsampling is allowed. Other format characteristics (bit depth, sample type, color family, etc.) must match the source clip.

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 vskernels/kernels/placebo.py
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def scale(
    self,
    clip: vs.VideoNode,
    width: int | None = None,
    height: int | None = None,
    # ComplexScaler adds shift per planes
    shift: tuple[TopShift | list[TopShift], LeftShift | list[LeftShift]] = (0, 0),
    *,
    # `linear` and `sigmoid` from LinearScaler
    linear: bool | None = None,
    sigmoid: bool | tuple[Slope, Center] = False,
    # `border_handling`, `sample_grid_model`, `sar`, `dar`, `dar_in` and `keep_ar` from KeepArScaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    # ComplexScaler adds blur
    blur: float | None = None,
    **kwargs: Any,
) -> vs.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.

    If a `format` is provided, only a change in chroma subsampling is allowed.
    Other format characteristics (bit depth, sample type, color family, etc.) must match the source clip.

    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. If a tuple is provided, it is used uniformly. If a
            list is given, the shift is applied per plane.
        linear: Whether to linearize the input before descaling. If None, inferred from sigmoid.
        sigmoid: 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: Method for handling image borders during sampling.
        sample_grid_model: Model used to align sampling grid.
        sar: Sample aspect ratio to assume or convert to.
        dar: Desired display aspect ratio.
        dar_in: Input display aspect ratio, if different from clip's.
        keep_ar: Whether to adjust dimensions to preserve aspect ratio.
        blur: Amount of blur to apply during scaling.

    Returns:
        Scaled clip, optionally aspect-corrected and linearized.
    """
    if fmt := fallback(kwargs.get("format"), self.kwargs.get("format"), False):
        fmt = get_video_format(fmt)

        if (
            clip.format.color_family != fmt.color_family
            or clip.format.num_planes != fmt.num_planes
            or clip.format.sample_type != fmt.sample_type
            or clip.format.bits_per_sample != fmt.bits_per_sample
        ):
            raise CustomValueError("Only YUV subsampling scaling is supported.", self.__class__, fmt.name)

        shift = (to_arr(shift[0]), to_arr(shift[1]))

    return super().scale(
        clip,
        width,
        height,
        shift,
        linear=linear,
        sigmoid=sigmoid,
        border_handling=border_handling,
        sample_grid_model=sample_grid_model,
        sar=sar,
        dar=dar,
        dar_in=dar_in,
        keep_ar=keep_ar,
        blur=blur,
        **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
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
537
538
539
540
541
542
543
544
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)

EwaJinc

EwaJinc(radius: float = 3.238315484166236, **kwargs: Any)

Bases: Placebo

Ewa Jinc resizer.

Initialize the kernel with a specific radius and 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:

  • radius

    (float, default: 3.238315484166236 ) –

    Overrides the filter kernel radius. Has no effect if the filter kernel is not resizeable.

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

Source code in vskernels/kernels/placebo.py
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
def __init__(self, radius: float = 3.2383154841662362076499, **kwargs: Any) -> None:
    """
    Initialize the kernel with a specific radius and 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:
        radius: Overrides the filter kernel radius. Has no effect if the filter kernel is not resizeable.
        **kwargs: Keyword arguments that configure the internal scaling behavior.
    """
    super().__init__(radius, None, None, **kwargs)

antiring instance-attribute

antiring = antiring

b instance-attribute

b = b

blur instance-attribute

blur = blur

c instance-attribute

c = c

clamp instance-attribute

clamp = clamp

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.

radius instance-attribute

radius = radius

scale_function class-attribute instance-attribute

scale_function = Resample

Scale function called internally when performing scaling operations.

taper instance-attribute

taper = taper

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/kernels/placebo.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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]:
    kwargs.pop("format", None)

    return (
        {
            "sx": kwargs.pop("src_left", shift[1]),
            "sy": kwargs.pop("src_top", shift[0]),
            "width": width,
            "height": height,
            "filter": self._kernel,
            "radius": self.radius,
            "param1": self.b,
            "param2": self.c,
            "clamp": self.clamp,
            "taper": self.taper,
            "blur": self.blur,
            "antiring": self.antiring,
        }
        | self.kwargs
        | kwargs
        | {"linearize": False, "sigmoidize": False}
    )

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
454
455
456
457
458
459
460
461
462
463
464
465
@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/kernels/placebo.py
192
193
194
195
196
197
198
199
200
201
202
203
@ComplexScaler.cachedproperty
def kernel_radius(self) -> int:
    if self.radius:
        return ceil(self.radius)

    if self.b or self.c:
        b, c = fallback(self.b, 0), fallback(self.c, 0.5)

        if (b, c) == (0, 0):
            return 1

    return 2

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift | list[TopShift], LeftShift | list[LeftShift]] = (
        0,
        0,
    ),
    *,
    linear: bool | None = None,
    sigmoid: bool | tuple[Slope, Center] = False,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    blur: float | None = None,
    **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.

If a format is provided, only a change in chroma subsampling is allowed. Other format characteristics (bit depth, sample type, color family, etc.) must match the source clip.

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 vskernels/kernels/placebo.py
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def scale(
    self,
    clip: vs.VideoNode,
    width: int | None = None,
    height: int | None = None,
    # ComplexScaler adds shift per planes
    shift: tuple[TopShift | list[TopShift], LeftShift | list[LeftShift]] = (0, 0),
    *,
    # `linear` and `sigmoid` from LinearScaler
    linear: bool | None = None,
    sigmoid: bool | tuple[Slope, Center] = False,
    # `border_handling`, `sample_grid_model`, `sar`, `dar`, `dar_in` and `keep_ar` from KeepArScaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    # ComplexScaler adds blur
    blur: float | None = None,
    **kwargs: Any,
) -> vs.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.

    If a `format` is provided, only a change in chroma subsampling is allowed.
    Other format characteristics (bit depth, sample type, color family, etc.) must match the source clip.

    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. If a tuple is provided, it is used uniformly. If a
            list is given, the shift is applied per plane.
        linear: Whether to linearize the input before descaling. If None, inferred from sigmoid.
        sigmoid: 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: Method for handling image borders during sampling.
        sample_grid_model: Model used to align sampling grid.
        sar: Sample aspect ratio to assume or convert to.
        dar: Desired display aspect ratio.
        dar_in: Input display aspect ratio, if different from clip's.
        keep_ar: Whether to adjust dimensions to preserve aspect ratio.
        blur: Amount of blur to apply during scaling.

    Returns:
        Scaled clip, optionally aspect-corrected and linearized.
    """
    if fmt := fallback(kwargs.get("format"), self.kwargs.get("format"), False):
        fmt = get_video_format(fmt)

        if (
            clip.format.color_family != fmt.color_family
            or clip.format.num_planes != fmt.num_planes
            or clip.format.sample_type != fmt.sample_type
            or clip.format.bits_per_sample != fmt.bits_per_sample
        ):
            raise CustomValueError("Only YUV subsampling scaling is supported.", self.__class__, fmt.name)

        shift = (to_arr(shift[0]), to_arr(shift[1]))

    return super().scale(
        clip,
        width,
        height,
        shift,
        linear=linear,
        sigmoid=sigmoid,
        border_handling=border_handling,
        sample_grid_model=sample_grid_model,
        sar=sar,
        dar=dar,
        dar_in=dar_in,
        keep_ar=keep_ar,
        blur=blur,
        **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
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
537
538
539
540
541
542
543
544
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)

EwaLanczos

EwaLanczos(radius: float = 3.238315484166236, **kwargs: Any)

Bases: Placebo

Ewa Lanczos resizer.

Initialize the kernel with a specific radius and 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:

  • radius

    (float, default: 3.238315484166236 ) –

    Overrides the filter kernel radius. Has no effect if the filter kernel is not resizeable.

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

Source code in vskernels/kernels/placebo.py
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
def __init__(self, radius: float = 3.2383154841662362076499, **kwargs: Any) -> None:
    """
    Initialize the kernel with a specific radius and 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:
        radius: Overrides the filter kernel radius. Has no effect if the filter kernel is not resizeable.
        **kwargs: Keyword arguments that configure the internal scaling behavior.
    """
    super().__init__(radius, None, None, **kwargs)

antiring instance-attribute

antiring = antiring

b instance-attribute

b = b

blur instance-attribute

blur = blur

c instance-attribute

c = c

clamp instance-attribute

clamp = clamp

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.

radius instance-attribute

radius = radius

scale_function class-attribute instance-attribute

scale_function = Resample

Scale function called internally when performing scaling operations.

taper instance-attribute

taper = taper

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/kernels/placebo.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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]:
    kwargs.pop("format", None)

    return (
        {
            "sx": kwargs.pop("src_left", shift[1]),
            "sy": kwargs.pop("src_top", shift[0]),
            "width": width,
            "height": height,
            "filter": self._kernel,
            "radius": self.radius,
            "param1": self.b,
            "param2": self.c,
            "clamp": self.clamp,
            "taper": self.taper,
            "blur": self.blur,
            "antiring": self.antiring,
        }
        | self.kwargs
        | kwargs
        | {"linearize": False, "sigmoidize": False}
    )

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
454
455
456
457
458
459
460
461
462
463
464
465
@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/kernels/placebo.py
192
193
194
195
196
197
198
199
200
201
202
203
@ComplexScaler.cachedproperty
def kernel_radius(self) -> int:
    if self.radius:
        return ceil(self.radius)

    if self.b or self.c:
        b, c = fallback(self.b, 0), fallback(self.c, 0.5)

        if (b, c) == (0, 0):
            return 1

    return 2

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift | list[TopShift], LeftShift | list[LeftShift]] = (
        0,
        0,
    ),
    *,
    linear: bool | None = None,
    sigmoid: bool | tuple[Slope, Center] = False,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    blur: float | None = None,
    **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.

If a format is provided, only a change in chroma subsampling is allowed. Other format characteristics (bit depth, sample type, color family, etc.) must match the source clip.

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 vskernels/kernels/placebo.py
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def scale(
    self,
    clip: vs.VideoNode,
    width: int | None = None,
    height: int | None = None,
    # ComplexScaler adds shift per planes
    shift: tuple[TopShift | list[TopShift], LeftShift | list[LeftShift]] = (0, 0),
    *,
    # `linear` and `sigmoid` from LinearScaler
    linear: bool | None = None,
    sigmoid: bool | tuple[Slope, Center] = False,
    # `border_handling`, `sample_grid_model`, `sar`, `dar`, `dar_in` and `keep_ar` from KeepArScaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    # ComplexScaler adds blur
    blur: float | None = None,
    **kwargs: Any,
) -> vs.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.

    If a `format` is provided, only a change in chroma subsampling is allowed.
    Other format characteristics (bit depth, sample type, color family, etc.) must match the source clip.

    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. If a tuple is provided, it is used uniformly. If a
            list is given, the shift is applied per plane.
        linear: Whether to linearize the input before descaling. If None, inferred from sigmoid.
        sigmoid: 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: Method for handling image borders during sampling.
        sample_grid_model: Model used to align sampling grid.
        sar: Sample aspect ratio to assume or convert to.
        dar: Desired display aspect ratio.
        dar_in: Input display aspect ratio, if different from clip's.
        keep_ar: Whether to adjust dimensions to preserve aspect ratio.
        blur: Amount of blur to apply during scaling.

    Returns:
        Scaled clip, optionally aspect-corrected and linearized.
    """
    if fmt := fallback(kwargs.get("format"), self.kwargs.get("format"), False):
        fmt = get_video_format(fmt)

        if (
            clip.format.color_family != fmt.color_family
            or clip.format.num_planes != fmt.num_planes
            or clip.format.sample_type != fmt.sample_type
            or clip.format.bits_per_sample != fmt.bits_per_sample
        ):
            raise CustomValueError("Only YUV subsampling scaling is supported.", self.__class__, fmt.name)

        shift = (to_arr(shift[0]), to_arr(shift[1]))

    return super().scale(
        clip,
        width,
        height,
        shift,
        linear=linear,
        sigmoid=sigmoid,
        border_handling=border_handling,
        sample_grid_model=sample_grid_model,
        sar=sar,
        dar=dar,
        dar_in=dar_in,
        keep_ar=keep_ar,
        blur=blur,
        **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
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
537
538
539
540
541
542
543
544
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)

EwaLanczos4Sharpest

EwaLanczos4Sharpest(
    radius: float = 4.24106286379607,
    blur: float = 0.8845120932605005,
    antiring: float = 0.8,
    **kwargs: Any
)

Bases: Placebo

Ewa Lanczos resizer.

Initialize the kernel with a specific radius and 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:

  • radius

    (float, default: 4.24106286379607 ) –

    Overrides the filter kernel radius. Has no effect if the filter kernel is not resizeable.

  • blur

    (float, default: 0.8845120932605005 ) –

    Additional blur coefficient. This effectively stretches the kernel, without changing the effective radius of the filter radius.

  • antiring

    (float, default: 0.8 ) –

    Antiringing strength.

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

Source code in vskernels/kernels/placebo.py
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
def __init__(
    self,
    radius: float = 4.2410628637960698819573,
    blur: float = 0.88451209326050047745788,
    antiring: float = 0.8,
    **kwargs: Any,
) -> None:
    """
    Initialize the kernel with a specific radius and 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:
        radius: Overrides the filter kernel radius. Has no effect if the filter kernel is not resizeable.
        blur: Additional blur coefficient. This effectively stretches the kernel,
            without changing the effective radius of the filter radius.
        antiring: Antiringing strength.
        **kwargs: Keyword arguments that configure the internal scaling behavior.
    """
    super().__init__(radius, None, None, blur=blur, antiring=antiring, **kwargs)

antiring instance-attribute

antiring = antiring

b instance-attribute

b = b

blur instance-attribute

blur = blur

c instance-attribute

c = c

clamp instance-attribute

clamp = clamp

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.

radius instance-attribute

radius = radius

scale_function class-attribute instance-attribute

scale_function = Resample

Scale function called internally when performing scaling operations.

taper instance-attribute

taper = taper

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/kernels/placebo.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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]:
    kwargs.pop("format", None)

    return (
        {
            "sx": kwargs.pop("src_left", shift[1]),
            "sy": kwargs.pop("src_top", shift[0]),
            "width": width,
            "height": height,
            "filter": self._kernel,
            "radius": self.radius,
            "param1": self.b,
            "param2": self.c,
            "clamp": self.clamp,
            "taper": self.taper,
            "blur": self.blur,
            "antiring": self.antiring,
        }
        | self.kwargs
        | kwargs
        | {"linearize": False, "sigmoidize": False}
    )

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
454
455
456
457
458
459
460
461
462
463
464
465
@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/kernels/placebo.py
192
193
194
195
196
197
198
199
200
201
202
203
@ComplexScaler.cachedproperty
def kernel_radius(self) -> int:
    if self.radius:
        return ceil(self.radius)

    if self.b or self.c:
        b, c = fallback(self.b, 0), fallback(self.c, 0.5)

        if (b, c) == (0, 0):
            return 1

    return 2

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift | list[TopShift], LeftShift | list[LeftShift]] = (
        0,
        0,
    ),
    *,
    linear: bool | None = None,
    sigmoid: bool | tuple[Slope, Center] = False,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    blur: float | None = None,
    **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.

If a format is provided, only a change in chroma subsampling is allowed. Other format characteristics (bit depth, sample type, color family, etc.) must match the source clip.

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 vskernels/kernels/placebo.py
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def scale(
    self,
    clip: vs.VideoNode,
    width: int | None = None,
    height: int | None = None,
    # ComplexScaler adds shift per planes
    shift: tuple[TopShift | list[TopShift], LeftShift | list[LeftShift]] = (0, 0),
    *,
    # `linear` and `sigmoid` from LinearScaler
    linear: bool | None = None,
    sigmoid: bool | tuple[Slope, Center] = False,
    # `border_handling`, `sample_grid_model`, `sar`, `dar`, `dar_in` and `keep_ar` from KeepArScaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    # ComplexScaler adds blur
    blur: float | None = None,
    **kwargs: Any,
) -> vs.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.

    If a `format` is provided, only a change in chroma subsampling is allowed.
    Other format characteristics (bit depth, sample type, color family, etc.) must match the source clip.

    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. If a tuple is provided, it is used uniformly. If a
            list is given, the shift is applied per plane.
        linear: Whether to linearize the input before descaling. If None, inferred from sigmoid.
        sigmoid: 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: Method for handling image borders during sampling.
        sample_grid_model: Model used to align sampling grid.
        sar: Sample aspect ratio to assume or convert to.
        dar: Desired display aspect ratio.
        dar_in: Input display aspect ratio, if different from clip's.
        keep_ar: Whether to adjust dimensions to preserve aspect ratio.
        blur: Amount of blur to apply during scaling.

    Returns:
        Scaled clip, optionally aspect-corrected and linearized.
    """
    if fmt := fallback(kwargs.get("format"), self.kwargs.get("format"), False):
        fmt = get_video_format(fmt)

        if (
            clip.format.color_family != fmt.color_family
            or clip.format.num_planes != fmt.num_planes
            or clip.format.sample_type != fmt.sample_type
            or clip.format.bits_per_sample != fmt.bits_per_sample
        ):
            raise CustomValueError("Only YUV subsampling scaling is supported.", self.__class__, fmt.name)

        shift = (to_arr(shift[0]), to_arr(shift[1]))

    return super().scale(
        clip,
        width,
        height,
        shift,
        linear=linear,
        sigmoid=sigmoid,
        border_handling=border_handling,
        sample_grid_model=sample_grid_model,
        sar=sar,
        dar=dar,
        dar_in=dar_in,
        keep_ar=keep_ar,
        blur=blur,
        **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
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
537
538
539
540
541
542
543
544
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)

EwaLanczosSharp

EwaLanczosSharp(
    radius: float = 3.238315484166236,
    blur: float = 0.9812505837223707,
    **kwargs: Any
)

Bases: Placebo

Ewa Lanczos resizer.

Initialize the kernel with a specific radius and 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:

  • radius

    (float, default: 3.238315484166236 ) –

    Overrides the filter kernel radius. Has no effect if the filter kernel is not resizeable.

  • blur

    (float, default: 0.9812505837223707 ) –

    Additional blur coefficient. This effectively stretches the kernel, without changing the effective radius of the filter radius.

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

Source code in vskernels/kernels/placebo.py
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
def __init__(
    self, radius: float = 3.2383154841662362076499, blur: float = 0.98125058372237073562493, **kwargs: Any
) -> None:
    """
    Initialize the kernel with a specific radius and 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:
        radius: Overrides the filter kernel radius. Has no effect if the filter kernel is not resizeable.
        blur: Additional blur coefficient. This effectively stretches the kernel,
            without changing the effective radius of the filter radius.
        **kwargs: Keyword arguments that configure the internal scaling behavior.
    """
    super().__init__(radius, None, None, blur=blur, **kwargs)

antiring instance-attribute

antiring = antiring

b instance-attribute

b = b

blur instance-attribute

blur = blur

c instance-attribute

c = c

clamp instance-attribute

clamp = clamp

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.

radius instance-attribute

radius = radius

scale_function class-attribute instance-attribute

scale_function = Resample

Scale function called internally when performing scaling operations.

taper instance-attribute

taper = taper

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/kernels/placebo.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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]:
    kwargs.pop("format", None)

    return (
        {
            "sx": kwargs.pop("src_left", shift[1]),
            "sy": kwargs.pop("src_top", shift[0]),
            "width": width,
            "height": height,
            "filter": self._kernel,
            "radius": self.radius,
            "param1": self.b,
            "param2": self.c,
            "clamp": self.clamp,
            "taper": self.taper,
            "blur": self.blur,
            "antiring": self.antiring,
        }
        | self.kwargs
        | kwargs
        | {"linearize": False, "sigmoidize": False}
    )

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
454
455
456
457
458
459
460
461
462
463
464
465
@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/kernels/placebo.py
192
193
194
195
196
197
198
199
200
201
202
203
@ComplexScaler.cachedproperty
def kernel_radius(self) -> int:
    if self.radius:
        return ceil(self.radius)

    if self.b or self.c:
        b, c = fallback(self.b, 0), fallback(self.c, 0.5)

        if (b, c) == (0, 0):
            return 1

    return 2

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift | list[TopShift], LeftShift | list[LeftShift]] = (
        0,
        0,
    ),
    *,
    linear: bool | None = None,
    sigmoid: bool | tuple[Slope, Center] = False,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    blur: float | None = None,
    **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.

If a format is provided, only a change in chroma subsampling is allowed. Other format characteristics (bit depth, sample type, color family, etc.) must match the source clip.

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 vskernels/kernels/placebo.py
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def scale(
    self,
    clip: vs.VideoNode,
    width: int | None = None,
    height: int | None = None,
    # ComplexScaler adds shift per planes
    shift: tuple[TopShift | list[TopShift], LeftShift | list[LeftShift]] = (0, 0),
    *,
    # `linear` and `sigmoid` from LinearScaler
    linear: bool | None = None,
    sigmoid: bool | tuple[Slope, Center] = False,
    # `border_handling`, `sample_grid_model`, `sar`, `dar`, `dar_in` and `keep_ar` from KeepArScaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    # ComplexScaler adds blur
    blur: float | None = None,
    **kwargs: Any,
) -> vs.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.

    If a `format` is provided, only a change in chroma subsampling is allowed.
    Other format characteristics (bit depth, sample type, color family, etc.) must match the source clip.

    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. If a tuple is provided, it is used uniformly. If a
            list is given, the shift is applied per plane.
        linear: Whether to linearize the input before descaling. If None, inferred from sigmoid.
        sigmoid: 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: Method for handling image borders during sampling.
        sample_grid_model: Model used to align sampling grid.
        sar: Sample aspect ratio to assume or convert to.
        dar: Desired display aspect ratio.
        dar_in: Input display aspect ratio, if different from clip's.
        keep_ar: Whether to adjust dimensions to preserve aspect ratio.
        blur: Amount of blur to apply during scaling.

    Returns:
        Scaled clip, optionally aspect-corrected and linearized.
    """
    if fmt := fallback(kwargs.get("format"), self.kwargs.get("format"), False):
        fmt = get_video_format(fmt)

        if (
            clip.format.color_family != fmt.color_family
            or clip.format.num_planes != fmt.num_planes
            or clip.format.sample_type != fmt.sample_type
            or clip.format.bits_per_sample != fmt.bits_per_sample
        ):
            raise CustomValueError("Only YUV subsampling scaling is supported.", self.__class__, fmt.name)

        shift = (to_arr(shift[0]), to_arr(shift[1]))

    return super().scale(
        clip,
        width,
        height,
        shift,
        linear=linear,
        sigmoid=sigmoid,
        border_handling=border_handling,
        sample_grid_model=sample_grid_model,
        sar=sar,
        dar=dar,
        dar_in=dar_in,
        keep_ar=keep_ar,
        blur=blur,
        **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
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
537
538
539
540
541
542
543
544
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)

EwaRobidoux

EwaRobidoux(**kwargs: Any)

Bases: Placebo

Ewa Robidoux resizer.

Initialize the kernel 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.

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

Source code in vskernels/kernels/placebo.py
395
396
397
398
399
400
401
402
403
404
405
406
407
408
def __init__(self, **kwargs: Any) -> None:
    """
    Initialize the kernel 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.
    """
    super().__init__(None, None, None, **kwargs)

antiring instance-attribute

antiring = antiring

b instance-attribute

b = b

blur instance-attribute

blur = blur

c instance-attribute

c = c

clamp instance-attribute

clamp = clamp

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.

radius instance-attribute

radius = radius

scale_function class-attribute instance-attribute

scale_function = Resample

Scale function called internally when performing scaling operations.

taper instance-attribute

taper = taper

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/kernels/placebo.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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]:
    kwargs.pop("format", None)

    return (
        {
            "sx": kwargs.pop("src_left", shift[1]),
            "sy": kwargs.pop("src_top", shift[0]),
            "width": width,
            "height": height,
            "filter": self._kernel,
            "radius": self.radius,
            "param1": self.b,
            "param2": self.c,
            "clamp": self.clamp,
            "taper": self.taper,
            "blur": self.blur,
            "antiring": self.antiring,
        }
        | self.kwargs
        | kwargs
        | {"linearize": False, "sigmoidize": False}
    )

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
454
455
456
457
458
459
460
461
462
463
464
465
@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/kernels/placebo.py
192
193
194
195
196
197
198
199
200
201
202
203
@ComplexScaler.cachedproperty
def kernel_radius(self) -> int:
    if self.radius:
        return ceil(self.radius)

    if self.b or self.c:
        b, c = fallback(self.b, 0), fallback(self.c, 0.5)

        if (b, c) == (0, 0):
            return 1

    return 2

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift | list[TopShift], LeftShift | list[LeftShift]] = (
        0,
        0,
    ),
    *,
    linear: bool | None = None,
    sigmoid: bool | tuple[Slope, Center] = False,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    blur: float | None = None,
    **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.

If a format is provided, only a change in chroma subsampling is allowed. Other format characteristics (bit depth, sample type, color family, etc.) must match the source clip.

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 vskernels/kernels/placebo.py
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def scale(
    self,
    clip: vs.VideoNode,
    width: int | None = None,
    height: int | None = None,
    # ComplexScaler adds shift per planes
    shift: tuple[TopShift | list[TopShift], LeftShift | list[LeftShift]] = (0, 0),
    *,
    # `linear` and `sigmoid` from LinearScaler
    linear: bool | None = None,
    sigmoid: bool | tuple[Slope, Center] = False,
    # `border_handling`, `sample_grid_model`, `sar`, `dar`, `dar_in` and `keep_ar` from KeepArScaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    # ComplexScaler adds blur
    blur: float | None = None,
    **kwargs: Any,
) -> vs.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.

    If a `format` is provided, only a change in chroma subsampling is allowed.
    Other format characteristics (bit depth, sample type, color family, etc.) must match the source clip.

    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. If a tuple is provided, it is used uniformly. If a
            list is given, the shift is applied per plane.
        linear: Whether to linearize the input before descaling. If None, inferred from sigmoid.
        sigmoid: 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: Method for handling image borders during sampling.
        sample_grid_model: Model used to align sampling grid.
        sar: Sample aspect ratio to assume or convert to.
        dar: Desired display aspect ratio.
        dar_in: Input display aspect ratio, if different from clip's.
        keep_ar: Whether to adjust dimensions to preserve aspect ratio.
        blur: Amount of blur to apply during scaling.

    Returns:
        Scaled clip, optionally aspect-corrected and linearized.
    """
    if fmt := fallback(kwargs.get("format"), self.kwargs.get("format"), False):
        fmt = get_video_format(fmt)

        if (
            clip.format.color_family != fmt.color_family
            or clip.format.num_planes != fmt.num_planes
            or clip.format.sample_type != fmt.sample_type
            or clip.format.bits_per_sample != fmt.bits_per_sample
        ):
            raise CustomValueError("Only YUV subsampling scaling is supported.", self.__class__, fmt.name)

        shift = (to_arr(shift[0]), to_arr(shift[1]))

    return super().scale(
        clip,
        width,
        height,
        shift,
        linear=linear,
        sigmoid=sigmoid,
        border_handling=border_handling,
        sample_grid_model=sample_grid_model,
        sar=sar,
        dar=dar,
        dar_in=dar_in,
        keep_ar=keep_ar,
        blur=blur,
        **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
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
537
538
539
540
541
542
543
544
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)

EwaRobidouxSharp

EwaRobidouxSharp(**kwargs: Any)

Bases: Placebo

Ewa Robidoux Sharp resizer.

Initialize the kernel 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.

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

Source code in vskernels/kernels/placebo.py
418
419
420
421
422
423
424
425
426
427
428
429
430
431
def __init__(self, **kwargs: Any) -> None:
    """
    Initialize the kernel 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.
    """
    super().__init__(None, None, None, **kwargs)

antiring instance-attribute

antiring = antiring

b instance-attribute

b = b

blur instance-attribute

blur = blur

c instance-attribute

c = c

clamp instance-attribute

clamp = clamp

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.

radius instance-attribute

radius = radius

scale_function class-attribute instance-attribute

scale_function = Resample

Scale function called internally when performing scaling operations.

taper instance-attribute

taper = taper

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/kernels/placebo.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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]:
    kwargs.pop("format", None)

    return (
        {
            "sx": kwargs.pop("src_left", shift[1]),
            "sy": kwargs.pop("src_top", shift[0]),
            "width": width,
            "height": height,
            "filter": self._kernel,
            "radius": self.radius,
            "param1": self.b,
            "param2": self.c,
            "clamp": self.clamp,
            "taper": self.taper,
            "blur": self.blur,
            "antiring": self.antiring,
        }
        | self.kwargs
        | kwargs
        | {"linearize": False, "sigmoidize": False}
    )

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
454
455
456
457
458
459
460
461
462
463
464
465
@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/kernels/placebo.py
192
193
194
195
196
197
198
199
200
201
202
203
@ComplexScaler.cachedproperty
def kernel_radius(self) -> int:
    if self.radius:
        return ceil(self.radius)

    if self.b or self.c:
        b, c = fallback(self.b, 0), fallback(self.c, 0.5)

        if (b, c) == (0, 0):
            return 1

    return 2

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift | list[TopShift], LeftShift | list[LeftShift]] = (
        0,
        0,
    ),
    *,
    linear: bool | None = None,
    sigmoid: bool | tuple[Slope, Center] = False,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    blur: float | None = None,
    **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.

If a format is provided, only a change in chroma subsampling is allowed. Other format characteristics (bit depth, sample type, color family, etc.) must match the source clip.

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 vskernels/kernels/placebo.py
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def scale(
    self,
    clip: vs.VideoNode,
    width: int | None = None,
    height: int | None = None,
    # ComplexScaler adds shift per planes
    shift: tuple[TopShift | list[TopShift], LeftShift | list[LeftShift]] = (0, 0),
    *,
    # `linear` and `sigmoid` from LinearScaler
    linear: bool | None = None,
    sigmoid: bool | tuple[Slope, Center] = False,
    # `border_handling`, `sample_grid_model`, `sar`, `dar`, `dar_in` and `keep_ar` from KeepArScaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    # ComplexScaler adds blur
    blur: float | None = None,
    **kwargs: Any,
) -> vs.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.

    If a `format` is provided, only a change in chroma subsampling is allowed.
    Other format characteristics (bit depth, sample type, color family, etc.) must match the source clip.

    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. If a tuple is provided, it is used uniformly. If a
            list is given, the shift is applied per plane.
        linear: Whether to linearize the input before descaling. If None, inferred from sigmoid.
        sigmoid: 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: Method for handling image borders during sampling.
        sample_grid_model: Model used to align sampling grid.
        sar: Sample aspect ratio to assume or convert to.
        dar: Desired display aspect ratio.
        dar_in: Input display aspect ratio, if different from clip's.
        keep_ar: Whether to adjust dimensions to preserve aspect ratio.
        blur: Amount of blur to apply during scaling.

    Returns:
        Scaled clip, optionally aspect-corrected and linearized.
    """
    if fmt := fallback(kwargs.get("format"), self.kwargs.get("format"), False):
        fmt = get_video_format(fmt)

        if (
            clip.format.color_family != fmt.color_family
            or clip.format.num_planes != fmt.num_planes
            or clip.format.sample_type != fmt.sample_type
            or clip.format.bits_per_sample != fmt.bits_per_sample
        ):
            raise CustomValueError("Only YUV subsampling scaling is supported.", self.__class__, fmt.name)

        shift = (to_arr(shift[0]), to_arr(shift[1]))

    return super().scale(
        clip,
        width,
        height,
        shift,
        linear=linear,
        sigmoid=sigmoid,
        border_handling=border_handling,
        sample_grid_model=sample_grid_model,
        sar=sar,
        dar=dar,
        dar_in=dar_in,
        keep_ar=keep_ar,
        blur=blur,
        **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
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
537
538
539
540
541
542
543
544
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)

Placebo

Placebo(
    radius: float | None = None,
    b: float | None = None,
    c: float | None = None,
    clamp: float = 0.0,
    blur: float = 0.0,
    taper: float = 0.0,
    antiring: float = 0.0,
    **kwargs: Any
)

Bases: ComplexScaler

Abstract Placebo scaler class.

This class and its subclasses depend on vs-placebo.

Initialize the scaler with optional arguments.

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:

  • radius

    (float | None, default: None ) –

    Overrides the filter kernel radius. Has no effect if the filter kernel is not resizeable.

  • b

    (float | None, default: None ) –

    The 'b' parameter for bicubic interpolation.

  • c

    (float | None, default: None ) –

    The 'c' parameter for bicubic interpolation.

  • clamp

    (float, default: 0.0 ) –

    Represents an extra weighting/clamping coefficient for negative weights. A value of 0.0 represents no clamping. A value of 1.0 represents full clamping, i.e. all negative lobes will be removed.

  • blur

    (float, default: 0.0 ) –

    Additional blur coefficient. This effectively stretches the kernel, without changing the effective radius of the filter radius.

  • taper

    (float, default: 0.0 ) –

    Additional taper coefficient. This essentially flattens the function's center.

  • antiring

    (float, default: 0.0 ) –

    Antiringing strength.

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

Source code in vskernels/kernels/placebo.py
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
def __init__(
    self,
    radius: float | None = None,
    b: float | None = None,
    c: float | None = None,
    clamp: float = 0.0,
    blur: float = 0.0,
    taper: float = 0.0,
    antiring: float = 0.0,
    **kwargs: Any,
) -> None:
    """
    Initialize the scaler with optional arguments.

    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:
        radius: Overrides the filter kernel radius. Has no effect if the filter kernel is not resizeable.
        b: The 'b' parameter for bicubic interpolation.
        c: The 'c' parameter for bicubic interpolation.
        clamp: Represents an extra weighting/clamping coefficient for negative weights. A value of 0.0 represents no
            clamping. A value of 1.0 represents full clamping, i.e. all negative lobes will be removed.
        blur: Additional blur coefficient. This effectively stretches the kernel, without changing the effective
            radius of the filter radius.
        taper: Additional taper coefficient. This essentially flattens the function's center.
        antiring: Antiringing strength.
        **kwargs: Keyword arguments that configure the internal scaling behavior.
    """
    self.radius = radius
    self.b = b
    self.c = c
    self.clamp = clamp
    self.blur = blur
    self.taper = taper
    self.antiring = antiring
    super().__init__(**kwargs)

antiring instance-attribute

antiring = antiring

b instance-attribute

b = b

blur instance-attribute

blur = blur

c instance-attribute

c = c

clamp instance-attribute

clamp = clamp

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.

radius instance-attribute

radius = radius

scale_function class-attribute instance-attribute

scale_function = Resample

Scale function called internally when performing scaling operations.

taper instance-attribute

taper = taper

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/kernels/placebo.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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]:
    kwargs.pop("format", None)

    return (
        {
            "sx": kwargs.pop("src_left", shift[1]),
            "sy": kwargs.pop("src_top", shift[0]),
            "width": width,
            "height": height,
            "filter": self._kernel,
            "radius": self.radius,
            "param1": self.b,
            "param2": self.c,
            "clamp": self.clamp,
            "taper": self.taper,
            "blur": self.blur,
            "antiring": self.antiring,
        }
        | self.kwargs
        | kwargs
        | {"linearize": False, "sigmoidize": False}
    )

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
454
455
456
457
458
459
460
461
462
463
464
465
@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/kernels/placebo.py
192
193
194
195
196
197
198
199
200
201
202
203
@ComplexScaler.cachedproperty
def kernel_radius(self) -> int:
    if self.radius:
        return ceil(self.radius)

    if self.b or self.c:
        b, c = fallback(self.b, 0), fallback(self.c, 0.5)

        if (b, c) == (0, 0):
            return 1

    return 2

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift | list[TopShift], LeftShift | list[LeftShift]] = (
        0,
        0,
    ),
    *,
    linear: bool | None = None,
    sigmoid: bool | tuple[Slope, Center] = False,
    border_handling: BorderHandling = MIRROR,
    sample_grid_model: SampleGridModel = MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    blur: float | None = None,
    **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.

If a format is provided, only a change in chroma subsampling is allowed. Other format characteristics (bit depth, sample type, color family, etc.) must match the source clip.

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 vskernels/kernels/placebo.py
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def scale(
    self,
    clip: vs.VideoNode,
    width: int | None = None,
    height: int | None = None,
    # ComplexScaler adds shift per planes
    shift: tuple[TopShift | list[TopShift], LeftShift | list[LeftShift]] = (0, 0),
    *,
    # `linear` and `sigmoid` from LinearScaler
    linear: bool | None = None,
    sigmoid: bool | tuple[Slope, Center] = False,
    # `border_handling`, `sample_grid_model`, `sar`, `dar`, `dar_in` and `keep_ar` from KeepArScaler
    border_handling: BorderHandling = BorderHandling.MIRROR,
    sample_grid_model: SampleGridModel = SampleGridModel.MATCH_EDGES,
    sar: Sar | float | bool | None = None,
    dar: Dar | float | bool | None = None,
    dar_in: Dar | bool | float | None = None,
    keep_ar: bool | None = None,
    # ComplexScaler adds blur
    blur: float | None = None,
    **kwargs: Any,
) -> vs.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.

    If a `format` is provided, only a change in chroma subsampling is allowed.
    Other format characteristics (bit depth, sample type, color family, etc.) must match the source clip.

    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. If a tuple is provided, it is used uniformly. If a
            list is given, the shift is applied per plane.
        linear: Whether to linearize the input before descaling. If None, inferred from sigmoid.
        sigmoid: 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: Method for handling image borders during sampling.
        sample_grid_model: Model used to align sampling grid.
        sar: Sample aspect ratio to assume or convert to.
        dar: Desired display aspect ratio.
        dar_in: Input display aspect ratio, if different from clip's.
        keep_ar: Whether to adjust dimensions to preserve aspect ratio.
        blur: Amount of blur to apply during scaling.

    Returns:
        Scaled clip, optionally aspect-corrected and linearized.
    """
    if fmt := fallback(kwargs.get("format"), self.kwargs.get("format"), False):
        fmt = get_video_format(fmt)

        if (
            clip.format.color_family != fmt.color_family
            or clip.format.num_planes != fmt.num_planes
            or clip.format.sample_type != fmt.sample_type
            or clip.format.bits_per_sample != fmt.bits_per_sample
        ):
            raise CustomValueError("Only YUV subsampling scaling is supported.", self.__class__, fmt.name)

        shift = (to_arr(shift[0]), to_arr(shift[1]))

    return super().scale(
        clip,
        width,
        height,
        shift,
        linear=linear,
        sigmoid=sigmoid,
        border_handling=border_handling,
        sample_grid_model=sample_grid_model,
        sar=sar,
        dar=dar,
        dar_in=dar_in,
        keep_ar=keep_ar,
        blur=blur,
        **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
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
537
538
539
540
541
542
543
544
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)