From 674da81eab4893d4315ddb567c2e9451be6da93e Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Mon, 19 Jan 2026 01:05:38 -0500 Subject: [PATCH] Make video/plane pure python --- av/video/{plane.pyx => plane.py} | 13 ++++++++----- av/video/reformatter.pyx | 8 +++----- 2 files changed, 11 insertions(+), 10 deletions(-) rename av/video/{plane.pyx => plane.py} (81%) diff --git a/av/video/plane.pyx b/av/video/plane.py similarity index 81% rename from av/video/plane.pyx rename to av/video/plane.py index 908b48716..495a9de4c 100644 --- a/av/video/plane.pyx +++ b/av/video/plane.py @@ -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 @@ -16,7 +18,7 @@ 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 @@ -24,7 +26,8 @@ def __cinit__(self, VideoFrame frame, int index): # 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 diff --git a/av/video/reformatter.pyx b/av/video/reformatter.pyx index a0c576d12..4f6ec4c9f 100644 --- a/av/video/reformatter.pyx +++ b/av/video/reformatter.pyx @@ -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, - &inv_tbl, + &inv_tbl, &src_colorspace_range, - &tbl, + &tbl, &dst_colorspace_range, &brightness, &contrast, @@ -210,8 +209,7 @@ cdef class VideoReformatter: with nogil: lib.sws_scale( self.ptr, - # Cast for const-ness, because Cython isn't expressive enough. - frame.ptr.data, + frame.ptr.data, frame.ptr.linesize, 0, # slice Y frame.ptr.height,