Skip to content

Commit 906c430

Browse files
committed
Make video/plane pure python
1 parent 27d2e23 commit 906c430

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
from av.video.frame cimport VideoFrame
1+
import cython
2+
from cython.cimports.av.video.frame import VideoFrame
23

34

4-
cdef class VideoPlane(Plane):
5-
def __cinit__(self, VideoFrame frame, int index):
5+
@cython.cclass
6+
class VideoPlane(Plane):
7+
def __cinit__(self, frame: VideoFrame, index: cython.int):
68
# The palette plane has no associated component or linesize; set fields manually
79
if frame.format.name == "pal8" and index == 1:
810
self.width = 256
@@ -16,15 +18,16 @@ def __cinit__(self, VideoFrame frame, int index):
1618
self.width = component.width
1719
self.height = component.height
1820
break
19-
else:
21+
else: # nobreak
2022
raise RuntimeError(f"could not find plane {index} of {frame.format!r}")
2123

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

27-
cdef size_t _buffer_size(self):
29+
@cython.cfunc
30+
def _buffer_size(self) -> cython.size_t:
2831
return self.buffer_size
2932

3033
@property

av/video/reformatter.pyx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,11 @@ cdef class VideoReformatter:
165165

166166
if src_colorspace != dst_colorspace or src_color_range != dst_color_range:
167167
with nogil:
168-
# Casts for const-ness, because Cython isn't expressive enough.
169168
ret = lib.sws_getColorspaceDetails(
170169
self.ptr,
171-
<int**>&inv_tbl,
170+
&inv_tbl,
172171
&src_colorspace_range,
173-
<int**>&tbl,
172+
&tbl,
174173
&dst_colorspace_range,
175174
&brightness,
176175
&contrast,
@@ -210,8 +209,7 @@ cdef class VideoReformatter:
210209
with nogil:
211210
lib.sws_scale(
212211
self.ptr,
213-
# Cast for const-ness, because Cython isn't expressive enough.
214-
<const uint8_t**>frame.ptr.data,
212+
frame.ptr.data,
215213
frame.ptr.linesize,
216214
0, # slice Y
217215
frame.ptr.height,

0 commit comments

Comments
 (0)