|
1 | 1 | from enum import IntEnum |
2 | 2 |
|
3 | 3 | import cython |
| 4 | +import cython.cimports.libav as lib |
4 | 5 | from cython.cimports.av.error import err_check |
5 | 6 | from cython.cimports.av.video.format import VideoFormat |
6 | 7 | from cython.cimports.av.video.frame import alloc_video_frame |
@@ -107,30 +108,25 @@ def _resolve_enum_value( |
107 | 108 |
|
108 | 109 | @cython.cfunc |
109 | 110 | def _set_frame_colorspace( |
110 | | - frame: VideoFrame, colorspace: cython.int, color_range: cython.int |
| 111 | + frame: cython.pointer(lib.AVFrame), |
| 112 | + colorspace: cython.int, |
| 113 | + color_range: cython.int, |
111 | 114 | ): |
112 | 115 | """Set AVFrame colorspace/range from SWS_CS_* and AVColorRange values.""" |
113 | | - if colorspace in _SWS_CS_TO_AVCOL_SPC: |
114 | | - frame.ptr.colorspace = cython.cast( |
115 | | - lib.AVColorSpace, _SWS_CS_TO_AVCOL_SPC[colorspace] |
116 | | - ) |
117 | 116 | if color_range != lib.AVCOL_RANGE_UNSPECIFIED: |
118 | | - frame.ptr.color_range = cython.cast(lib.AVColorRange, color_range) |
119 | | - |
120 | | - |
121 | | -# Mapping from SWS_CS_* (swscale colorspace) to AVColorSpace (frame metadata). |
122 | | -# Note: SWS_CS_ITU601, SWS_CS_ITU624, SWS_CS_SMPTE170M, and SWS_CS_DEFAULT all have |
123 | | -# the same value (5), so we map 5 -> AVCOL_SPC_SMPTE170M as the most common case. |
124 | | -# SWS_CS_DEFAULT is handled specially by not setting frame metadata. |
125 | | -_SWS_CS_TO_AVCOL_SPC = cython.declare( |
126 | | - dict, |
127 | | - { |
128 | | - SWS_CS_ITU709: lib.AVCOL_SPC_BT709, |
129 | | - SWS_CS_FCC: lib.AVCOL_SPC_FCC, |
130 | | - SWS_CS_ITU601: lib.AVCOL_SPC_SMPTE170M, |
131 | | - SWS_CS_SMPTE240M: lib.AVCOL_SPC_SMPTE240M, |
132 | | - }, |
133 | | -) |
| 117 | + frame.color_range = cython.cast(lib.AVColorRange, color_range) |
| 118 | + # Mapping from SWS_CS_* (swscale colorspace) to AVColorSpace (frame metadata). |
| 119 | + # Note: SWS_CS_ITU601, SWS_CS_ITU624, SWS_CS_SMPTE170M, and SWS_CS_DEFAULT all have |
| 120 | + # the same value (5), so we map 5 -> AVCOL_SPC_SMPTE170M as the most common case. |
| 121 | + # SWS_CS_DEFAULT is handled specially by not setting frame metadata. |
| 122 | + if colorspace == SWS_CS_ITU709: |
| 123 | + frame.colorspace = lib.AVCOL_SPC_BT709 |
| 124 | + elif colorspace == SWS_CS_FCC: |
| 125 | + frame.colorspace = lib.AVCOL_SPC_FCC |
| 126 | + elif colorspace == SWS_CS_ITU601: |
| 127 | + frame.colorspace = lib.AVCOL_SPC_SMPTE170M |
| 128 | + elif colorspace == SWS_CS_SMPTE240M: |
| 129 | + frame.colorspace = lib.AVCOL_SPC_SMPTE240M |
134 | 130 |
|
135 | 131 |
|
136 | 132 | @cython.cclass |
@@ -300,8 +296,8 @@ def _reformat( |
300 | 296 | # Set source frame colorspace/range so sws_scale_frame can read it |
301 | 297 | frame_src_colorspace: lib.AVColorSpace = frame.ptr.colorspace |
302 | 298 | frame_src_color_range: lib.AVColorRange = frame.ptr.color_range |
303 | | - _set_frame_colorspace(frame, src_colorspace, src_color_range) |
304 | | - _set_frame_colorspace(new_frame, dst_colorspace, dst_color_range) |
| 299 | + _set_frame_colorspace(frame.ptr, src_colorspace, src_color_range) |
| 300 | + _set_frame_colorspace(new_frame.ptr, dst_colorspace, dst_color_range) |
305 | 301 |
|
306 | 302 | with cython.nogil: |
307 | 303 | ret = sws_scale_frame(self.ptr, new_frame.ptr, frame.ptr) |
|
0 commit comments