]> git.nihav.org Git - nihav-player.git/commitdiff
videoplayer: pass aligned dimensions to YUV texture update
authorKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 7 Feb 2026 17:33:20 +0000 (18:33 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 7 Feb 2026 17:33:20 +0000 (18:33 +0100)
It should be safe since YUV formats should have aligned dimensions already.

videoplayer/src/videodec.rs

index ca9fa622a3ae7ec3effb7465618d18748e2e6b42..ea6ca72d772b09022fddf9062821f86ffc40e430 100644 (file)
@@ -336,14 +336,15 @@ impl Advance for FrameSkipMode {
 }
 
 fn output_yuv(yuv_texture: &mut Texture, buf: &NAVideoBuffer<u8>, width: usize, height: usize) {
+    let aheight = (height + 1) & !1;
     let src = buf.get_data();
     let ysstride = buf.get_stride(0);
-    let ysrc = &src[buf.get_offset(0)..][..ysstride * height];
+    let ysrc = &src[buf.get_offset(0)..][..ysstride * aheight];
     let usstride = buf.get_stride(2);
-    let usrc = &src[buf.get_offset(2)..][..usstride * (height / 2)];
+    let usrc = &src[buf.get_offset(2)..][..usstride * (aheight / 2)];
     let vsstride = buf.get_stride(1);
-    let vsrc = &src[buf.get_offset(1)..][..vsstride * (height / 2)];
-    let rect = Some(sdl2::rect::Rect::new(0, 0, width as u32, height as u32));
+    let vsrc = &src[buf.get_offset(1)..][..vsstride * (aheight / 2)];
+    let rect = Some(sdl2::rect::Rect::new(0, 0, (width as u32 + 1) & !1, aheight as u32));
     yuv_texture.update_yuv(rect, ysrc, ysstride, vsrc, vsstride, usrc, usstride)
         .expect("YUV surface updated");
 }