-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement bore wrapper * Rename submodule to borders * Clean up code * Fix typing * Fix FunctionUtil call --------- Co-authored-by: Setsugennoao <[email protected]>
- Loading branch information
1 parent
05bfb8e
commit 7a8d304
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |