Skip to content

Commit

Permalink
Update dithering methods (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
wiwaz authored Mar 12, 2024
1 parent d20e661 commit f27e074
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
6 changes: 2 additions & 4 deletions vsdenoise/bm3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from vstools import (
MISSING, ColorRange, ColorRangeT, Colorspace, ConstantFormatVideoNode, CustomIndexError, CustomRuntimeError,
CustomStrEnum, CustomValueError, DitherType, FuncExceptT, FunctionUtil, KwargsT, Matrix, MatrixT, MissingT, PlanesT,
CustomStrEnum, CustomValueError, FuncExceptT, FunctionUtil, KwargsT, Matrix, MatrixT, MissingT, PlanesT,
Self, SingleOrArr, check_variable, core, depth, get_video_format, get_y, join, normalize_seq, vs, vs_object
)

Expand Down Expand Up @@ -91,13 +91,11 @@ def prepare_clip(self, clip: vs.VideoNode | None) -> vs.VideoNode | None:
def post_processing(self, clip: vs.VideoNode) -> vs.VideoNode:
assert clip.format

dither = DitherType.ERROR_DIFFUSION if DitherType.should_dither(self.clip.format, clip) else DitherType.NONE

if self.clip.format.color_family is vs.YUV:
if clip.format.color_family is vs.GRAY:
clip = join(depth(clip, self.clip), self.clip)
else:
clip = self.csp.to_yuv(clip, self.fp32, format=self.clip.format, matrix=self.matrix, dither_type=dither)
clip = self.csp.to_yuv(clip, self.fp32, format=self.clip.format, matrix=self.matrix)
elif self.clip.format.color_family is vs.RGB:
clip = self.csp.to_rgb(clip, self.fp32)

Expand Down
4 changes: 2 additions & 2 deletions vsdenoise/deblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from vsmasktools import FDoG, GenericMaskT, adg_mask, normalize_mask
from vsrgtools import gauss_blur
from vstools import (
ColorRange, CustomStrEnum, DependencyNotFoundError, DitherType, FrameRangeN, FrameRangesN, InvalidColorFamilyError,
ColorRange, CustomStrEnum, DependencyNotFoundError, FrameRangeN, FrameRangesN, InvalidColorFamilyError,
KwargsT, LengthMismatchError, Matrix, MatrixT, UnsupportedVideoFormatError, check_variable, core, depth, fallback,
get_depth, get_nvidia_version, get_y, join, replace_ranges, vs
)
Expand Down Expand Up @@ -115,7 +115,7 @@ def _norm_str_clip(str_clip: vs.VideoNode) -> vs.VideoNode:

targ_format = clip.format.replace(subsampling_w=0, subsampling_h=0) if i444 else clip.format

clip_upsample = depth(clip, 16 if fp16 else 32, vs.FLOAT, dither_type=DitherType.ERROR_DIFFUSION)
clip_upsample = depth(clip, 16 if fp16 else 32, vs.FLOAT)

if is_rgb or is_gray:
clip_rgb = clip_upsample
Expand Down
6 changes: 2 additions & 4 deletions vsdenoise/prefilters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from vsmasktools import retinex
from vsrgtools import bilateral, blur, gauss_blur, min_blur, replace_low_frequencies
from vstools import (
MISSING, ColorRange, ConvMode, CustomEnum, CustomIntEnum, CustomRuntimeError, DitherType, MissingT, PlanesT,
MISSING, ColorRange, ConvMode, CustomEnum, CustomIntEnum, CustomRuntimeError, MissingT, PlanesT,
SingleOrArr, SingleOrArrOpt, check_variable, clamp, core, depth, disallow_variable_format,
disallow_variable_resolution, get_depth, get_neutral_value, get_peak_value, get_y, join, normalize_planes,
normalize_seq, scale_8bit, scale_value, split, vs
Expand Down Expand Up @@ -884,9 +884,7 @@ def prefilter_to_full_range(pref: vs.VideoNode, range_conversion: float, planes:
elif range_conversion > 0.0:
pref_full = retinex(work_clip, upper_thr=range_conversion, fast=False)
else:
pref_full = depth(
work_clip, bits, range_out=ColorRange.FULL, range_in=ColorRange.LIMITED, dither_type=DitherType.NONE
)
pref_full = depth(work_clip, bits, range_out=ColorRange.FULL, range_in=ColorRange.LIMITED)

if chroma:
return join(pref_full, *chroma, family=pref.format.color_family)
Expand Down

0 comments on commit f27e074

Please sign in to comment.