Skip to content

Commit

Permalink
Implement bore wrapper (#4)
Browse files Browse the repository at this point in the history
* Implement bore wrapper

* Rename submodule to borders

* Clean up code

* Fix typing

* Fix FunctionUtil call

---------

Co-authored-by: Setsugennoao <[email protected]>
  • Loading branch information
LightArrowsEXE and Setsugennoao authored Jun 24, 2024
1 parent 05bfb8e commit 7a8d304
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
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)

0 comments on commit 7a8d304

Please sign in to comment.