X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-duck%2Fsrc%2Fcodecs%2Ftruemotion2.rs;h=469147fcc46b981c31b8172b7afbf854662165b4;hb=9d8612819aacd6947bd0ea64e3a00172d02182b9;hp=84162b55ffd87c0a55a1515d64cca48e6fd3ca82;hpb=01613464323864a655c994820d3c43df1954e3b2;p=nihav.git diff --git a/nihav-duck/src/codecs/truemotion2.rs b/nihav-duck/src/codecs/truemotion2.rs index 84162b5..469147f 100644 --- a/nihav-duck/src/codecs/truemotion2.rs +++ b/nihav-duck/src/codecs/truemotion2.rs @@ -223,6 +223,7 @@ struct DeltaState { dc: [[i32; 2]; 2], } +#[allow(clippy::erasing_op)] impl DeltaState { fn apply_y(&mut self, dst: &mut [u8], mut yoff: usize, ystride: usize, ydeltas: &[i32; 16], last: &mut [i32]) { for y in 0..4 { @@ -287,20 +288,20 @@ impl DeltaState { } fn recalc_y(&mut self, dst: &[u8], yoff: usize, ystride: usize, last: &mut [i32]) { let src = &dst[yoff+3..]; - self.dy[0] = (src[ystride * 0] as i32) - last[3]; - self.dy[1] = (src[ystride * 1] as i32) - (src[ystride * 0] as i32); - self.dy[2] = (src[ystride * 2] as i32) - (src[ystride * 1] as i32); - self.dy[3] = (src[ystride * 3] as i32) - (src[ystride * 2] as i32); + self.dy[0] = i32::from(src[ystride * 0]) - last[3]; + self.dy[1] = i32::from(src[ystride * 1]) - i32::from(src[ystride * 0]); + self.dy[2] = i32::from(src[ystride * 2]) - i32::from(src[ystride * 1]); + self.dy[3] = i32::from(src[ystride * 3]) - i32::from(src[ystride * 2]); let src = &dst[yoff + 3 * ystride..]; for x in 0..4 { - last[x] = src[x] as i32; + last[x] = i32::from(src[x]); } } fn recalc_c(&mut self, dst: &[i16], coff: usize, cstride: usize, idx: usize, last: &mut [i32]) { - self.dc[idx][0] = (dst[coff + 1] as i32) - last[1]; - self.dc[idx][1] = (dst[coff + 1 + cstride] as i32) - (dst[coff + 1] as i32); - last[0] = dst[coff + cstride + 0] as i32; - last[1] = dst[coff + cstride + 1] as i32; + self.dc[idx][0] = i32::from(dst[coff + 1]) - last[1]; + self.dc[idx][1] = i32::from(dst[coff + 1 + cstride]) - i32::from(dst[coff + 1]); + last[0] = i32::from(dst[coff + cstride + 0]); + last[1] = i32::from(dst[coff + cstride + 1]); } } @@ -317,15 +318,9 @@ impl TM2Frame { fn alloc(width: usize, height: usize) -> Self { let ystride = (width + 3) & !3; let ysize = ystride * ((height + 3) & !3); - let mut ydata = Vec::with_capacity(ysize); - ydata.resize(ysize, 0); let cstride = ystride >> 1; let csize = cstride * (((height + 3) & !3) >> 1); - let mut udata = Vec::with_capacity(csize); - udata.resize(csize, 0); - let mut vdata = Vec::with_capacity(csize); - vdata.resize(csize, 0); - Self { ydata, udata, vdata, ystride, cstride } + Self { ydata: vec![0; ysize], udata: vec![0; csize], vdata: vec![0; csize], ystride, cstride } } } @@ -356,12 +351,9 @@ impl TM2Decoder { let mut ydeltas: [i32; 16] = [0; 16]; let mut cdeltas: [[i32; 4]; 2] = [[0; 4]; 2]; - let mut lasty: Vec = Vec::with_capacity(self.width + 1); - lasty.resize(self.width + 1, 0); - let mut lastu: Vec = Vec::with_capacity(self.width/2 + 1); - lastu.resize(self.width/2 + 1, 0); - let mut lastv: Vec = Vec::with_capacity(self.width/2 + 1); - lastv.resize(self.width/2 + 1, 0); + let mut lasty: Vec = vec![0; self.width + 1]; + let mut lastu: Vec = vec![0; self.width/2 + 1]; + let mut lastv: Vec = vec![0; self.width/2 + 1]; for by in 0..bh { let mut dstate = DeltaState::default(); for bx in 0..bw { @@ -529,7 +521,7 @@ impl TM2Decoder { for y in 0..self.height { let out = &mut dst[off..]; for (x, pic) in out.chunks_exact_mut(3).take(self.width).enumerate() { - let y = self.cur_frame.ydata[ysrc + x] as i16; + let y = i16::from(self.cur_frame.ydata[ysrc + x]); let u = self.cur_frame.udata[csrc + (x >> 1)]; let v = self.cur_frame.vdata[csrc + (x >> 1)]; pic[offs[0]] = (y + u).max(0).min(255) as u8; @@ -573,9 +565,7 @@ impl NADecoder for TM2Decoder { } let myinfo = NAVideoInfo::new(self.width, self.height, false, RGB24_FORMAT); - let bufret = alloc_video_buffer(myinfo, 2); - if let Err(_) = bufret { return Err(DecoderError::InvalidData); } - let bufinfo = bufret.unwrap(); + let bufinfo = alloc_video_buffer(myinfo, 2)?; let mut buf = bufinfo.get_vbuf().unwrap(); let is_intra = self.decode_blocks()?; @@ -587,9 +577,11 @@ impl NADecoder for TM2Decoder { frm.set_frame_type(if is_intra { FrameType::I } else { FrameType::P }); Ok(frm.into_ref()) } + fn flush(&mut self) { + } } -pub fn get_decoder() -> Box { +pub fn get_decoder() -> Box { Box::new(TM2Decoder::new()) } @@ -607,6 +599,24 @@ mod test { let mut dec_reg = RegisteredDecoders::new(); duck_register_all_codecs(&mut dec_reg); - test_file_decoding("avi", "assets/Duck/tm20.avi", Some(16), true, false, None/*Some("tm2")*/, &dmx_reg, &dec_reg); + test_decoding("avi", "truemotion2", "assets/Duck/tm20.avi", Some(16), + &dmx_reg, &dec_reg, ExpectedTestResult::MD5Frames(vec![ + [0x8c336eb4, 0x10d0d934, 0x52392306, 0xc0bc6dd3], + [0xf168ddc2, 0x502fef17, 0xf7a5d0a2, 0xc0bf2d26], + [0xf33e02fa, 0x3931b691, 0xb29a0754, 0x07c0f8fa], + [0x2dd81034, 0x1c9f7616, 0x64eed48a, 0x3aa09cf0], + [0x55d18cd9, 0x0a3fd971, 0xf28fd5af, 0x9d9c3e3d], + [0xbf9cbbd8, 0x7b44c122, 0x1c7b1904, 0x77cc87aa], + [0xa6f6e79d, 0xc463a5bc, 0x5df9460c, 0xfce2e352], + [0x2ad22b2d, 0xd4ceaff8, 0xa4adb974, 0x37888a8d], + [0x4d45575f, 0x7e5b7670, 0x40cb7438, 0x9872d422], + [0xb35bc12b, 0x026c77c6, 0x93163784, 0xb37630b7], + [0xb1ec5059, 0x1fe26596, 0x4ac8d214, 0xdaf1b895], + [0x69dd5a5f, 0xe14a16fa, 0xa0653092, 0xb04e0739], + [0x979d8fe1, 0xbef29f89, 0xefae5f86, 0xa1ceb7d2], + [0xc6dc80d7, 0x80153c6b, 0x76d770c0, 0x8fd7cce7], + [0x8da96394, 0x1bd68024, 0x5feddfba, 0xd2b00660], + [0x53ff97c3, 0xc021a9b3, 0xabdddc10, 0xc99ab86f], + [0x66c877c4, 0xd8358048, 0xbca593db, 0xc6ecc4d1]])); } }