X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-commonfmt%2Fsrc%2Fcodecs%2Fzmbvenc.rs;h=d7be6054ea184acdf2b4f02954c1923e22284150;hb=625751036014b099fd9c126397bc973cb0543130;hp=8ba976a71c952df92d02c14ee14893e8a088de39;hpb=95b8d59d1acf44b0f3d3d4b4fed0d07af45d702c;p=nihav.git diff --git a/nihav-commonfmt/src/codecs/zmbvenc.rs b/nihav-commonfmt/src/codecs/zmbvenc.rs index 8ba976a..d7be605 100644 --- a/nihav-commonfmt/src/codecs/zmbvenc.rs +++ b/nihav-commonfmt/src/codecs/zmbvenc.rs @@ -139,13 +139,14 @@ impl ZMBVEncoder { } } fn encode_intra(&mut self, bw: &mut ByteWriter, buf: NABufferType) -> EncoderResult<()> { - let bpp = buf_type_to_bpp(&buf); + let mut bpp = buf_type_to_bpp(&buf); if let NABufferType::None = buf { if self.bpp == 0 { return Err(EncoderError::FormatError); } self.frm1.copy_from_slice(&self.frm2); + bpp = self.bpp; } else { if bpp == 0 { return Err(EncoderError::FormatError); @@ -184,7 +185,7 @@ impl ZMBVEncoder { } bw.write_buf(&self.frm1[..self.width * self.height * bm])?; } else { - self.tmp_buf.truncate(0); + self.tmp_buf.clear(); if bpp == 8 { self.tmp_buf.extend_from_slice(&self.pal); } @@ -193,7 +194,7 @@ impl ZMBVEncoder { let mut db = Vec::new(); std::mem::swap(&mut db, &mut self.zbuf); - db.truncate(0); + db.clear(); let mut wr = DeflateWriter::new(db); self.compr.write_zlib_header(&mut wr); self.compr.compress(&self.tmp_buf, &mut wr); @@ -211,7 +212,7 @@ impl ZMBVEncoder { self.frm1.copy_from_slice(&self.frm2); bw.write_byte(0)?; - self.tmp_buf.truncate(0); + self.tmp_buf.clear(); let tile_w = (self.width + self.tile_w - 1) / self.tile_w; let tile_h = (self.height + self.tile_h - 1) / self.tile_h; let mv_size = (tile_w * tile_h * 2 + 3) & !3; @@ -224,7 +225,7 @@ impl ZMBVEncoder { let mut db = Vec::new(); std::mem::swap(&mut db, &mut self.zbuf); - db.truncate(0); + db.clear(); let mut wr = DeflateWriter::new(db); self.compr.compress(&self.tmp_buf, &mut wr); self.compr.compress_flush(&mut wr); @@ -240,7 +241,7 @@ impl ZMBVEncoder { return Err(EncoderError::FormatError); } - self.tmp_buf.truncate(0); + self.tmp_buf.clear(); if let (NABufferType::Video(ref vbuf), true) = (&buf, bpp == 8) { let mut npal = [0; 768]; let off = vbuf.get_offset(1); @@ -356,7 +357,7 @@ impl ZMBVEncoder { let mut db = Vec::new(); std::mem::swap(&mut db, &mut self.zbuf); - db.truncate(0); + db.clear(); let mut wr = DeflateWriter::new(db); self.compr.compress(&self.tmp_buf, &mut wr); self.compr.compress_flush(&mut wr); @@ -365,7 +366,7 @@ impl ZMBVEncoder { bw.write_buf(&self.zbuf)?; } - + Ok(()) } } @@ -374,9 +375,10 @@ impl NAEncoder for ZMBVEncoder { fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult { match encinfo.format { NACodecTypeInfo::None => { - let mut ofmt = EncodeParameters::default(); - ofmt.format = NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, true, YUV420_FORMAT)); - Ok(ofmt) + Ok(EncodeParameters { + format: NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, true, YUV420_FORMAT)), + ..Default::default() + }) }, NACodecTypeInfo::Audio(_) => Err(EncoderError::FormatError), NACodecTypeInfo::Video(vinfo) => { @@ -397,6 +399,7 @@ impl NAEncoder for ZMBVEncoder { } } } + fn get_capabilities(&self) -> u64 { ENC_CAPS_SKIPFRAME } fn init(&mut self, stream_id: u32, encinfo: EncodeParameters) -> EncoderResult { match encinfo.format { NACodecTypeInfo::None => Err(EncoderError::FormatError), @@ -404,7 +407,7 @@ impl NAEncoder for ZMBVEncoder { NACodecTypeInfo::Video(vinfo) => { self.width = vinfo.width; self.height = vinfo.height; - + let out_info = NAVideoInfo::new(vinfo.width, vinfo.height, false, vinfo.format); let info = NACodecInfo::new("zmbv", NACodecTypeInfo::Video(out_info), None); let mut stream = NAStream::new(StreamType::Video, stream_id, info, encinfo.tb_num, encinfo.tb_den, 0); @@ -549,6 +552,7 @@ mod test { use nihav_codec_support::test::enc_video::*; use super::{RGB555_FORMAT, RGB24_0_FORMAT}; + // samples are from https://samples.mplayerhq.hu/V-codecs/ZMBV/ #[test] fn test_zmbv_encoder_8bit() { let mut dmx_reg = RegisteredDemuxers::new(); @@ -588,9 +592,12 @@ mod test { tb_den: 0, flags: 0, }; - //test_encoding_to_file(&dec_config, &enc_config, enc_params); - test_encoding_md5(&dec_config, &enc_config, enc_params, - &[0x50df10e2, 0x606f3268, 0xdd4bc2ff, 0x844e7d87]); + let enc_options = &[ + NAOption { name: "range", value: NAValue::Int(16) }, + ]; + //test_encoding_to_file(&dec_config, &enc_config, enc_params, enc_options); + test_encoding_md5(&dec_config, &enc_config, enc_params, enc_options, + &[0x18bd3754, 0x97007f81, 0xff2bcd07, 0x739c48dc]); } #[test] @@ -632,9 +639,12 @@ mod test { tb_den: 0, flags: 0, }; - //test_encoding_to_file(&dec_config, &enc_config, enc_params); - test_encoding_md5(&dec_config, &enc_config, enc_params, - &[0x0b4cb528, 0x66c91f6c, 0x1c2187a5, 0x2723a08d]); + let enc_options = &[ + NAOption { name: "range", value: NAValue::Int(16) }, + ]; + //test_encoding_to_file(&dec_config, &enc_config, enc_params, enc_options); + test_encoding_md5(&dec_config, &enc_config, enc_params, enc_options, + &[0x00311257, 0xd26a0e9e, 0xfd4b003f, 0x7c962d7b]); } #[test] @@ -676,9 +686,12 @@ mod test { tb_den: 0, flags: 0, }; - //test_encoding_to_file(&dec_config, &enc_config, enc_params); - test_encoding_md5(&dec_config, &enc_config, enc_params, - &[0x1a522743, 0x6c320a6e, 0xd08539e1, 0x03fc17ea]); + let enc_options = &[ + NAOption { name: "range", value: NAValue::Int(16) }, + ]; + //test_encoding_to_file(&dec_config, &enc_config, enc_params, enc_options); + test_encoding_md5(&dec_config, &enc_config, enc_params, enc_options, + &[0x4eea104f, 0x2ebe544b, 0x54deb0f9, 0xe5ca88f4]); } #[test] @@ -720,8 +733,11 @@ mod test { tb_den: 0, flags: 0, }; - //test_encoding_to_file(&dec_config, &enc_config, enc_params); - test_encoding_md5(&dec_config, &enc_config, enc_params, - &[0x3880e045, 0xe6c88dc7, 0x21066058, 0xc789f1e9]); + let enc_options = &[ + NAOption { name: "range", value: NAValue::Int(16) }, + ]; + //test_encoding_to_file(&dec_config, &enc_config, enc_params, enc_options); + test_encoding_md5(&dec_config, &enc_config, enc_params, enc_options, + &[0xffceb4bd, 0xb1beccd9, 0x4983e7f6, 0xf46e33ba]); } }