Skip to content

Commit

Permalink
Improve docstring and type hinting, and a bit of code for execute() a…
Browse files Browse the repository at this point in the history
…nd it's replace_planes()
  • Loading branch information
rlaphoenix committed Dec 27, 2020
1 parent 14acebb commit b5d327e
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions vsgan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def run(self, clip: vs.VideoNode, chunk: bool = False) -> vs.VideoNode:
# return the new result clip
return clip

def execute(self, n: int, clip: vs.VideoNode):
def execute(self, n: int, clip: vs.VideoNode) -> vs.VideoNode:
"""
Copies the xinntao ESRGAN repo's main execution code. The only real difference is it doesn't use cv2, and
instead uses vapoursynth ports of cv2's functionality for read and writing "images".
Expand Down Expand Up @@ -250,19 +250,20 @@ def cv2_imwrite(image, out_color_space: str = "RGB24") -> vs.VideoNode:
image = image.reshape([1] + list(image.shape))
# Define the shapes items
plane_count = image.shape[-1]
image_width = image.shape[-2]
image_height = image.shape[-3]
image_length = image.shape[-4]
# this is a clip (or array buffer for frames) that we will insert the GAN'd frames into
# this is a clip (or array buffer for frames) that we will insert the GAN frames into
buffer = core.std.BlankClip(
clip=None,
width=image_width,
height=image_height,
width=image.shape[-2],
height=image.shape[-3],
format=vs.PresetFormat[out_color_space],
length=image_length
length=image.shape[-4]
)

def replace_planes(n: int, f):
def replace_planes(n: int, f: vs.VideoFrame) -> vs.VideoFrame:
"""
:param n: frame number
:param f: frame
:returns: frame with planes replaced
"""
frame = f.copy()
for i, plane_num in enumerate(reversed(range(plane_count))):
# todo ; any better way to do this without storing the np.array in a variable?
Expand Down

0 comments on commit b5d327e

Please sign in to comment.