Skip to content

util

Functions:

Attributes:

ExprVarRangeT module-attribute

ExprVars module-attribute

ExprVars: _ExprVars = _ExprVars

ExprVarsT module-attribute

ExprVarsT: TypeAlias = _ExprVars

complexpr_available module-attribute

complexpr_available = _complexpr_available()

bitdepth_aware_tokenize_expr

bitdepth_aware_tokenize_expr(
    clips: Sequence[VideoNode],
    expr: str,
    chroma: bool,
    func: FuncExceptT | None = None,
) -> str
Source code
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
def bitdepth_aware_tokenize_expr(
    clips: Sequence[vs.VideoNode], expr: str, chroma: bool, func: FuncExceptT | None = None
) -> str:
    from .exprop import ExprToken

    func = func or bitdepth_aware_tokenize_expr

    if not expr or len(expr) < 4:
        return expr

    replaces = list[tuple[str, Callable[[vs.VideoNode, bool, ColorRange], float]]]()

    for token in sorted(ExprToken, key=lambda x: len(x), reverse=True):
        if token.value in expr:
            replaces.append((token.value, token.get_value))

        if token.name in expr:
            replaces.append(
                (f'{token.__class__.__name__}.{token.name}', token.get_value)
            )

    if not replaces:
        return expr

    clips = list(clips)
    ranges = [ColorRange.from_video(c, func=func) for c in clips]

    mapped_clips = list(reversed(list(zip(['', *EXPR_VARS], clips[:1] + clips, ranges[:1] + ranges))))

    for mkey, function in replaces:
        if mkey in expr:
            for key, clip, crange in [
                (f'{mkey}_{k} ' if k else f'{mkey} ', clip, crange)
                for k, clip, crange in mapped_clips
            ]:
                expr = expr.replace(key, str(function(clip, chroma, crange) * 1.0) + ' ')

        if mkey in expr:
            raise CustomIndexError('Parsing error or not enough clips passed!', func, reason=expr)

    return expr

norm_expr_planes

norm_expr_planes(
    clip: VideoNode,
    expr: str | list[str],
    planes: PlanesT = None,
    **kwargs: Iterable[SupportsString] | SupportsString
) -> list[str]
Source code
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
def norm_expr_planes(
    clip: vs.VideoNode, expr: str | list[str], planes: PlanesT = None, **kwargs: Iterable[SupportsString] | SupportsString
) -> list[str]:
    assert clip.format

    expr_array = normalize_seq(expr, clip.format.num_planes)

    planes = normalize_planes(clip, planes)

    string_args = [(key, normalize_seq(value)) for key, value in kwargs.items()]

    return [
        exp.format(**({'plane_idx': i} | {key: value[i] for key, value in string_args}))
        if i in planes else '' for i, exp in enumerate(expr_array, 0)
    ]