X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-indeo%2Fsrc%2Fcodecs%2Findeo2.rs;h=a022ec4af1a62d7781c72fbdf5d6819c99643219;hb=f2af8ecaeed8ec8c1fa6b3c2cfdb075d64994b7a;hp=c03d2c226c4bf685e81c6d2779d73e15fe2139fd;hpb=c3904fe5804a28e73822c27c69ba10a716cb290d;p=nihav.git diff --git a/nihav-indeo/src/codecs/indeo2.rs b/nihav-indeo/src/codecs/indeo2.rs index c03d2c2..a022ec4 100644 --- a/nihav-indeo/src/codecs/indeo2.rs +++ b/nihav-indeo/src/codecs/indeo2.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; -use std::cell::RefCell; use nihav_core::io::bitreader::*; use nihav_core::io::codebook::*; use nihav_core::formats; @@ -178,7 +176,7 @@ struct IR2CodeReader { } impl CodebookDescReader for IR2CodeReader { fn bits(&mut self, idx: usize) -> u8 { INDEO2_CODE_LENGTHS[idx] } - fn code(&mut self, idx: usize) -> u32 { INDEO2_CODE_CODES[idx] as u32 } + fn code(&mut self, idx: usize) -> u32 { u32::from(INDEO2_CODE_CODES[idx]) } fn sym (&mut self, idx: usize) -> u8 { if idx < 0x7F { (idx + 1) as u8 } else { (idx + 2) as u8 } } @@ -186,17 +184,17 @@ impl CodebookDescReader for IR2CodeReader { } struct Indeo2Decoder { - info: Rc, + info: NACodecInfoRef, cb: Codebook, frmmgr: HAMShuffler, } impl Indeo2Decoder { fn new() -> Self { - let dummy_info = Rc::new(DUMMY_CODEC_INFO); + let dummy_info = NACodecInfo::new_dummy(); let mut coderead = IR2CodeReader{}; let cb = Codebook::new(&mut coderead, CodebookMode::LSB).unwrap(); - Indeo2Decoder { info: dummy_info, cb: cb, frmmgr: HAMShuffler::new() } + Indeo2Decoder { info: dummy_info, cb, frmmgr: HAMShuffler::new() } } fn decode_plane_intra(&self, br: &mut BitReader, @@ -207,7 +205,7 @@ impl Indeo2Decoder { let stride = buf.get_stride(planeno); let cb = &self.cb; - let mut data = buf.get_data_mut(); + let data = buf.get_data_mut().unwrap(); let framebuf: &mut [u8] = data.as_mut_slice(); let table = &INDEO2_DELTA_TABLE[tableno]; @@ -242,10 +240,10 @@ impl Indeo2Decoder { } x += run; } else { - let delta0 = (table[idx * 2 + 0] as i16) - 0x80; - let delta1 = (table[idx * 2 + 1] as i16) - 0x80; - let mut pix0 = framebuf[base + x + 0 - stride] as i16; - let mut pix1 = framebuf[base + x + 1 - stride] as i16; + let delta0 = i16::from(table[idx * 2 + 0]) - 0x80; + let delta1 = i16::from(table[idx * 2 + 1]) - 0x80; + let mut pix0 = i16::from(framebuf[base + x + 0 - stride]); + let mut pix1 = i16::from(framebuf[base + x + 1 - stride]); pix0 += delta0; pix1 += delta1; if pix0 < 0 { pix0 = 0; } @@ -270,7 +268,7 @@ impl Indeo2Decoder { let stride = buf.get_stride(planeno); let cb = &self.cb; - let mut data = buf.get_data_mut(); + let data = buf.get_data_mut().unwrap(); let framebuf: &mut [u8] = data.as_mut_slice(); let table = &INDEO2_DELTA_TABLE[tableno]; @@ -285,12 +283,12 @@ impl Indeo2Decoder { if x + run > w { return Err(DecoderError::InvalidData); } x += run; } else { - let delta0 = (table[idx * 2 + 0] as i16) - 0x80; - let delta1 = (table[idx * 2 + 1] as i16) - 0x80; - let mut pix0 = framebuf[base + x + 0] as i16; - let mut pix1 = framebuf[base + x + 1] as i16; - pix0 += delta0 * 3 >> 2; - pix1 += delta1 * 3 >> 2; + let delta0 = i16::from(table[idx * 2 + 0]) - 0x80; + let delta1 = i16::from(table[idx * 2 + 1]) - 0x80; + let mut pix0 = i16::from(framebuf[base + x + 0]); + let mut pix1 = i16::from(framebuf[base + x + 1]); + pix0 += (delta0 * 3) >> 2; + pix1 += (delta1 * 3) >> 2; if pix0 < 0 { pix0 = 0; } if pix1 < 0 { pix1 = 0; } if pix0 > 255 { pix0 = 255; } @@ -309,21 +307,21 @@ impl Indeo2Decoder { const IR2_START: usize = 48; impl NADecoder for Indeo2Decoder { - fn init(&mut self, info: Rc) -> DecoderResult<()> { + fn init(&mut self, _supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let w = vinfo.get_width(); let h = vinfo.get_height(); let f = vinfo.is_flipped(); let fmt = formats::YUV410_FORMAT; let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(w, h, f, fmt)); - self.info = Rc::new(NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata())); + self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); self.frmmgr.clear(); Ok(()) } else { Err(DecoderError::InvalidData) } } - fn decode(&mut self, pkt: &NAPacket) -> DecoderResult { + fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult { let src = pkt.get_buffer(); if src.len() <= IR2_START { return Err(DecoderError::ShortData); } let interframe = src[18]; @@ -333,9 +331,7 @@ impl NADecoder for Indeo2Decoder { let chroma_tab = (tabs >> 2) & 3; if interframe != 0 { let vinfo = self.info.get_properties().get_video_info().unwrap(); - let bufret = alloc_video_buffer(vinfo, 2); - if let Err(_) = bufret { return Err(DecoderError::InvalidData); } - let mut bufinfo = bufret.unwrap(); + let bufinfo = alloc_video_buffer(vinfo, 2)?; let mut buf = bufinfo.get_vbuf().unwrap(); for plane in 0..3 { let tabidx = (if plane == 0 { luma_tab } else { chroma_tab }) as usize; @@ -345,10 +341,10 @@ impl NADecoder for Indeo2Decoder { let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), bufinfo); frm.set_keyframe(true); frm.set_frame_type(FrameType::I); - Ok(Rc::new(RefCell::new(frm))) + Ok(frm.into_ref()) } else { let bufret = self.frmmgr.clone_ref(); - if let None = bufret { return Err(DecoderError::MissingReference); } + if bufret.is_none() { return Err(DecoderError::MissingReference); } let mut buf = bufret.unwrap(); for plane in 0..3 { @@ -358,12 +354,12 @@ impl NADecoder for Indeo2Decoder { let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), NABufferType::Video(buf)); frm.set_keyframe(false); frm.set_frame_type(FrameType::P); - Ok(Rc::new(RefCell::new(frm))) + Ok(frm.into_ref()) } } } -pub fn get_decoder() -> Box { +pub fn get_decoder() -> Box { Box::new(Indeo2Decoder::new()) } @@ -381,6 +377,6 @@ mod test { let mut dec_reg = RegisteredDecoders::new(); indeo_register_all_codecs(&mut dec_reg); - test_file_decoding("avi", "assets/laser05.avi", Some(10), true, false, None, &dmx_reg, &dec_reg); + test_file_decoding("avi", "assets/Indeo/laser05.avi", Some(10), true, false, None, &dmx_reg, &dec_reg); } }