X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-indeo%2Fsrc%2Fcodecs%2Findeo3.rs;h=a99db74667b8ac2085569746cf9864b3747b97ab;hb=1a967e6bad5f17943b4de0607078eb940ad5adfe;hp=793ef630a0c275affd71049c2e39520cebea1719;hpb=3167c45c8087a692192021e08a8063dff680001c;p=nihav.git diff --git a/nihav-indeo/src/codecs/indeo3.rs b/nihav-indeo/src/codecs/indeo3.rs index 793ef63..a99db74 100644 --- a/nihav-indeo/src/codecs/indeo3.rs +++ b/nihav-indeo/src/codecs/indeo3.rs @@ -2,7 +2,6 @@ use std::rc::Rc; use std::cell::RefCell; use nihav_core::formats; use nihav_core::codecs::*; -use nihav_core::frame::*; use nihav_core::io::byteio::*; use std::io::SeekFrom; use std::mem; @@ -21,6 +20,8 @@ struct MV { struct Buffers { width: usize, height: usize, + cw: usize, + ch: usize, buf1: Vec, buf2: Vec, fbuf: bool, @@ -29,7 +30,7 @@ struct Buffers { const DEFAULT_PIXEL: u8 = 0x40; impl Buffers { - fn new() -> Self { Buffers { width: 0, height: 0, buf1: Vec::new(), buf2: Vec::new(), fbuf: true } } + fn new() -> Self { Buffers { width: 0, height: 0, cw: 0, ch: 0, buf1: Vec::new(), buf2: Vec::new(), fbuf: true } } fn reset(&mut self) { self.width = 0; self.height = 0; @@ -39,17 +40,19 @@ impl Buffers { fn alloc(&mut self, w: usize, h: usize) { self.width = w; self.height = h; - self.buf1.resize(w * h + (w >> 2) * (h >> 2) * 2, DEFAULT_PIXEL); - self.buf2.resize(w * h + (w >> 2) * (h >> 2) * 2, DEFAULT_PIXEL); + self.cw = ((w >> 2) + 3) & !3; + self.ch = ((h >> 2) + 3) & !3; + self.buf1.resize(w * h + self.cw * self.ch * 2, DEFAULT_PIXEL); + self.buf2.resize(w * h + self.cw * self.ch * 2, DEFAULT_PIXEL); } fn flip(&mut self) { self.fbuf = !self.fbuf; } fn get_stride(&mut self, planeno: usize) -> usize { - if planeno == 0 { self.width } else { self.width >> 2 } + if planeno == 0 { self.width } else { self.cw } } fn get_offset(&mut self, planeno: usize) -> usize { match planeno { 1 => self.width * self.height, - 2 => self.width * self.height + (self.width >> 2) * (self.height >> 2), + 2 => self.width * self.height + self.cw * self.ch, _ => 0, } } @@ -59,10 +62,10 @@ impl Buffers { let mut doff = fbuf.get_offset(planeno); let sstride = self.get_stride(planeno); let dstride = fbuf.get_stride(planeno); - let width = if planeno == 0 { self.width } else { self.width >> 2 }; + let width = if planeno == 0 { self.width } else { self.width >> 2 }; let height = if planeno == 0 { self.height } else { self.height >> 2 }; let src = if self.fbuf { &self.buf1[0..] } else { &self.buf2[0..] }; - let mut dst = fbuf.get_data_mut(); + let dst = fbuf.get_data_mut().unwrap(); for _ in 0..height { for x in 0..width { dst[doff + x] = src[soff + x] * 2; @@ -234,6 +237,9 @@ fn fill_block8x8(bufs: &mut Buffers, doff: usize, stride: usize, h: usize, topli } let start = if !topline { 0 } else { 1 }; + if topline { + didx += stride; + } if bufs.fbuf { for _ in start..h { for i in 0..8 { bufs.buf1[didx + i] = buf[i]; } @@ -646,8 +652,9 @@ impl Indeo3Decoder { } let shift = if planeno == 0 { 2 } else { 4 }; - let cell = IV3Cell::new((self.bufs.width >> shift) as u16, - (self.bufs.height >> shift) as u16); + let round = (1 << shift) - 1; + let cell = IV3Cell::new(((self.bufs.width + round) >> shift) as u16, + ((self.bufs.height + round) >> shift) as u16); self.br_reset(); self.parse_tree(br, cell, offs, stride, if planeno > 0 { 10 } else { 40 }, true)?; validate!(br.tell() <= end); @@ -752,9 +759,11 @@ impl NADecoder for Indeo3Decoder { let intraframe = (flags & FLAG_KEYFRAME) != 0; let vinfo = self.info.get_properties().get_video_info().unwrap(); - let bufret = alloc_video_buffer(vinfo, 2); + validate!((vinfo.get_width() & !3) == (self.width & !3).into()); + validate!((vinfo.get_height() & !3) == (self.height & !3).into()); + let bufret = alloc_video_buffer(vinfo, 4); if let Err(_) = bufret { return Err(DecoderError::InvalidData); } - let mut bufinfo = bufret.unwrap(); + let bufinfo = bufret.unwrap(); let mut buf = bufinfo.get_vbuf().unwrap(); let ystart = data_start + (yoff as u64); let ustart = data_start + (uoff as u64); @@ -798,7 +807,7 @@ mod test { let mut dec_reg = RegisteredDecoders::new(); indeo_register_all_codecs(&mut dec_reg); - test_file_decoding("avi", "assets/iv32_example.avi", Some(10), true, false, None, &dmx_reg, &dec_reg); + test_file_decoding("avi", "assets/Indeo/iv32_example.avi", Some(10), true, false, None, &dmx_reg, &dec_reg); } }