Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions av/video/plane.pyx → av/video/plane.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from av.video.frame cimport VideoFrame
import cython
from cython.cimports.av.video.frame import VideoFrame


cdef class VideoPlane(Plane):
def __cinit__(self, VideoFrame frame, int index):
@cython.cclass
class VideoPlane(Plane):
def __cinit__(self, frame: VideoFrame, index: cython.int):
# The palette plane has no associated component or linesize; set fields manually
if frame.format.name == "pal8" and index == 1:
self.width = 256
Expand All @@ -16,15 +18,16 @@ def __cinit__(self, VideoFrame frame, int index):
self.width = component.width
self.height = component.height
break
else:
else: # nobreak
raise RuntimeError(f"could not find plane {index} of {frame.format!r}")

# Sometimes, linesize is negative (and that is meaningful). We are only
# insisting that the buffer size be based on the extent of linesize, and
# ignore it's direction.
self.buffer_size = abs(self.frame.ptr.linesize[self.index]) * self.height

cdef size_t _buffer_size(self):
@cython.cfunc
def _buffer_size(self) -> cython.size_t:
return self.buffer_size

@property
Expand Down
8 changes: 3 additions & 5 deletions av/video/reformatter.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,11 @@ cdef class VideoReformatter:

if src_colorspace != dst_colorspace or src_color_range != dst_color_range:
with nogil:
# Casts for const-ness, because Cython isn't expressive enough.
ret = lib.sws_getColorspaceDetails(
self.ptr,
<int**>&inv_tbl,
&inv_tbl,
&src_colorspace_range,
<int**>&tbl,
&tbl,
&dst_colorspace_range,
&brightness,
&contrast,
Expand Down Expand Up @@ -210,8 +209,7 @@ cdef class VideoReformatter:
with nogil:
lib.sws_scale(
self.ptr,
# Cast for const-ness, because Cython isn't expressive enough.
<const uint8_t**>frame.ptr.data,
frame.ptr.data,
frame.ptr.linesize,
0, # slice Y
frame.ptr.height,
Expand Down
Loading