Skip to content

Commit

Permalink
Merge branch 'master' into custom-kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
Setsugennoao committed Jul 9, 2024
2 parents 7200f55 + c53b468 commit e89f98e
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 85 deletions.
15 changes: 7 additions & 8 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@ name: Build documentation
on:
push:
paths:
- "**.py"
- "**.rst"
- '**.py'
- '**.rst'
pull_request:
branches:
- master
paths:
- "**.py"
- "**.rst"

- '**.py'
- '**.rst'

jobs:
docs:
runs-on: ubuntu-latest
strategy:
matrix:
versions:
- 65
- 68
python-version:
- "3.11"
- '3.12'
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -36,4 +35,4 @@ jobs:
pip install -r requirements-dev.txt
pip install -r docs/requirements.txt
- name: Building sphinx
run: python3 setup.py build_sphinx -W --keep-going
run: python3 setup.py build_sphinx -W --keep-going
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ jobs:
strategy:
matrix:
versions:
- 65
- 68
python-version:
- "3.11"
- '3.12'

steps:
- uses: actions/checkout@v2
Expand All @@ -28,4 +28,4 @@ jobs:
run: flake8 vskernels
- name: Running mypy
if: steps.dependencies.outcome == 'success'
run: mypy vskernels
run: mypy vskernels
2 changes: 1 addition & 1 deletion .github/workflows/pypipublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Prep Python
uses: actions/setup-python@v2
with:
python-version: '3.11'
python-version: '3.12'

- name: Install build tools
run: |
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ idna==3.3
imagesize==1.3.0
Jinja2==3.1.2
MarkupSafe==2.1.1
packaging==21.3
packaging>=24.0
Pygments==2.12.0
pyparsing==3.0.8
pytz==2022.1
Expand Down
12 changes: 6 additions & 6 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
flake8==4.0.1
mypy==0.971
mypy-extensions==0.4.3
packaging==21.3
pycodestyle==2.8.0
typing-extensions>=4.2.0
flake8>=7.0.0
mypy>=1.10.0
mypy-extensions>=1.0.0
packaging>=24.0
pycodestyle>=2.11.1
typing-extensions>=4.11.0
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VapourSynth>=65
vstools>=3.0.0
VapourSynth>=68
vstools>=3.2.0
4 changes: 0 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ statistics = True


[mypy]
mypy_path = ./stubs/

python_version = 3.10

ignore_missing_imports = False

disallow_any_generics = True
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
'Contact': 'https://discord.gg/XTpc6Fa9eB',
},
install_requires=requirements,
python_requires='>=3.11',
python_requires='>=3.12',
packages=[
package_name, f'{package_name}.kernels'
],
Expand Down
2 changes: 1 addition & 1 deletion vskernels/_metadata.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Kernel objects for scaling and format conversion within VapourSynth"""

__version__ = '3.1.0'
__version__ = '3.2.0'

__author_name__, __author_email__ = 'LightArrowsEXE', '[email protected]'
__maintainer_name__, __maintainer_email__ = 'Setsugen no ao', '[email protected]'
Expand Down
63 changes: 46 additions & 17 deletions vskernels/kernels/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
from vstools import (
CustomIndexError, CustomRuntimeError, CustomValueError, FieldBased, FuncExceptT, GenericVSFunction,
HoldsVideoFormatT, KwargsT, Matrix, MatrixT, T, VideoFormatT, check_correct_subsampling, check_variable_resolution,
core, depth, expect_bits, get_subclasses, get_video_format, inject_self, vs, vs_object
core, depth, expect_bits, fallback, get_subclasses, get_video_format, inject_self, vs, vs_object
)
from vstools.enums.color import _norm_props_enums

from ..exceptions import UnknownDescalerError, UnknownKernelError, UnknownResamplerError, UnknownScalerError
from ..types import LeftShift, TopShift
from ..types import BotFieldLeftShift, BotFieldTopShift, LeftShift, TopFieldLeftShift, TopFieldTopShift, TopShift

__all__ = [
'Scaler', 'ScalerT',
Expand Down Expand Up @@ -90,14 +91,14 @@ def _base_from_param(


def _base_ensure_obj(
cls: type[T],
basecls: type[T],
value: str | type[T] | T | None,
cls: type[BaseScalerT],
basecls: type[BaseScalerT],
value: str | type[BaseScalerT] | BaseScalerT | None,
exception_cls: type[CustomValueError],
excluded: Sequence[type] = [],
func_except: FuncExceptT | None = None
) -> T:
new_scaler: T
) -> BaseScalerT:
new_scaler: BaseScalerT

if value is None:
new_scaler = cls()
Expand Down Expand Up @@ -166,6 +167,10 @@ def __init_subclass__(cls) -> None:
if mro:
raise CustomRuntimeError('You must implement kernel_radius when inheriting BaseScaler!', reason=cls)

@staticmethod
def _wh_norm(clip: vs.VideoNode, width: int | None = None, height: int | None = None) -> tuple[int, int]:
return (fallback(width, clip.width), fallback(height, clip.height))

@classmethod
def from_param(
cls: type[BaseScalerT], scaler: str | type[BaseScalerT] | BaseScalerT | None = None, /,
Expand Down Expand Up @@ -208,10 +213,12 @@ class Scaler(BaseScaler):
@inject_self.cached
@inject_kwargs_params
def scale( # type: ignore[override]
self, clip: vs.VideoNode, width: int, height: int, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
self, clip: vs.VideoNode, width: int | None = None, height: int | None = None,
shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
width, height = Scaler._wh_norm(clip, width, height)
check_correct_subsampling(clip, width, height)
return self.scale_function(clip, **self.get_scale_args(clip, shift, width, height, **kwargs))
return self.scale_function(clip, **_norm_props_enums(self.get_scale_args(clip, shift, width, height, **kwargs)))

@inject_self.cached
def multi(
Expand Down Expand Up @@ -261,32 +268,52 @@ class Descaler(BaseScaler):
@inject_self.cached
@inject_kwargs_params
def descale( # type: ignore[override]
self, clip: vs.VideoNode, width: int, height: int, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
self, clip: vs.VideoNode, width: int | None, height: int | None,
shift: tuple[TopShift, LeftShift] | tuple[
TopShift | tuple[TopFieldTopShift, BotFieldTopShift],
LeftShift | tuple[TopFieldLeftShift, BotFieldLeftShift]
] = (0, 0), **kwargs: Any
) -> vs.VideoNode:
width, height = self._wh_norm(clip, width, height)

check_correct_subsampling(clip, width, height)

field_based = FieldBased.from_param_or_video(kwargs.pop('field_based', None), clip)

clip, bits = expect_bits(clip, 32)

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

if field_based.is_inter:
shift_y, shift_x = tuple[tuple[float, float], ...](
sh if isinstance(sh, tuple) else (sh, sh) for sh in shift
)

de_kwargs_tf = self.get_descale_args(clip, (shift_y[0], shift_x[0]), *de_base_args, **kwargs)
de_kwargs_bf = self.get_descale_args(clip, (shift_y[1], shift_x[1]), *de_base_args, **kwargs)

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

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

fields = clip.std.SeparateFields(field_based.is_tff)

interleaved = core.std.Interleave([
self.descale_function(fields[offset::2], **(de_kwargs | dict(src_top=top_shift + (field_shift * mult))))
for offset, mult in [(0, 1), (1, -1)]
self.descale_function(fields[offset::2], **_norm_props_enums(
de_kwargs | dict(src_top=de_kwargs.get('src_top', 0.0) + (field_shift * mult))
))
for offset, mult, de_kwargs in [(0, 1, de_kwargs_tf), (1, -1, de_kwargs_bf)]
])

descaled = interleaved.std.DoubleWeave(field_based.is_tff)[::2]
else:
descaled = self.descale_function(clip, **de_kwargs)
if any(isinstance(sh, tuple) for sh in shift):
raise CustomValueError('You can\'t descale per-field when the input is progressive!', self.descale)

de_kwargs = self.get_descale_args(clip, shift, *de_base_args, **kwargs) # type: ignore

descaled = self.descale_function(clip, **_norm_props_enums(de_kwargs))

return depth(descaled, bits)

Expand Down Expand Up @@ -326,7 +353,9 @@ def resample(
self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
matrix: MatrixT | None = None, matrix_in: MatrixT | None = None, **kwargs: Any
) -> vs.VideoNode:
return self.resample_function(clip, **self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
return self.resample_function(
clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
)

def get_resample_args(
self, clip: vs.VideoNode, format: int | VideoFormatT | HoldsVideoFormatT,
Expand Down Expand Up @@ -381,7 +410,7 @@ def shift(
n_planes = clip.format.num_planes

def _shift(src: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0)) -> vs.VideoNode:
return self.scale_function(src, **self.get_scale_args(src, shift, **kwargs))
return Scaler.scale(self, src, src.width, src.height, shift, **kwargs)

if not shifts_or_top and not shift_left:
return _shift(clip)
Expand Down
Loading

0 comments on commit e89f98e

Please sign in to comment.