From: Kostya Shishkov Date: Tue, 14 Feb 2023 14:48:51 +0000 (+0100) Subject: indeo3enc: fix checksum calculation X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=7b430a1e47759ba440db5d56523ec043433732c9;p=nihav.git indeo3enc: fix checksum calculation --- diff --git a/nihav-indeo/src/codecs/indeo3enc/mod.rs b/nihav-indeo/src/codecs/indeo3enc/mod.rs index 8ff2aec..5566228 100644 --- a/nihav-indeo/src/codecs/indeo3enc/mod.rs +++ b/nihav-indeo/src/codecs/indeo3enc/mod.rs @@ -162,7 +162,7 @@ impl Indeo3Encoder { for plane in self.cframe.plane.iter() { checksum ^= plane.checksum(); } - write_u16le(&mut dbuf[26..], checksum)?; + write_u16le(&mut dbuf[26..], checksum * 2)?; let size = (dbuf.len() - OS_HEADER_SIZE) as u32; write_u32le(&mut dbuf[8..], self.frameno ^ HDR_FIELD_2 ^ FRMH_TAG ^ size)?; @@ -587,7 +587,7 @@ mod test { let enc_options = &[ NAOption { name: super::TRY_AGAIN_OPTION, value: NAValue::Bool(true) }, ]; - encode_test("indeo3.avi", enc_options, Some(4), &[0x4cc927d3, 0x9872f824, 0x92dee9cb, 0xaf912ecc]); + encode_test("indeo3.avi", enc_options, Some(4), &[0xd62f9996, 0x7fb4ba1b, 0x1f552801, 0xfd4e4726]); } /*#[test] fn test_indeo3_roundtrip() { @@ -626,6 +626,7 @@ mod test { } let info = NACodecInfo::new("indeo3", NACodecTypeInfo::Video(dst_vinfo), None).into_ref(); let frm = NAFrame::new(NATimeInfo::new(Some(0), None, None, 1, 12), FrameType::I, true, info.clone(), buffer); + //ienc.set_options(&[NAOption{ name: super::DEBUG_FRAME_OPTION, value: NAValue::Bool(true) }]); ienc.encode(&frm).unwrap(); let pkt = ienc.get_packet().unwrap().unwrap(); println!(" pkt size {}", pkt.get_buffer().len()); @@ -636,6 +637,7 @@ mod test { let mut dec = (decfunc)(); let mut dsupp = Box::new(NADecoderSupport::new()); dec.init(&mut dsupp, info).unwrap(); + dec.set_options(&[NAOption{ name: "checksum", value: NAValue::Bool(true) }]); let dst = dec.decode(&mut dsupp, &pkt).unwrap(); if let NABufferType::Video(ref vbuf) = dst.get_buffer() { for plane in 0..3 { diff --git a/nihav-indeo/src/codecs/indeo3enc/tree.rs b/nihav-indeo/src/codecs/indeo3enc/tree.rs index 8c51ad7..8b1bb68 100644 --- a/nihav-indeo/src/codecs/indeo3enc/tree.rs +++ b/nihav-indeo/src/codecs/indeo3enc/tree.rs @@ -169,7 +169,7 @@ impl Plane { self.mvs.clear(); } pub fn checksum(&self) -> u16 { - let xors = self.data[self.width..].chunks(2).fold([0u8; 2], |acc, pair| [acc[0] ^ pair[0], acc[1] ^ pair[1]]); + let xors = self.data.chunks(2).fold([0u8; 2], |acc, pair| [acc[0] ^ pair[0], acc[1] ^ pair[1]]); u16::from(xors[0]) | (u16::from(xors[1]) * 256) } pub fn find_cells(&mut self, is_intra: bool, pplane: &Plane, mv_est: &MotionEstimator) -> Box {