From 6d830e65414bfcfb41d46aa1832f1d05fed8da9c Mon Sep 17 00:00:00 2001 From: Setsugennoao <41454651+Setsugennoao@users.noreply.github.com> Date: Mon, 5 Feb 2024 22:25:57 +0100 Subject: [PATCH] Add GrainPP.NormBrightness --- vsdeband/noise.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/vsdeband/noise.py b/vsdeband/noise.py index 8a17f10..9a78d6e 100644 --- a/vsdeband/noise.py +++ b/vsdeband/noise.py @@ -61,6 +61,19 @@ class GrainPP(_gpp): def Bump(cls, strength: float = 0.1) -> GrainPP: return cls('x[-1,1] x - {strength} * x +', KwargsT(strength=strength + 1.0)) + @classmethod + def NormBrightness(cls) -> ResolverTwoClipsArgs: + def _resolve(grained: vs.VideoNode) -> vs.VideoNode: + for i in range(grained.format.num_planes): + grained = grained.std.PlaneStats(plane=i, prop=f'PS{i}') + + if get_sample_type(grained) is vs.FLOAT: + return norm_expr(grained, 'x x.PS{plane_idx}Average -') + + return norm_expr(grained, 'x range_diff range_size / x.PS{plane_idx}Average / *') + + return _resolve + FadeLimits = tuple[int | Iterable[int] | None, int | Iterable[int] | None] GrainPostProcessT = ResolverOneClipArgs | ResolverTwoClipsArgs | str | GrainPP | GrainPP.Resolver