Skip to content

Commit

Permalink
based_aa: remove pmask (#25)
Browse files Browse the repository at this point in the history
* based_aa: remove pmask

* Remove unused imports
  • Loading branch information
emotion3459 authored Sep 9, 2024
1 parent 5c31176 commit c9c46eb
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions vsaa/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any, Literal

from vsexprtools import ExprOp, complexpr_available, norm_expr
from vsexprtools import complexpr_available, norm_expr
from vskernels import Catrom, NoScale, Scaler, ScalerT, Bilinear
from vsmasktools import EdgeDetect, EdgeDetectT, Morpho, Prewitt, ScharrTCanny
from vsmasktools import EdgeDetect, EdgeDetectT, Prewitt, ScharrTCanny
from vsrgtools import RepairMode, box_blur, contrasharpening_median, median_clips, repair, unsharp_masked
from vstools import (
MISSING, CustomOverflowError, CustomRuntimeError, CustomValueError, FunctionUtil, MissingT, PlanesT, VSFunction,
MISSING, CustomOverflowError, CustomRuntimeError, FunctionUtil, MissingT, PlanesT, VSFunction,
check_ref_clip, get_h, get_peak_value, get_w, get_y, join, normalize_planes, plane, scale_8bit, scale_value, split,
vs, padder
vs
)

from .abstract import Antialiaser, SingleRater
Expand Down Expand Up @@ -322,7 +322,7 @@ def based_aa(
downscaler: ScalerT = Catrom,
supersampler: ScalerT | FSRCNNXShaderT | ShaderFile | Path | Literal[False] = ArtCNN.C16F64,
antialiaser: Antialiaser = Eedi3(0.125, 0.25, vthresh0=12, vthresh1=24, field=1, sclip_aa=None),
prefilter: Prefilter | vs.VideoNode = Prefilter.NONE, show_mask: bool | int = False, planes: PlanesT = 0,
prefilter: Prefilter | vs.VideoNode = Prefilter.NONE, show_mask: bool = False, planes: PlanesT = 0,
**kwargs: Any
) -> vs.VideoNode:
...
Expand All @@ -333,7 +333,7 @@ def based_aa(
downscaler: ScalerT = Catrom,
supersampler: ScalerT | FSRCNNXShaderT | ShaderFile | Path | Literal[False] | MissingT = MISSING,
antialiaser: Antialiaser = Eedi3(0.125, 0.25, vthresh0=12, vthresh1=24, field=1, sclip_aa=None),
prefilter: Prefilter | vs.VideoNode | MissingT = MISSING, show_mask: bool | int = False, planes: PlanesT = 0,
prefilter: Prefilter | vs.VideoNode | MissingT = MISSING, show_mask: bool = False, planes: PlanesT = 0,
**kwargs: Any
) -> vs.VideoNode:
try:
Expand Down Expand Up @@ -396,7 +396,7 @@ def based_aa(
if not func.luma_only:
lmask = Catrom.resample(join(lmask, lmask, lmask), work_clip)

if show_mask == 1:
if show_mask:
return lmask

supersampler = Scaler.ensure_obj(supersampler, based_aa)
Expand All @@ -410,24 +410,10 @@ def based_aa(
aa = antialiaser.interpolate(ss, False, sclip=ss, mclip=mclip_up).std.Transpose()
aa = antialiaser.interpolate(aa, False, sclip=aa, mclip=mclip_up.std.Transpose()).std.Transpose()

pmask = norm_expr([ss, aa], 'x y = 0 range_size ?')
pmask = padder.COLOR(pmask.std.Crop(2, 2, 2, 2), 2, 2, 2, 2)
pmask = resize_aa_mask(pmask, work_clip.width, work_clip.height)
pmask = Morpho.maximum(norm_expr(pmask, 'x range_size 0 ?'), iterations=3)

lpmask = ExprOp.MIN(lmask, pmask)

if show_mask == 2:
return pmask
elif show_mask == 3:
return lpmask
elif show_mask:
raise CustomValueError('Wrong show_mask value! It can be one of 1 (True), 2, 3', based_aa)

aa = downscaler.scale(aa, work_clip.width, work_clip.height)
no_aa = downscaler.scale(ss, work_clip.width, work_clip.height)

aa_merge = norm_expr([work_clip, aa, no_aa], "y z = x y ?")
aa_merge = work_clip.std.MaskedMerge(aa_merge, lpmask)
aa_merge = work_clip.std.MaskedMerge(aa_merge, lmask)

return func.return_clip(aa_merge)

0 comments on commit c9c46eb

Please sign in to comment.