Skip to content

helpers

Classes:

  • ClipVar

    Expression variable that wraps a VideoNode and provides symbolic and numeric access.

  • ComputedVar

    Represents a fully built RPN expression as a sequence of operations with per-plane operations support.

  • ExprVar

    Base interface for variables used in RPN expression

  • LiteralVar

    Literal value wrapper for use in RPN expressions.

  • Operators

    A singleton class that defines the expression operators used in inline_expr.

  • Tokens

    A singleton class that defines the expression tokens used in inline_expr.

Attributes:

  • ExprVarLike (TypeAlias) –

    Type alias representing any expression-compatible variable or literal.

ExprVarLike module-attribute

ExprVarLike: TypeAlias = int | float | str | ExprVar

Type alias representing any expression-compatible variable or literal.

op module-attribute

op = Operators()

The Operators singleton instance

tokens module-attribute

tokens = Tokens()

The Tokens singleton instance

ClipVar

ClipVar(char: str, node: VideoNode)

Bases: ExprVar, vs_object

Expression variable that wraps a VideoNode and provides symbolic and numeric access.

Initializes a new ClipVar instance.

Parameters:

  • char

    (str) –

    A short symbolic name representing this clip in the RPN expression.

  • node

    (VideoNode) –

    The actual VapourSynth VideoNode.

Methods:

  • as_var

    Converts the expression variable to a ComputedVar.

  • to_str

    Returns the string representation of the expression variable.

Attributes:

Source code
763
764
765
766
767
768
769
770
771
772
def __init__(self, char: str, node: vs.VideoNode) -> None:
    """
    Initializes a new ClipVar instance.

    Args:
        char: A short symbolic name representing this clip in the RPN expression.
        node: The actual VapourSynth VideoNode.
    """
    self._char = char
    self._node = node

ChromaMax class-attribute instance-attribute

ChromaMax: Final[ComputedVar] = cast(ComputedVar, ...)

The maximum chroma value in limited range.

ChromaMin class-attribute instance-attribute

ChromaMin: Final[ComputedVar] = cast(ComputedVar, ...)

The minimum chroma value in limited range.

ChromaRangeInMax class-attribute instance-attribute

ChromaRangeInMax: Final[ComputedVar] = cast(ComputedVar, ...)

Like ChromaRangeMax, but adapts to input range_in.

ChromaRangeInMin class-attribute instance-attribute

ChromaRangeInMin: Final[ComputedVar] = cast(ComputedVar, ...)

Like ChromaRangeMin, but adapts to input range_in.

ChromaRangeMax class-attribute instance-attribute

ChromaRangeMax: Final[ComputedVar] = cast(ComputedVar, ...)

Maximum chroma value based on input clip's color range.

ChromaRangeMin class-attribute instance-attribute

ChromaRangeMin: Final[ComputedVar] = cast(ComputedVar, ...)

Minimum chroma value based on input clip's color range.

LumaMax class-attribute instance-attribute

LumaMax: Final[ComputedVar] = cast(ComputedVar, ...)

The maximum luma value in limited range.

LumaMin class-attribute instance-attribute

LumaMin: Final[ComputedVar] = cast(ComputedVar, ...)

The minimum luma value in limited range.

LumaRangeInMax class-attribute instance-attribute

LumaRangeInMax: Final[ComputedVar] = cast(ComputedVar, ...)

Like LumaRangeMax, but adapts to input range_in.

LumaRangeInMin class-attribute instance-attribute

LumaRangeInMin: Final[ComputedVar] = cast(ComputedVar, ...)

Like LumaRangeMin, but adapts to input range_in.

LumaRangeMax class-attribute instance-attribute

LumaRangeMax: Final[ComputedVar] = cast(ComputedVar, ...)

Maximum luma value based on input clip's color range.

LumaRangeMin class-attribute instance-attribute

LumaRangeMin: Final[ComputedVar] = cast(ComputedVar, ...)

Minimum luma value based on input clip's color range.

Neutral class-attribute instance-attribute

Neutral: Final[ComputedVar] = cast(ComputedVar, ...)

The neutral value (e.g. 128 for 8-bit limited, 0 for float).

RangeHalf class-attribute instance-attribute

RangeHalf: Final[ComputedVar] = cast(ComputedVar, ...)

Half of the full range (e.g. 128.0 for 8-bit full range).

RangeInMax class-attribute instance-attribute

RangeInMax: Final[ComputedVar] = cast(ComputedVar, ...)

Like RangeMax, but adapts to input range_in.

RangeInMin class-attribute instance-attribute

RangeInMin: Final[ComputedVar] = cast(ComputedVar, ...)

Like RangeMin, but adapts to input range_in parameter.

RangeMax class-attribute instance-attribute

RangeMax: Final[ComputedVar] = cast(ComputedVar, ...)

Maximum value in full range (chroma-aware).

RangeMin class-attribute instance-attribute

RangeMin: Final[ComputedVar] = cast(ComputedVar, ...)

Minimum value in full range (chroma-aware).

RangeSize class-attribute instance-attribute

RangeSize: Final[ComputedVar] = cast(ComputedVar, ...)

The size of the full range (e.g. 256 for 8-bit, 65536 for 16-bit).

char property

char: str

A short symbolic name representing this clip in the RPN expression.

node property

node: VideoNode

The actual VapourSynth VideoNode.

props cached property

props: ClipVarProps

A helper to access frame properties.

as_var

as_var() -> ComputedVar

Converts the expression variable to a ComputedVar.

Returns:

Source code
464
465
466
467
468
469
470
471
472
473
def as_var(self) -> ComputedVar:
    """
    Converts the expression variable to a ComputedVar.

    Returns:
        A ComputedVar.
    """
    if isinstance(self, ComputedVar):
        return self
    return ComputedVar(self)

to_str

to_str(**kwargs: Any) -> str

Returns the string representation of the expression variable.

Parameters:

  • **kwargs

    (Any, default: {} ) –

    Additional keywords arguments.

Returns:

  • str

    The string representation of the expression variable.

Source code
440
441
442
443
444
445
446
447
448
449
450
def to_str(self, **kwargs: Any) -> str:
    """
    Returns the string representation of the expression variable.

    Args:
        **kwargs: Additional keywords arguments.

    Returns:
        The string representation of the expression variable.
    """
    return str(self)

ClipVarProps

ClipVarProps(var: ClipVar)

Helper class exposing common frame properties of a ClipVar.

Attributes:

Source code
688
689
def __init__(self, var: ClipVar) -> None:
    self._var = var

PlaneStatsAverage instance-attribute

PlaneStatsAverage: ComputedVar

PlaneStatsMax instance-attribute

PlaneStatsMax: ComputedVar

PlaneStatsMin instance-attribute

PlaneStatsMin: ComputedVar

ComputedVar

Bases: ExprVar

Represents a fully built RPN expression as a sequence of operations with per-plane operations support.

Initializes a new ComputedVar.

Parameters:

Methods:

  • as_var

    Converts the expression variable to a ComputedVar.

  • to_str

    Returns a string representation of the expression in RPN format for the selected plane.

  • to_str_per_plane

    Returns string representations of the expression in RPN format for each plane.

Attributes:

  • b (Self) –

    Returns the B (blue) plane expression.

  • g (Self) –

    Returns the G (green) plane expression.

  • r (Self) –

    Returns the R (red) plane expression.

  • u (Self) –

    Returns the U (chroma) plane expression.

  • uv (tuple[Self, Self]) –

    Returns the U and V (chroma) planes expression.

  • v (Self) –

    Returns the V (chroma) plane expression.

  • y (Self) –

    Returns the Y (luma) plane expression.

Source code
501
502
503
504
505
506
507
508
509
510
def __init__(self, operations: ExprVarLike | Iterable[ExprVarLike]) -> None:
    """
    Initializes a new ComputedVar.

    Args:
        operations: An iterable of operators and/or expression variables that define the computation.
    """
    self._operations_per_plane: list[list[ExprVar]] = [
        [LiteralVar(x) if not isinstance(x, ExprVar) else x for x in to_arr(operations)]  # type: ignore[arg-type]
    ] * 3

b deletable property writable

b: Self

Returns the B (blue) plane expression.

g deletable property writable

g: Self

Returns the G (green) plane expression.

r deletable property writable

r: Self

Returns the R (red) plane expression.

u deletable property writable

u: Self

Returns the U (chroma) plane expression.

uv deletable property writable

uv: tuple[Self, Self]

Returns the U and V (chroma) planes expression.

v deletable property writable

v: Self

Returns the V (chroma) plane expression.

y deletable property writable

y: Self

Returns the Y (luma) plane expression.

as_var

as_var() -> ComputedVar

Converts the expression variable to a ComputedVar.

Returns:

Source code
464
465
466
467
468
469
470
471
472
473
def as_var(self) -> ComputedVar:
    """
    Converts the expression variable to a ComputedVar.

    Returns:
        A ComputedVar.
    """
    if isinstance(self, ComputedVar):
        return self
    return ComputedVar(self)

to_str

to_str(*, plane: int = 0, **kwargs: Any) -> str

Returns a string representation of the expression in RPN format for the selected plane.

Parameters:

  • plane

    (int, default: 0 ) –

    Optional plane index to select which expression to stringify.

  • **kwargs

    (Any, default: {} ) –

    Additional keyword arguments passed to each expression's to_str method.

Returns:

  • str

    String representation of the expression in RPN format for the selected plane.

Source code
665
666
667
668
669
670
671
672
673
674
675
676
677
def to_str(self, *, plane: int = 0, **kwargs: Any) -> str:
    """
    Returns a string representation of the expression in RPN format for the selected plane.

    Args:
        plane: Optional plane index to select which expression to stringify.
        **kwargs: Additional keyword arguments passed to each expression's to_str method.

    Returns:
        String representation of the expression in RPN format for the selected plane.
    """

    return " ".join(x.to_str(**kwargs) for x in self._operations_per_plane[plane])

to_str_per_plane

to_str_per_plane(num_planes: int = 3) -> list[str]

Returns string representations of the expression in RPN format for each plane.

Parameters:

  • num_planes

    (int, default: 3 ) –

    Optional number of planes to include (defaults to 3).

Returns:

  • list[str]

    A list of strings, one for each plane.

Source code
653
654
655
656
657
658
659
660
661
662
663
def to_str_per_plane(self, num_planes: int = 3) -> list[str]:
    """
    Returns string representations of the expression in RPN format for each plane.

    Args:
        num_planes: Optional number of planes to include (defaults to 3).

    Returns:
        A list of strings, one for each plane.
    """
    return [p.to_str(plane=i) for x, i in zip(self._operations_per_plane, range(num_planes)) for p in x]

ExprVar

Bases: ABC

Base interface for variables used in RPN expression

Methods:

  • as_var

    Converts the expression variable to a ComputedVar.

  • to_str

    Returns the string representation of the expression variable.

as_var

as_var() -> ComputedVar

Converts the expression variable to a ComputedVar.

Returns:

Source code
464
465
466
467
468
469
470
471
472
473
def as_var(self) -> ComputedVar:
    """
    Converts the expression variable to a ComputedVar.

    Returns:
        A ComputedVar.
    """
    if isinstance(self, ComputedVar):
        return self
    return ComputedVar(self)

to_str

to_str(**kwargs: Any) -> str

Returns the string representation of the expression variable.

Parameters:

  • **kwargs

    (Any, default: {} ) –

    Additional keywords arguments.

Returns:

  • str

    The string representation of the expression variable.

Source code
440
441
442
443
444
445
446
447
448
449
450
def to_str(self, **kwargs: Any) -> str:
    """
    Returns the string representation of the expression variable.

    Args:
        **kwargs: Additional keywords arguments.

    Returns:
        The string representation of the expression variable.
    """
    return str(self)

LiteralVar

LiteralVar(value: ExprVarLike)

Bases: ExprVar

Literal value wrapper for use in RPN expressions.

Initializes a new LiteralVar.

Parameters:

  • value

    (ExprVarLike) –

    An integer, float, string, or ExprVar to wrap.

Methods:

  • as_var

    Converts the expression variable to a ComputedVar.

  • to_str

    Returns the string representation of the expression variable.

Attributes:

Source code
483
484
485
486
487
488
489
490
def __init__(self, value: ExprVarLike):
    """
    Initializes a new LiteralVar.

    Args:
        value: An integer, float, string, or ExprVar to wrap.
    """
    self.value = value

value instance-attribute

value = value

as_var

as_var() -> ComputedVar

Converts the expression variable to a ComputedVar.

Returns:

Source code
464
465
466
467
468
469
470
471
472
473
def as_var(self) -> ComputedVar:
    """
    Converts the expression variable to a ComputedVar.

    Returns:
        A ComputedVar.
    """
    if isinstance(self, ComputedVar):
        return self
    return ComputedVar(self)

to_str

to_str(**kwargs: Any) -> str

Returns the string representation of the expression variable.

Parameters:

  • **kwargs

    (Any, default: {} ) –

    Additional keywords arguments.

Returns:

  • str

    The string representation of the expression variable.

Source code
440
441
442
443
444
445
446
447
448
449
450
def to_str(self, **kwargs: Any) -> str:
    """
    Returns the string representation of the expression variable.

    Args:
        **kwargs: Additional keywords arguments.

    Returns:
        The string representation of the expression variable.
    """
    return str(self)

Operators

Bases: Singleton

A singleton class that defines the expression operators used in inline_expr.

Methods:

  • __call__

    Returns itself.

  • abs

    Absolute value of x.

  • abs_pix

    Absolute pixel access.

  • acos

    Arccosine (inverse cosine) of x.

  • add

    Performs addition of two elements (x + y).

  • and_

    Performs a logical AND.

  • asin

    Arcsine (inverse sine) of x.

  • atan

    Arctangent of x

  • bitand

    Performs a bitwise AND.

  • bitnot

    Performs a bitwise NOT.

  • bitor

    Performs a bitwise OR.

  • bitxor

    Performs a bitwise XOR.

  • ceil

    Round up x to nearest integer.

  • clamp

    Clamps a value between a min and a max.

  • convolution

    Convenience method wrapping ExprOp.convolution.

  • cos

    Cosine (radians) of x.

  • div

    Performs division of two elements (x / y).

  • eq

    Performs x == y.

  • exp

    Exponential function (e^x).

  • floor

    Round down x to nearest integer.

  • gt

    Performs x > y.

  • gte

    Performs x >= y.

  • lerp

    Performs a linear interpolation of t between x and y.

  • log

    Natural logarithm of x.

  • lt

    Performs x < y.

  • lte

    Performs x <= y.

  • matrix

    Convenience method wrapping ExprOp.matrix.

  • max

    Calculates the maximum of x and y.

  • min

    Calculates the minimum of x and y.

  • mod

    Performs x % y.

  • mul

    Performs multiplication of two elements (x * y).

  • neg

    Negation (multiply by -1) of x.

  • not_

    Logical NOT of x.

  • or_

    Performs a logical OR.

  • polyval

    Evaluates a polynomial at x using Horner's method.

  • pow

    Performs x to the power of y (x ** y).

  • rel_pix

    Relative pixel access.

  • round

    Round x to nearest integer.

  • sgn

    Sign function (-1, 0, or 1) of x.

  • sin

    Sine (radians) of x.

  • sqrt

    Square root of x.

  • sub

    Performs subtraction of two elements (x - y).

  • tan

    Tangent (radians) of x.

  • tern

    Ternary operator (if cond then if_true else if_false).

  • trunc

    Truncate x to integer (toward zero).

  • xor

    Performs a logical XOR.

Attributes:

if_ class-attribute instance-attribute

if_ = tern

Alias for tern.

__call__

__call__() -> Self

Returns itself.

Returns:

  • Self

    Returns itself.

Source code
215
216
217
218
219
220
221
222
def __call__(self) -> Self:
    """
    Returns itself.

    Returns:
        Returns itself.
    """
    return self

abs

Absolute value of x.

Source code
72
73
74
def abs(self, x: ExprVarLike) -> ComputedVar:
    """Absolute value of x."""
    return ComputedVar([x, ExprOp.ABS])

abs_pix

abs_pix(char: SupportsString, x: int, y: int) -> ComputedVar

Absolute pixel access.

Source code
211
212
213
def abs_pix(self, char: SupportsString, x: int, y: int) -> ComputedVar:
    """Absolute pixel access."""
    return ComputedVar(ExprOp.ABS_PIX.format(char=char, x=x, y=y))

acos

Arccosine (inverse cosine) of x.

Source code
60
61
62
def acos(self, x: ExprVarLike) -> ComputedVar:
    """Arccosine (inverse cosine) of x."""
    return ComputedVar([x, ExprOp.ACOS])

add

Performs addition of two elements (x + y).

Source code
117
118
119
def add(self, x: ExprVarLike, y: ExprVarLike) -> ComputedVar:
    """Performs addition of two elements (x + y)."""
    return ComputedVar([x, y, ExprOp.ADD])

and_

Performs a logical AND.

Source code
157
158
159
def and_(self, x: ExprVarLike, y: ExprVarLike) -> ComputedVar:
    """Performs a logical AND."""
    return ComputedVar([x, y, ExprOp.AND])

asin

Arcsine (inverse sine) of x.

Source code
52
53
54
def asin(self, x: ExprVarLike) -> ComputedVar:
    """Arcsine (inverse sine) of x."""
    return ComputedVar([x, ExprOp.ASIN])

atan

Arctangent of x

Source code
68
69
70
def atan(self, x: ExprVarLike) -> ComputedVar:
    """Arctangent of x"""
    return ComputedVar([x, ExprOp.ATAN])

bitand

Performs a bitwise AND.

Source code
173
174
175
def bitand(self, x: ExprVarLike, y: ExprVarLike) -> ComputedVar:
    """Performs a bitwise AND."""
    return ComputedVar([x, y, ExprOp.BITAND])

bitnot

bitnot(x: ExprVarLike) -> ComputedVar

Performs a bitwise NOT.

Source code
96
97
98
def bitnot(self, x: ExprVarLike) -> ComputedVar:
    """Performs a bitwise NOT."""
    return ComputedVar([x, ExprOp.BITNOT])

bitor

Performs a bitwise OR.

Source code
177
178
179
def bitor(self, x: ExprVarLike, y: ExprVarLike) -> ComputedVar:
    """Performs a bitwise OR."""
    return ComputedVar([x, y, ExprOp.BITOR])

bitxor

Performs a bitwise XOR.

Source code
181
182
183
def bitxor(self, x: ExprVarLike, y: ExprVarLike) -> ComputedVar:
    """Performs a bitwise XOR."""
    return ComputedVar([x, y, ExprOp.BITXOR])

ceil

Round up x to nearest integer.

Source code
92
93
94
def ceil(self, x: ExprVarLike) -> ComputedVar:
    """Round up x to nearest integer."""
    return ComputedVar([x, ExprOp.CEIL])

clamp

Clamps a value between a min and a max.

Source code
193
194
195
def clamp(self, x: ExprVarLike, min: ExprVarLike, max: ExprVarLike) -> ComputedVar:
    """Clamps a value between a min and a max."""
    return ComputedVar([x, min, max, ExprOp.CLAMP])

convolution

convolution(
    var: SupportsString | Collection[SupportsString],
    matrix: Iterable[ExprVarLike] | Iterable[Iterable[ExprVarLike]],
    bias: ExprVarLike | None = None,
    divisor: ExprVarLike | bool = True,
    saturate: bool = True,
    mode: OnePassConvModeT = SQUARE,
    premultiply: ExprVarLike | None = None,
    multiply: ExprVarLike | None = None,
    clamp: bool = False,
) -> ComputedVar

Convenience method wrapping ExprOp.convolution.

Parameters:

  • var

    (SupportsString | Collection[SupportsString]) –

    The variable used as the central value or elements proportional to the radius if mode is Literal[ConvMode.TEMPORAL].

  • matrix

    (Iterable[ExprVarLike] | Iterable[Iterable[ExprVarLike]]) –

    A flat or 2D iterable representing the convolution weights.

  • bias

    (ExprVarLike | None, default: None ) –

    A constant value to add to the result after convolution (default: None).

  • divisor

    (ExprVarLike | bool, default: True ) –

    If True, normalizes by the sum of weights; if False, skips division; Otherwise, divides by this value.

  • saturate

    (bool, default: True ) –

    If False, applies abs() to avoid negatives.

  • mode

    (OnePassConvModeT, default: SQUARE ) –

    The convolution shape.

  • premultiply

    (ExprVarLike | None, default: None ) –

    Optional scalar to multiply the result before normalization.

  • multiply

    (ExprVarLike | None, default: None ) –

    Optional scalar to multiply the result at the end.

  • clamp

    (bool, default: False ) –

    If True, clamps the final result to [RangeMin, RangeMax].

Returns:

  • ComputedVar

    A ComputedVar representing the expression-based convolution.

Source code
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
def convolution(
    self,
    var: SupportsString | Collection[SupportsString],
    matrix: Iterable[ExprVarLike] | Iterable[Iterable[ExprVarLike]],
    bias: ExprVarLike | None = None,
    divisor: ExprVarLike | bool = True,
    saturate: bool = True,
    mode: OnePassConvModeT = ConvMode.SQUARE,
    premultiply: ExprVarLike | None = None,
    multiply: ExprVarLike | None = None,
    clamp: bool = False,
) -> ComputedVar:
    """
    Convenience method wrapping [ExprOp.convolution][vsexprtools.ExprOp.convolution].

    Args:
        var: The variable used as the central value
            or elements proportional to the radius if mode is `Literal[ConvMode.TEMPORAL]`.
        matrix: A flat or 2D iterable representing the convolution weights.
        bias: A constant value to add to the result after convolution (default: None).
        divisor: If True, normalizes by the sum of weights; if False, skips division;
            Otherwise, divides by this value.
        saturate: If False, applies `abs()` to avoid negatives.
        mode: The convolution shape.
        premultiply: Optional scalar to multiply the result before normalization.
        multiply: Optional scalar to multiply the result at the end.
        clamp: If True, clamps the final result to [RangeMin, RangeMax].

    Returns:
        A `ComputedVar` representing the expression-based convolution.
    """
    convo, *_ = ExprOp.convolution(
        var, flatten(matrix), bias, divisor, saturate, mode, premultiply, multiply, clamp
    )
    return ComputedVar(convo.to_str())

cos

Cosine (radians) of x.

Source code
56
57
58
def cos(self, x: ExprVarLike) -> ComputedVar:
    """Cosine (radians) of x."""
    return ComputedVar([x, ExprOp.COS])

div

Performs division of two elements (x / y).

Source code
129
130
131
def div(self, x: ExprVarLike, y: ExprVarLike) -> ComputedVar:
    """Performs division of two elements (x / y)."""
    return ComputedVar([x, y, ExprOp.DIV])

eq

Performs x == y.

Source code
145
146
147
def eq(self, x: ExprVarLike, y: ExprVarLike) -> ComputedVar:
    """Performs x == y."""
    return ComputedVar([x, y, ExprOp.EQ])

exp

Exponential function (e^x).

Source code
36
37
38
def exp(self, x: ExprVarLike) -> ComputedVar:
    """Exponential function (e^x)."""
    return ComputedVar([x, ExprOp.EXP])

floor

floor(x: ExprVarLike) -> ComputedVar

Round down x to nearest integer.

Source code
88
89
90
def floor(self, x: ExprVarLike) -> ComputedVar:
    """Round down x to nearest integer."""
    return ComputedVar([x, ExprOp.FLOOR])

gt

Performs x > y.

Source code
137
138
139
def gt(self, x: ExprVarLike, y: ExprVarLike) -> ComputedVar:
    """Performs x > y."""
    return ComputedVar([x, y, ExprOp.GT])

gte

Performs x >= y.

Source code
149
150
151
def gte(self, x: ExprVarLike, y: ExprVarLike) -> ComputedVar:
    """Performs x >= y."""
    return ComputedVar([x, y, ExprOp.GTE])

lerp

Performs a linear interpolation of t between x and y.

Source code
197
198
199
def lerp(self, x: ExprVarLike, y: ExprVarLike, t: ExprVarLike) -> ComputedVar:
    """Performs a linear interpolation of t between x and y."""
    return ComputedVar([x, y, t, ExprOp.LERP])

log

Natural logarithm of x.

Source code
40
41
42
def log(self, x: ExprVarLike) -> ComputedVar:
    """Natural logarithm of x."""
    return ComputedVar([x, ExprOp.LOG])

lt

Performs x < y.

Source code
141
142
143
def lt(self, x: ExprVarLike, y: ExprVarLike) -> ComputedVar:
    """Performs x < y."""
    return ComputedVar([x, y, ExprOp.LT])

lte

Performs x <= y.

Source code
153
154
155
def lte(self, x: ExprVarLike, y: ExprVarLike) -> ComputedVar:
    """Performs x <= y."""
    return ComputedVar([x, y, ExprOp.LTE])

matrix

matrix(
    char: SupportsString | Collection[SupportsString],
    radius: int,
    mode: Literal[SQUARE, HORIZONTAL, VERTICAL, TEMPORAL],
    exclude: Iterable[tuple[int, int]] | None = None,
) -> list[LiteralVar]

Convenience method wrapping ExprOp.matrix.

Parameters:

  • char

    (SupportsString | Collection[SupportsString]) –

    The variable representing the central pixel(s).

  • radius

    (int) –

    The radius of the kernel in pixels (e.g., 1 for 3x3).

  • mode

    (Literal[SQUARE, HORIZONTAL, VERTICAL, TEMPORAL]) –

    The convolution mode. HV is not supported.

  • exclude

    (Iterable[tuple[int, int]] | None, default: None ) –

    Optional set of (x, y) coordinates to exclude from the matrix.

Returns:

Source code
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
def matrix(
    self,
    char: SupportsString | Collection[SupportsString],
    radius: int,
    mode: Literal[ConvMode.SQUARE, ConvMode.HORIZONTAL, ConvMode.VERTICAL, ConvMode.TEMPORAL],
    exclude: Iterable[tuple[int, int]] | None = None,
) -> list[LiteralVar]:
    """
    Convenience method wrapping [ExprOp.matrix][vsexprtools.ExprOp.matrix].

    Args:
        char: The variable representing the central pixel(s).
        radius: The radius of the kernel in pixels (e.g., 1 for 3x3).
        mode: The convolution mode. `HV` is not supported.
        exclude: Optional set of (x, y) coordinates to exclude from the matrix.

    Returns:
        A list of [LiteralVar][vsexprtools.inline.helpers.LiteralVar] instances
        representing the matrix of expressions.
    """
    matrix, *_ = ExprOp.matrix(char, radius, mode, exclude)

    return [LiteralVar(str(m)) for m in matrix]

max

Calculates the maximum of x and y.

Source code
109
110
111
def max(self, x: ExprVarLike, y: ExprVarLike) -> ComputedVar:
    """Calculates the maximum of x and y."""
    return ComputedVar([x, y, ExprOp.MAX])

min

Calculates the minimum of x and y.

Source code
113
114
115
def min(self, x: ExprVarLike, y: ExprVarLike) -> ComputedVar:
    """Calculates the minimum of x and y."""
    return ComputedVar([x, y, ExprOp.MIN])

mod

Performs x % y.

Source code
169
170
171
def mod(self, x: ExprVarLike, y: ExprVarLike) -> ComputedVar:
    """Performs x % y."""
    return ComputedVar([x, y, ExprOp.MOD])

mul

Performs multiplication of two elements (x * y).

Source code
125
126
127
def mul(self, x: ExprVarLike, y: ExprVarLike) -> ComputedVar:
    """Performs multiplication of two elements (x * y)."""
    return ComputedVar([x, y, ExprOp.MUL])

neg

Negation (multiply by -1) of x.

Source code
104
105
106
def neg(self, x: ExprVarLike) -> ComputedVar:
    """Negation (multiply by -1) of x."""
    return ComputedVar([x, ExprOp.NEG])

not_

Logical NOT of x.

Source code
76
77
78
def not_(self, x: ExprVarLike) -> ComputedVar:
    """Logical NOT of x."""
    return ComputedVar([x, ExprOp.NOT])

or_

Performs a logical OR.

Source code
161
162
163
def or_(self, x: ExprVarLike, y: ExprVarLike) -> ComputedVar:
    """Performs a logical OR."""
    return ComputedVar([x, y, ExprOp.OR])

polyval

polyval(x: ExprVarLike, *coeffs: ExprVarLike) -> ComputedVar

Evaluates a polynomial at x using Horner's method.

Source code
202
203
204
def polyval(self, x: ExprVarLike, *coeffs: ExprVarLike) -> ComputedVar:
    """Evaluates a polynomial at x using Horner's method."""
    return ComputedVar(ExprOp.polyval(x, *coeffs).to_str())

pow

Performs x to the power of y (x ** y).

Source code
133
134
135
def pow(self, x: ExprVarLike, y: ExprVarLike) -> ComputedVar:
    """Performs x to the power of y (x ** y)."""
    return ComputedVar([x, y, ExprOp.POW])

rel_pix

rel_pix(char: SupportsString, x: int, y: int) -> ComputedVar

Relative pixel access.

Source code
207
208
209
def rel_pix(self, char: SupportsString, x: int, y: int) -> ComputedVar:
    """Relative pixel access."""
    return ComputedVar(ExprOp.REL_PIX.format(char=char, x=x, y=y))

round

round(x: ExprVarLike) -> ComputedVar

Round x to nearest integer.

Source code
84
85
86
def round(self, x: ExprVarLike) -> ComputedVar:
    """Round x to nearest integer."""
    return ComputedVar([x, ExprOp.ROUND])

sgn

Sign function (-1, 0, or 1) of x.

Source code
100
101
102
def sgn(self, x: ExprVarLike) -> ComputedVar:
    """Sign function (-1, 0, or 1) of x."""
    return ComputedVar([x, ExprOp.SGN])

sin

Sine (radians) of x.

Source code
48
49
50
def sin(self, x: ExprVarLike) -> ComputedVar:
    """Sine (radians) of x."""
    return ComputedVar([x, ExprOp.SIN])

sqrt

Square root of x.

Source code
44
45
46
def sqrt(self, x: ExprVarLike) -> ComputedVar:
    """Square root of x."""
    return ComputedVar([x, ExprOp.SQRT])

sub

Performs subtraction of two elements (x - y).

Source code
121
122
123
def sub(self, x: ExprVarLike, y: ExprVarLike) -> ComputedVar:
    """Performs subtraction of two elements (x - y)."""
    return ComputedVar([x, y, ExprOp.SUB])

tan

Tangent (radians) of x.

Source code
64
65
66
def tan(self, x: ExprVarLike) -> ComputedVar:
    """Tangent (radians) of x."""
    return ComputedVar([x, ExprOp.TAN])

tern

tern(
    cond: ExprVarLike, if_true: ExprVarLike, if_false: ExprVarLike
) -> ComputedVar

Ternary operator (if cond then if_true else if_false).

Source code
186
187
188
def tern(self, cond: ExprVarLike, if_true: ExprVarLike, if_false: ExprVarLike) -> ComputedVar:
    """Ternary operator (if cond then if_true else if_false)."""
    return ComputedVar([cond, if_true, if_false, ExprOp.TERN])

trunc

trunc(x: ExprVarLike) -> ComputedVar

Truncate x to integer (toward zero).

Source code
80
81
82
def trunc(self, x: ExprVarLike) -> ComputedVar:
    """Truncate x to integer (toward zero)."""
    return ComputedVar([x, ExprOp.TRUNC])

xor

Performs a logical XOR.

Source code
165
166
167
def xor(self, x: ExprVarLike, y: ExprVarLike) -> ComputedVar:
    """Performs a logical XOR."""
    return ComputedVar([x, y, ExprOp.XOR])

Token

Bases: LiteralVar

An expression token wrapping ExprToken.

Initializes a new Token instance.

Parameters:

Methods:

  • __call__

    Returns a version of the token specific to a clip variable.

  • as_var

    Converts the expression variable to a ComputedVar.

  • to_str

    Returns the string representation of the expression variable.

Attributes:

Source code
817
818
819
820
821
822
823
824
def __init__(self, expr_token: ExprToken) -> None:
    """
    Initializes a new Token instance.

    Args:
        expr_token: Token to wrapped.
    """
    super().__init__(expr_token.value)

value instance-attribute

value = value

__call__

__call__(var: ClipVar) -> ComputedVar

Returns a version of the token specific to a clip variable.

Parameters:

Returns:

  • ComputedVar

    A ComputedVar with a var suffix for use in inline expressions.

Source code
826
827
828
829
830
831
832
833
834
835
836
def __call__(self, var: ClipVar) -> ComputedVar:
    """
    Returns a version of the token specific to a clip variable.

    Args:
        var: The ClipVar to use.

    Returns:
        A ComputedVar with a var suffix for use in inline expressions.
    """
    return ComputedVar(f"{self.value}_{var.char}")

as_var

as_var() -> ComputedVar

Converts the expression variable to a ComputedVar.

Returns:

Source code
464
465
466
467
468
469
470
471
472
473
def as_var(self) -> ComputedVar:
    """
    Converts the expression variable to a ComputedVar.

    Returns:
        A ComputedVar.
    """
    if isinstance(self, ComputedVar):
        return self
    return ComputedVar(self)

to_str

to_str(**kwargs: Any) -> str

Returns the string representation of the expression variable.

Parameters:

  • **kwargs

    (Any, default: {} ) –

    Additional keywords arguments.

Returns:

  • str

    The string representation of the expression variable.

Source code
440
441
442
443
444
445
446
447
448
449
450
def to_str(self, **kwargs: Any) -> str:
    """
    Returns the string representation of the expression variable.

    Args:
        **kwargs: Additional keywords arguments.

    Returns:
        The string representation of the expression variable.
    """
    return str(self)

Tokens

Bases: Singleton

A singleton class that defines the expression tokens used in inline_expr.

Attributes:

ChromaMax class-attribute instance-attribute

ChromaMax: Final[Token] = cast(Token, ...)

The maximum chroma value in limited range.

ChromaMin class-attribute instance-attribute

ChromaMin: Final[Token] = cast(Token, ...)

The minimum chroma value in limited range.

ChromaRangeInMax class-attribute instance-attribute

ChromaRangeInMax: Final[Token] = cast(Token, ...)

Like ChromaRangeMax, but adapts to input range_in.

ChromaRangeInMin class-attribute instance-attribute

ChromaRangeInMin: Final[Token] = cast(Token, ...)

Like ChromaRangeMin, but adapts to input range_in.

ChromaRangeMax class-attribute instance-attribute

ChromaRangeMax: Final[Token] = cast(Token, ...)

Maximum chroma value based on input clip's color range.

ChromaRangeMin class-attribute instance-attribute

ChromaRangeMin: Final[Token] = cast(Token, ...)

Minimum chroma value based on input clip's color range.

LumaMax class-attribute instance-attribute

LumaMax: Final[Token] = cast(Token, ...)

The maximum luma value in limited range.

LumaMin class-attribute instance-attribute

LumaMin: Final[Token] = cast(Token, ...)

The minimum luma value in limited range.

LumaRangeInMax class-attribute instance-attribute

LumaRangeInMax: Final[Token] = cast(Token, ...)

Like LumaRangeMax, but adapts to input range_in.

LumaRangeInMin class-attribute instance-attribute

LumaRangeInMin: Final[Token] = cast(Token, ...)

Like LumaRangeMin, but adapts to input range_in.

LumaRangeMax class-attribute instance-attribute

LumaRangeMax: Final[Token] = cast(Token, ...)

Maximum luma value based on input clip's color range.

LumaRangeMin class-attribute instance-attribute

LumaRangeMin: Final[Token] = cast(Token, ...)

Minimum luma value based on input clip's color range.

Neutral class-attribute instance-attribute

Neutral: Final[Token] = cast(Token, ...)

The neutral value (e.g. 128 for 8-bit limited, 0 for float).

RangeHalf class-attribute instance-attribute

RangeHalf: Final[Token] = cast(Token, ...)

Half of the full range (e.g. 128.0 for 8-bit full range).

RangeInMax class-attribute instance-attribute

RangeInMax: Final[Token] = cast(Token, ...)

Like RangeMax, but adapts to input range_in.

RangeInMin class-attribute instance-attribute

RangeInMin: Final[Token] = cast(Token, ...)

Like RangeMin, but adapts to input range_in parameter.

RangeMax class-attribute instance-attribute

RangeMax: Final[Token] = cast(Token, ...)

Maximum value in full range (chroma-aware).

RangeMin class-attribute instance-attribute

RangeMin: Final[Token] = cast(Token, ...)

Minimum value in full range (chroma-aware).

RangeSize class-attribute instance-attribute

RangeSize: Final[Token] = cast(Token, ...)

The size of the full range (e.g. 256 for 8-bit, 65536 for 16-bit).