def extract_plane_r36compat(frame: VideoFrame, planeno: int, *, compat: bool=False) -> Image.Image:
"""
Extracts the plane using the old VapourSynth API for reading a frame.
Since we are doing raw memory operations using ctypes, this function has proven to be prone
to SIGSEGV while developing.
This code will subseqently be dropped from this codebase when VapourSynth r36 is officially dropped
with the official release of R39.
:param frame: The frame
:param planeno: The plane number
:param compat: Are we dealing with a compat format.
:return: The extracted image.
"""
width, height = calculate_size(frame, planeno)
stride = frame.get_stride(planeno)
s_plane = height * stride
buf = (ctypes.c_byte*s_plane).from_address(frame.get_read_ptr(planeno).value)
if not compat:
return Image.frombuffer('L', (width, height), buf, "raw", "L", stride, -1)
else:
return Image.frombuffer('RGB', (width, height), buf, "raw", "BGRX", stride, -1)
评论列表
文章目录