Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement bore wrapper #4

Merged
merged 5 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions vsadjust/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# flake8: noqa

from .colorspace import *
from .borders import *
from .levels import *
from .shift import *
from .tweaking import *
56 changes: 56 additions & 0 deletions vsadjust/borders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from __future__ import annotations

from itertools import chain
from typing import Sequence

from vstools import CustomEnum, CustomValueError, FunctionUtil, KwargsT, PlanesT, core, vs

__all__ = [
'bore'
]


class bore(CustomEnum):
FIX_BRIGHTNESS: bore = object() # type:ignore
BALANCE: bore = object() # type:ignore

def __call__(
self, clip: vs.VideoNode,
left: int | Sequence[int] = 0, right: int | Sequence[int] = 0,
top: int | Sequence[int] = 0, bottom: int | Sequence[int] = 0,
planes: PlanesT = None, **kwargs: KwargsT
) -> vs.VideoNode:
func = FunctionUtil(clip, self.__class__, planes, vs.YUV, 32)

values = list(map(func.norm_seq, (left, right, top, bottom)))

if any(x < 0 for x in chain(*values)):
raise CustomValueError('Negative values are not allowed!', func.func)

if not any(x != 0 for x in chain(*values)):
return clip

try:
if self == self.FIX_BRIGHTNESS:
plugin = core.bore.FixBrightness
elif self == self.BALANCE:
plugin = core.bore.Balance
else:
raise AttributeError
except AttributeError:
raise CustomValueError(
'Could not find this bore function! Make sure you\'re using an up-to-date version of Bore.',
func.func, dict(function=self.value)
)

proc_clip: vs.VideoNode = func.work_clip

for plane in func.norm_planes:
plane_values = values[plane]

if not any(x != 0 for x in plane_values):
continue

proc_clip = plugin(proc_clip, *plane_values, plane=plane, **kwargs) # type:ignore

return func.return_clip(proc_clip)
Loading