Skip to content

Commit

Permalink
rewrite clamp_aa expr
Browse files Browse the repository at this point in the history
  • Loading branch information
emotion3459 committed Jan 29, 2025
1 parent 2e1eb7a commit 3167027
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions vsaa/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any, Literal

from vsexprtools import complexpr_available, norm_expr
from vsexprtools import norm_expr
from vskernels import Bilinear, Box, Catrom, NoScale, Scaler, ScalerT
from vsmasktools import EdgeDetect, EdgeDetectT, Prewitt, ScharrTCanny
from vsrgtools import MeanMode, bilateral, box_blur, unsharp_masked
from vstools import (
MISSING, CustomRuntimeError, CustomValueError, FormatsMismatchError, FunctionUtil, KwargsT, MissingT,
PlanesT, VSFunction, get_peak_value, get_y, plane, scale_mask, vs
PlanesT, VSFunction, get_peak_value, get_y, plane, scale_mask, vs, fallback
)

from .abstract import Antialiaser
Expand Down Expand Up @@ -104,6 +104,8 @@ def clamp_aa(
elif func.luma_only:
strong_aa = get_y(strong_aa)

ref = fallback(ref, func.work_clip)

if ref and func.luma_only:
ref = get_y(ref)

Expand All @@ -115,20 +117,10 @@ def clamp_aa(
if thr == 0:
clamped = MeanMode.MEDIAN(func.work_clip, weak_aa, strong_aa, planes=planes)
else:
if ref:
if complexpr_available:
expr = f'y z - ZD! y a - AD! ZD@ AD@ xor x ZD@ abs AD@ abs < a z {thr} + min z {thr} - max a ? ?'
else:
expr = f'y z - y a - xor x y z - abs y a - abs < a z {thr} + min z {thr} - max a ? ?'
else:
if complexpr_available:
expr = f'x y - XYD! x z - XZD! XYD@ XZD@ xor x XYD@ abs XZD@ abs < z y {thr} + min y {thr} - max z ? ?'
else:
expr = f'x y - x z - xor x x y - abs x z - abs < z y {thr} + min y {thr} - max z ? ?'

clamped = norm_expr(
[func.work_clip, ref, weak_aa, strong_aa] if ref else [func.work_clip, strong_aa, strong_aa],
expr, func.norm_planes
[func.work_clip, weak_aa, strong_aa, ref],
'x y - D1! x z - D2! xor a D1@ abs D2@ abs < z y {thr} - y {thr} + clip z ? ?',
thr=thr, planes=func.norm_planes
)

if mask:
Expand Down

0 comments on commit 3167027

Please sign in to comment.