Skip to content

Commit

Permalink
Rewrite placebo.Deband wrapper to fix graining logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Setsugennoao committed Oct 15, 2023
1 parent 3b211b7 commit c2d314b
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions vsdeband/placebo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import Iterable

from vstools import CustomIntEnum, KwargsT, check_variable, fallback, inject_self, join, normalize_seq, split, vs

Expand Down Expand Up @@ -111,12 +112,34 @@ def deband( # type: ignore[override]
grain = normalize_seq(fallback(self.grain, grain)) # type: ignore[arg-type]
dither = fallback(self.dither, dither)

debs = [
p.placebo.Deband(1, iterations, thr, radius, gra * (1 << 5) * 0.8, **dither.placebo_args)
for p, thr, gra in zip(split(clip), thr, grain)
]
def _placebo(clip: vs.VideoNode, thr: float, grain: float, planes: Iterable[int]) -> vs.VideoNode:
plane = 0
for p in planes:
plane |= pow(2, p)
return clip.placebo.Deband(plane, iterations, thr, radius, grain * (1 << 5) * 0.8, **dither.placebo_args)

if len(debs) == 1:
return debs[0]
set_grn = set(grain)

return join(debs, clip.format.color_family)
if set_grn == {0} or clip.format.num_planes == 1:
def_grain = grain[0] if clip.format.num_planes == 1 else 0

debs = [_placebo(p, thr, def_grain, [0]) for p, thr in zip(split(clip), thr)]

if len(debs) == 1:
return debs[0]

return join(debs, clip.format.color_family)

plane_map = {
tuple(i for i in range(clip.format.num_planes) if grain[i] == x): x for x in set_grn - {0}
}

debanded = clip
for planes, grain_val in plane_map.items():
if len(set(thr[p] for p in planes)) == 1:
debanded = _placebo(debanded, thr[planes[0]], grain_val, planes)
else:
for p in planes:
debanded = _placebo(debanded, thr[p], grain_val, planes)

return debanded

0 comments on commit c2d314b

Please sign in to comment.