Skip to content

shaders

Classes:

PlaceboShader

PlaceboShader(
    shader: str | SPathLike,
    *,
    kernel: KernelT = Catrom,
    scaler: ScalerT | None = None,
    shifter: KernelT | None = None,
    **kwargs: Any
)

Bases: BaseGenericScaler

Placebo shader class.

Methods:

Attributes:

Source code
23
24
25
26
27
28
29
30
31
32
33
34
def __init__(
    self,
    shader: str | SPathLike,
    *,
    kernel: KernelT = Catrom,
    scaler: ScalerT | None = None,
    shifter: KernelT | None = None,
    **kwargs: Any
) -> None:
    super().__init__(kernel=kernel, scaler=scaler, shifter=shifter, **kwargs)

    self.shader = SPath(shader).resolve().to_str()

kernel instance-attribute

kernel = ensure_obj(kernel, __class__)

kwargs instance-attribute

kwargs: KwargsT = kwargs

Arguments passed to the internal scale function

scale_function instance-attribute

scale_function: Callable[..., VideoNode]

Scale function called internally when scaling

scaler instance-attribute

scaler = ensure_obj(scaler or kernel, __class__)

shader instance-attribute

shader = to_str()

shifter instance-attribute

shifter = ensure_obj(shifter or kernel, __class__)

ensure_obj classmethod

ensure_obj(
    scaler: str | type[BaseScalerT] | BaseScalerT | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> BaseScalerT
Source code
201
202
203
204
205
206
207
208
@classmethod
def ensure_obj(
    cls: type[BaseScalerT], scaler: str | type[BaseScalerT] | BaseScalerT | None = None, /,
    func_except: FuncExceptT | None = None
) -> BaseScalerT:
    return _base_ensure_obj(
        cls, (mro := cls.mro())[mro.index(BaseScaler) - 1], scaler, cls._err_class, [], func_except
    )

from_param classmethod

from_param(
    scaler: str | type[BaseScalerT] | BaseScalerT | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> type[BaseScalerT]
Source code
192
193
194
195
196
197
198
199
@classmethod
def from_param(
    cls: type[BaseScalerT], scaler: str | type[BaseScalerT] | BaseScalerT | None = None, /,
    func_except: FuncExceptT | None = None
) -> type[BaseScalerT]:
    return _base_from_param(
        cls, (mro := cls.mro())[mro.index(BaseScaler) - 1], scaler, cls._err_class, [], func_except
    )

get_clean_kwargs

get_clean_kwargs(*funcs: Callable[..., Any] | None) -> KwargsT
Source code
216
217
def get_clean_kwargs(self, *funcs: Callable[..., Any] | None) -> KwargsT:
    return _clean_self_kwargs(funcs, self)

get_implemented_funcs

get_implemented_funcs() -> tuple[Callable[..., Any], ...]
Source code
299
300
def get_implemented_funcs(self) -> tuple[Callable[..., Any], ...]:
    return (self.scale, self.supersample)

get_scale_args

get_scale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    *funcs: Callable[..., Any],
    **kwargs: Any
) -> KwargsT
Source code
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
@inject_kwargs_params
def get_scale_args(
    self, clip: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None, height: int | None = None,
    *funcs: Callable[..., Any], **kwargs: Any
) -> KwargsT:
    return (
        dict(
            src_top=shift[0],
            src_left=shift[1]
        )
        | self.get_clean_kwargs(*funcs)
        | dict(width=width, height=height)
        | kwargs
    )

kernel_radius

kernel_radius() -> int
Source code
210
211
212
213
214
@inject_self.cached.property
def kernel_radius(self) -> int:
    if hasattr(self, '_static_kernel_radius'):
        return ceil(self._static_kernel_radius)
    raise CustomNotImplementedError('kernel_radius is not implemented!', self.__class__)

multi

multi(
    clip: VideoNode,
    multi: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
272
273
274
275
276
277
278
279
280
281
@inject_self.cached
def multi(
    self, clip: vs.VideoNode, multi: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:

    import warnings

    warnings.warn('The "multi" method is deprecated. Use "supersample" instead.', DeprecationWarning)

    return self.supersample(clip, multi, shift, **kwargs)

pretty_string

pretty_string() -> str
Source code
225
226
227
@inject_self.cached.property
def pretty_string(self) -> str:
    return self._pretty_string()

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[float, float] = (0, 0),
    **kwargs: Any
) -> ConstantFormatVideoNode
Source code
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
@inject_self.cached
def scale(
    self,
    clip: vs.VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[float, float] = (0, 0),
    **kwargs: Any
) -> ConstantFormatVideoNode:
    assert check_variable(clip, self.__class__)

    width, height = self._wh_norm(clip, width, height)

    kwargs = self.kwargs | kwargs

    output = depth(clip, 16)

    # Add fake chroma planes
    if output.format.num_planes == 1:
        if width > output.width or height > output.height:
            output = output.resize.Point(format=vs.YUV444P16)
        else:
            for div in (4, 2):
                if width % div == 0 and height % div == 0:
                    blank = core.std.BlankClip(output, output.width // div, output.height // div, vs.GRAY16)
                    break
            else:
                blank = core.std.BlankClip(output, format=vs.GRAY16)

            output = join(output, blank, blank)

    # Configure filter param mainly used for chroma planes if input clip is GRAY. Box was slightly faster.
    if 'filter' not in kwargs:
        kwargs['filter'] = 'box' if output.format.num_planes == 1 else 'ewa_lanczos'

    output = core.placebo.Shader(
        output,
        self.shader,
        output.width * ceil(width / output.width),
        output.height * ceil(height / output.height),
        **kwargs
    )

    return self._finish_scale(output, clip, width, height, shift)

supersample

supersample(
    clip: VideoNode,
    rfactor: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
257
258
259
260
261
262
263
264
265
266
267
268
269
270
@inject_self.cached
def supersample(
    self, clip: vs.VideoNode, rfactor: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    assert check_variable_resolution(clip, self.multi)

    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)