Skip to content

Commit

Permalink
src/cython/vapoursynth.pyx: restore api3 VideoFrame.planes
Browse files Browse the repository at this point in the history
Turns out this undocumented API is used in the wild.

Signed-off-by: akarin <i@akarin.info>
  • Loading branch information
AkarinVS committed Dec 25, 2021
1 parent fb58e12 commit 74e0c22
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/cython/vapoursynth.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,11 @@ cdef class VideoFrame(RawFrame):
s += '\tHeight: ' + str(self.height) + '\n'
return s

def planes(self): # undocumented api3
cdef int x
for x in range(self.format.num_planes):
yield VideoPlane.__new__(VideoPlane, self, x)

def get_read_array(self, int index):
return memoryview2(self.__getitem__(index), True)
def get_write_array(self, int index):
Expand Down Expand Up @@ -1367,6 +1372,27 @@ cdef VideoFrame createVideoFrame(VSFrame *f, const VSAPI *funcs, VSCore *core):
instance.props = createFrameProps(instance)
return instance

# done: undeprecate this
cdef class VideoPlane:
cdef:
object data

def __cinit__(self, *args, **kwargs):
self.data = VideoFrame.__getitem__(*args, **kwargs)

@property
def width(self):
"""Plane's pixel width."""
return PyMemoryView_GET_BUFFER(self.data).shape[1]

@property
def height(self):
"""Plane's pixel height."""
return PyMemoryView_GET_BUFFER(self.data).shape[0]

def __getbuffer__(self, Py_buffer* view, int flags):
# forward the request to the memoryview instance
PyObject_GetBuffer(self.data, view, flags)

@cython.final
@cython.internal
Expand Down

0 comments on commit 74e0c22

Please sign in to comment.