Skip to content

Commit

Permalink
Always dither up/down manually with descale
Browse files Browse the repository at this point in the history
  • Loading branch information
Setsugennoao committed Nov 8, 2023
1 parent 436e164 commit 960751b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
16 changes: 10 additions & 6 deletions vskernels/kernels/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from vstools import (
CustomIndexError, CustomValueError, FieldBased, FuncExceptT, GenericVSFunction, HoldsVideoFormatT, Matrix, MatrixT,
T, VideoFormatT, check_correct_subsampling, check_variable_resolution, core, get_subclasses, get_video_format,
inject_self, vs, vs_object
T, VideoFormatT, check_correct_subsampling, check_variable_resolution, core, depth, expect_bits, get_subclasses,
get_video_format, inject_self, vs, vs_object
)

from ..exceptions import UnknownDescalerError, UnknownKernelError, UnknownScalerError
Expand Down Expand Up @@ -130,12 +130,14 @@ def descale( # type: ignore[override]

field_based = FieldBased.from_video(clip)

clip, bits = expect_bits(clip, 32)

de_kwargs = self.get_descale_args(clip, shift, width, height // (1 + field_based.is_inter), **kwargs)

if field_based.is_inter:
if height % 2:
raise CustomIndexError('You can\'t descale to odd resolution when crossconverted!', self.descale)

de_kwargs = self.get_descale_args(clip, shift, width, height // 2, **kwargs)

top_shift, field_shift = de_kwargs.get('src_top'), 0.125 * height / clip.height

fields = clip.std.SeparateFields(field_based.is_tff)
Expand All @@ -145,9 +147,11 @@ def descale( # type: ignore[override]
for offset, mult in [(0, 1), (1, -1)]
])

return interleaved.std.DoubleWeave(field_based.is_tff)[::2]
descaled = interleaved.std.DoubleWeave(field_based.is_tff)[::2]
else:
descaled = self.descale_function(clip, **de_kwargs)

return self.descale_function(clip, **self.get_descale_args(clip, shift, width, height, **kwargs))
return depth(descaled, bits)

@classmethod
def from_param(
Expand Down
8 changes: 4 additions & 4 deletions vskernels/kernels/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import Any, overload

from vstools import HoldsVideoFormatT, MatrixT, VideoFormatT, core, get_video_format, inject_self, vs
from vstools import HoldsVideoFormatT, MatrixT, VideoFormatT, core, depth, get_video_format, inject_self, vs

from .abstract import Kernel

Expand Down Expand Up @@ -54,9 +54,9 @@ def descale( # type: ignore[override]
:rtype: ``VideoNode``
"""
return core.descale.Debicubic(
clip, width, height, b=self.b, c=self.c, src_top=shift[0], src_left=shift[1], **kwargs
)
return depth(core.descale.Debicubic(
depth(clip, 32), width, height, b=self.b, c=self.c, src_top=shift[0], src_left=shift[1], **kwargs
), clip)

@inject_self.cached
def resample( # type: ignore[override]
Expand Down

0 comments on commit 960751b

Please sign in to comment.