Skip to content

abstract

Antialiaser dataclass

Antialiaser(
    *,
    field: int = 0,
    drop_fields: bool = True,
    transpose_first: bool = False,
    shifter: KernelT | None = None,
    scaler: ScalerT | None = None,
    merge_func: Callable[[VideoNode, VideoNode], VideoNode] = Merge
)

Bases: DoubleRater, SuperSampler

drop_fields class-attribute instance-attribute

drop_fields: bool = field(default=True, kw_only=True)

field class-attribute instance-attribute

field: int = field(default=0, kw_only=True)

merge_func class-attribute instance-attribute

merge_func: Callable[[VideoNode, VideoNode], VideoNode] = Merge

scaler class-attribute instance-attribute

scaler: ScalerT | None = field(default=None, kw_only=True)

shifter class-attribute instance-attribute

shifter: KernelT | None = field(default=None, kw_only=True)

transpose_first class-attribute instance-attribute

transpose_first: bool = field(default=False, kw_only=True)

aa

aa(clip: VideoNode, dir: AADirection = BOTH, /, **kwargs: Any) -> VideoNode
aa(
    clip: VideoNode, y: bool = True, x: bool = True, /, **kwargs: Any
) -> VideoNode
aa(
    clip: VideoNode,
    y_or_dir: bool | AADirection = True,
    x: bool = True,
    /,
    **kwargs: Any,
) -> VideoNode

Single rate aa with this antialiaser

Source code
275
276
277
278
279
280
281
282
283
284
285
286
287
288
@inject_self.init_kwargs.clean
def aa(
    self, clip: vs.VideoNode, y_or_dir: bool | AADirection = True, x: bool = True, /, **kwargs: Any
) -> vs.VideoNode:
    """Single rate aa with this antialiaser"""

    if isinstance(y_or_dir, AADirection):
        y, x = y_or_dir.to_yx()
    else:
        y = y_or_dir

    clip = self.preprocess_clip(clip)

    return SingleRater._aa(self, clip, y, x, **kwargs)

copy

copy(**kwargs: Any) -> T
Source code
71
72
73
@inject_self
def copy(self: T, **kwargs: Any) -> T:
    return replace(self, **kwargs)

draa

draa(clip: VideoNode, dir: AADirection = BOTH, /, **kwargs: Any) -> VideoNode
draa(
    clip: VideoNode, y: bool = True, x: bool = True, /, **kwargs: Any
) -> VideoNode
draa(
    clip: VideoNode,
    y_or_dir: bool | AADirection = True,
    x: bool = True,
    /,
    **kwargs: Any,
) -> VideoNode

Double rate aa with this antialiaser

Source code
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
@inject_self.init_kwargs.clean
def draa(
    self, clip: vs.VideoNode, y_or_dir: bool | AADirection = True, x: bool = True, /, **kwargs: Any
) -> vs.VideoNode:
    """Double rate aa with this antialiaser"""

    if isinstance(y_or_dir, AADirection):
        y, x = y_or_dir.to_yx()
    else:
        y = y_or_dir

    clip = self.preprocess_clip(clip)

    kwargs.pop('field', None)

    return DoubleRater._aa(self, clip, y, x, **kwargs)

get_aa_args

get_aa_args(clip: VideoNode, **kwargs: Any) -> dict[str, Any]
Source code
56
57
def get_aa_args(self, clip: vs.VideoNode, **kwargs: Any) -> dict[str, Any]:
    return {}

get_sr_args

get_sr_args(clip: VideoNode, **kwargs: Any) -> dict[str, Any]
Source code
177
178
def get_sr_args(self, clip: vs.VideoNode, **kwargs: Any) -> dict[str, Any]:
    return {}

get_ss_args

get_ss_args(clip: VideoNode, **kwargs: Any) -> dict[str, Any]
Source code
85
86
def get_ss_args(self, clip: vs.VideoNode, **kwargs: Any) -> dict[str, Any]:
    return {}

interpolate

interpolate(clip: VideoNode, double_y: bool, **kwargs: Any) -> VideoNode
Source code
35
36
def interpolate(self, clip: vs.VideoNode, double_y: bool, **kwargs: Any) -> vs.VideoNode:
    raise NotImplementedError

preprocess_clip

preprocess_clip(clip: VideoNode) -> VideoNode
Source code
53
54
def preprocess_clip(self, clip: vs.VideoNode) -> vs.VideoNode:
    return clip

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[float, float] = (0, 0),
    **kwargs: Any
) -> VideoNode

Scale with this antialiaser

Source code
255
256
257
258
259
260
261
262
@inject_self
def scale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[float, float] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
    """Scale with this antialiaser"""
    width, height = Scaler._wh_norm(clip, width, height)
    return SuperSampler.scale(self, clip, width, height, shift, **kwargs)

shift_interpolate

shift_interpolate(
    clip: VideoNode, inter: VideoNode, double_y: bool, **kwargs: Any
) -> VideoNode
Source code
59
60
61
62
63
64
65
66
67
68
69
def shift_interpolate(
    self, clip: vs.VideoNode, inter: vs.VideoNode, double_y: bool, **kwargs: Any
) -> vs.VideoNode:
    if not double_y and not self.drop_fields:
        shift = (self._shift * int(not self.field), 0)

        inter = (self._scaler if self._scaler else self._shifter).scale(inter, clip.width, clip.height, shift)

        return self._post_interpolate(clip, inter, double_y, **kwargs)

    return inter

DoubleRater dataclass

DoubleRater(
    *,
    field: int = 0,
    drop_fields: bool = True,
    transpose_first: bool = False,
    shifter: KernelT | None = None,
    scaler: ScalerT | None = None,
    merge_func: Callable[[VideoNode, VideoNode], VideoNode] = Merge
)

Bases: SingleRater

drop_fields class-attribute instance-attribute

drop_fields: bool = field(default=True, kw_only=True)

field class-attribute instance-attribute

field: int = field(default=0, kw_only=True)

merge_func class-attribute instance-attribute

merge_func: Callable[[VideoNode, VideoNode], VideoNode] = Merge

scaler class-attribute instance-attribute

scaler: ScalerT | None = field(default=None, kw_only=True)

shifter class-attribute instance-attribute

shifter: KernelT | None = field(default=None, kw_only=True)

transpose_first class-attribute instance-attribute

transpose_first: bool = field(default=False, kw_only=True)

aa

aa(clip: VideoNode, dir: AADirection = BOTH, /, **kwargs: Any) -> VideoNode
aa(
    clip: VideoNode, y: bool = True, x: bool = True, /, **kwargs: Any
) -> VideoNode
aa(
    clip: VideoNode,
    y_or_dir: bool | AADirection = True,
    x: bool = True,
    /,
    **kwargs: Any,
) -> VideoNode
Source code
190
191
192
193
194
195
196
197
198
199
200
201
@inject_self.init_kwargs.clean
def aa(
    self, clip: vs.VideoNode, y_or_dir: bool | AADirection = True, x: bool = True, /, **kwargs: Any
) -> vs.VideoNode:
    if isinstance(y_or_dir, AADirection):
        y, x = y_or_dir.to_yx()
    else:
        y = y_or_dir

    clip = self.preprocess_clip(clip)

    return self._aa(clip, y, x, **kwargs)

copy

copy(**kwargs: Any) -> T
Source code
71
72
73
@inject_self
def copy(self: T, **kwargs: Any) -> T:
    return replace(self, **kwargs)

get_aa_args

get_aa_args(clip: VideoNode, **kwargs: Any) -> dict[str, Any]
Source code
56
57
def get_aa_args(self, clip: vs.VideoNode, **kwargs: Any) -> dict[str, Any]:
    return {}

get_sr_args

get_sr_args(clip: VideoNode, **kwargs: Any) -> dict[str, Any]
Source code
177
178
def get_sr_args(self, clip: vs.VideoNode, **kwargs: Any) -> dict[str, Any]:
    return {}

interpolate

interpolate(clip: VideoNode, double_y: bool, **kwargs: Any) -> VideoNode
Source code
35
36
def interpolate(self, clip: vs.VideoNode, double_y: bool, **kwargs: Any) -> vs.VideoNode:
    raise NotImplementedError

preprocess_clip

preprocess_clip(clip: VideoNode) -> VideoNode
Source code
53
54
def preprocess_clip(self, clip: vs.VideoNode) -> vs.VideoNode:
    return clip

shift_interpolate

shift_interpolate(
    clip: VideoNode, inter: VideoNode, double_y: bool, **kwargs: Any
) -> VideoNode
Source code
59
60
61
62
63
64
65
66
67
68
69
def shift_interpolate(
    self, clip: vs.VideoNode, inter: vs.VideoNode, double_y: bool, **kwargs: Any
) -> vs.VideoNode:
    if not double_y and not self.drop_fields:
        shift = (self._shift * int(not self.field), 0)

        inter = (self._scaler if self._scaler else self._shifter).scale(inter, clip.width, clip.height, shift)

        return self._post_interpolate(clip, inter, double_y, **kwargs)

    return inter

SingleRater dataclass

SingleRater(
    *,
    field: int = 0,
    drop_fields: bool = True,
    transpose_first: bool = False,
    shifter: KernelT | None = None,
    scaler: ScalerT | None = None
)

Bases: _Antialiaser

drop_fields class-attribute instance-attribute

drop_fields: bool = field(default=True, kw_only=True)

field class-attribute instance-attribute

field: int = field(default=0, kw_only=True)

scaler class-attribute instance-attribute

scaler: ScalerT | None = field(default=None, kw_only=True)

shifter class-attribute instance-attribute

shifter: KernelT | None = field(default=None, kw_only=True)

transpose_first class-attribute instance-attribute

transpose_first: bool = field(default=False, kw_only=True)

aa

aa(clip: VideoNode, dir: AADirection = BOTH, /, **kwargs: Any) -> VideoNode
aa(
    clip: VideoNode, y: bool = True, x: bool = True, /, **kwargs: Any
) -> VideoNode
aa(
    clip: VideoNode,
    y_or_dir: bool | AADirection = True,
    x: bool = True,
    /,
    **kwargs: Any,
) -> VideoNode
Source code
190
191
192
193
194
195
196
197
198
199
200
201
@inject_self.init_kwargs.clean
def aa(
    self, clip: vs.VideoNode, y_or_dir: bool | AADirection = True, x: bool = True, /, **kwargs: Any
) -> vs.VideoNode:
    if isinstance(y_or_dir, AADirection):
        y, x = y_or_dir.to_yx()
    else:
        y = y_or_dir

    clip = self.preprocess_clip(clip)

    return self._aa(clip, y, x, **kwargs)

copy

copy(**kwargs: Any) -> T
Source code
71
72
73
@inject_self
def copy(self: T, **kwargs: Any) -> T:
    return replace(self, **kwargs)

get_aa_args

get_aa_args(clip: VideoNode, **kwargs: Any) -> dict[str, Any]
Source code
56
57
def get_aa_args(self, clip: vs.VideoNode, **kwargs: Any) -> dict[str, Any]:
    return {}

get_sr_args

get_sr_args(clip: VideoNode, **kwargs: Any) -> dict[str, Any]
Source code
177
178
def get_sr_args(self, clip: vs.VideoNode, **kwargs: Any) -> dict[str, Any]:
    return {}

interpolate

interpolate(clip: VideoNode, double_y: bool, **kwargs: Any) -> VideoNode
Source code
35
36
def interpolate(self, clip: vs.VideoNode, double_y: bool, **kwargs: Any) -> vs.VideoNode:
    raise NotImplementedError

preprocess_clip

preprocess_clip(clip: VideoNode) -> VideoNode
Source code
53
54
def preprocess_clip(self, clip: vs.VideoNode) -> vs.VideoNode:
    return clip

shift_interpolate

shift_interpolate(
    clip: VideoNode, inter: VideoNode, double_y: bool, **kwargs: Any
) -> VideoNode
Source code
59
60
61
62
63
64
65
66
67
68
69
def shift_interpolate(
    self, clip: vs.VideoNode, inter: vs.VideoNode, double_y: bool, **kwargs: Any
) -> vs.VideoNode:
    if not double_y and not self.drop_fields:
        shift = (self._shift * int(not self.field), 0)

        inter = (self._scaler if self._scaler else self._shifter).scale(inter, clip.width, clip.height, shift)

        return self._post_interpolate(clip, inter, double_y, **kwargs)

    return inter

SuperSampler dataclass

SuperSampler(
    *,
    field: int = 0,
    drop_fields: bool = True,
    transpose_first: bool = False,
    shifter: KernelT | None = None,
    scaler: ScalerT | None = None
)

Bases: _Antialiaser, Scaler

drop_fields class-attribute instance-attribute

drop_fields: bool = field(default=True, kw_only=True)

field class-attribute instance-attribute

field: int = field(default=0, kw_only=True)

scaler class-attribute instance-attribute

scaler: ScalerT | None = field(default=None, kw_only=True)

shifter class-attribute instance-attribute

shifter: KernelT | None = field(default=None, kw_only=True)

transpose_first class-attribute instance-attribute

transpose_first: bool = field(default=False, kw_only=True)

copy

copy(**kwargs: Any) -> T
Source code
71
72
73
@inject_self
def copy(self: T, **kwargs: Any) -> T:
    return replace(self, **kwargs)

get_aa_args

get_aa_args(clip: VideoNode, **kwargs: Any) -> dict[str, Any]
Source code
56
57
def get_aa_args(self, clip: vs.VideoNode, **kwargs: Any) -> dict[str, Any]:
    return {}

get_ss_args

get_ss_args(clip: VideoNode, **kwargs: Any) -> dict[str, Any]
Source code
85
86
def get_ss_args(self, clip: vs.VideoNode, **kwargs: Any) -> dict[str, Any]:
    return {}

interpolate

interpolate(clip: VideoNode, double_y: bool, **kwargs: Any) -> VideoNode
Source code
35
36
def interpolate(self, clip: vs.VideoNode, double_y: bool, **kwargs: Any) -> vs.VideoNode:
    raise NotImplementedError

preprocess_clip

preprocess_clip(clip: VideoNode) -> VideoNode
Source code
53
54
def preprocess_clip(self, clip: vs.VideoNode) -> vs.VideoNode:
    return clip

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[float, float] = (0, 0),
    **kwargs: Any
) -> VideoNode
Source code
 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
161
162
163
164
165
166
167
168
169
170
171
172
173
@inject_self
def scale(  # type: ignore[override]
    self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
    shift: tuple[float, float] = (0, 0), **kwargs: Any
) -> vs.VideoNode:

    if FieldBased.from_video(clip).is_inter:
        raise UnsupportedFieldBasedError('Only progressive video is supported!', self.scale)

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

    assert clip.format and clip.width and clip.height

    if (clip.width, clip.height) == (width, height):
        return clip

    kwargs = self.get_aa_args(clip, **kwargs) | self.get_ss_args(clip, **kwargs) | kwargs

    divw, divh = (ceil(size) for size in (width / clip.width, height / clip.height))

    mult_x, mult_y = (int(log2(divs)) for divs in (divw, divh))

    cdivw, cdivh = 1 << clip.format.subsampling_w, 1 << clip.format.subsampling_h

    upscaled = clip

    def _transpose(before: bool, is_width: int, y: int, x: int) -> None:
        nonlocal upscaled

        before = self.transpose_first if before else not self.transpose_first

        if ((before or not y) if is_width else (before and x)):
            upscaled = upscaled.std.Transpose()

    for (y, x) in zip_longest([True] * mult_y, [True] * mult_x, fillvalue=False):
        if isinstance(self, _FullInterpolate) and self.is_full_interpolate_enabled(x, y):
            upscaled = self.full_interpolate(upscaled, y, x, **kwargs)
        else:
            for isx, val in enumerate([y, x]):
                if val:
                    _transpose(True, isx, y, x)

                    upscaled = self.interpolate(upscaled, True, **kwargs)

                    _transpose(False, isx, y, x)

        topshift = leftshift = cleftshift = ctopshift = 0.0

        if y and self._shift:
            topshift = ctopshift = self._shift

            if cdivw == 2 and cdivh == 2:
                ctopshift -= 0.125
            elif cdivw == 1 and cdivh == 2:
                ctopshift += 0.125

        cresshift = 0.0

        if x and self._shift:
            leftshift = cleftshift = self._shift

            if cdivw in {4, 2} and cdivh in {4, 2, 1}:
                cleftshift = self._shift + 0.5

                if cdivw == 4 and cdivh == 1:
                    cresshift = 0.125 * 1
                elif cdivw == 2 and cdivh == 2:
                    cresshift = 0.125 * 2
                elif cdivw == 2 and cdivh == 1:
                    cresshift = 0.125 * 3

                cleftshift -= cresshift

        if isinstance(self._shifter, NoShift):
            if upscaled.format.subsampling_h or upscaled.format.subsampling_w:
                upscaled = Catrom.shift(upscaled, 0, [0, cleftshift + cresshift])  # type: ignore
        else:
            upscaled = self._shifter.shift(
                upscaled, [topshift, ctopshift], [leftshift, cleftshift]
            )

    if self._scaler:
        return self._scaler.scale(upscaled, width, height, shift)

    return self._shifter.scale(upscaled, width, height, shift)

shift_interpolate

shift_interpolate(
    clip: VideoNode, inter: VideoNode, double_y: bool, **kwargs: Any
) -> VideoNode
Source code
59
60
61
62
63
64
65
66
67
68
69
def shift_interpolate(
    self, clip: vs.VideoNode, inter: vs.VideoNode, double_y: bool, **kwargs: Any
) -> vs.VideoNode:
    if not double_y and not self.drop_fields:
        shift = (self._shift * int(not self.field), 0)

        inter = (self._scaler if self._scaler else self._shifter).scale(inter, clip.width, clip.height, shift)

        return self._post_interpolate(clip, inter, double_y, **kwargs)

    return inter