X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-commonfmt%2Fsrc%2Fcodecs%2Fzmbvenc.rs;h=7de6c23a8f97162cb31ca53a24edbc0d0993e44f;hb=b09ecc095508e73b170333ff85d25f64bd8394db;hp=23e8aadd893bfd45eb3255b313229d6ba8ea186e;hpb=f17870054cf46115cd1eb95176b1767bd874d95c;p=nihav.git diff --git a/nihav-commonfmt/src/codecs/zmbvenc.rs b/nihav-commonfmt/src/codecs/zmbvenc.rs index 23e8aad..7de6c23 100644 --- a/nihav-commonfmt/src/codecs/zmbvenc.rs +++ b/nihav-commonfmt/src/codecs/zmbvenc.rs @@ -35,6 +35,7 @@ struct ZMBVEncoder { width: usize, height: usize, range: usize, + sent_pal: bool, } fn buf_type_to_bpp(buf: &NABufferType) -> u8 { @@ -134,6 +135,7 @@ impl ZMBVEncoder { width: 0, height: 0, range: 128, + sent_pal: false, } } fn encode_intra(&mut self, bw: &mut ByteWriter, buf: NABufferType) -> EncoderResult<()> { @@ -258,6 +260,8 @@ impl ZMBVEncoder { self.pal = npal; bw.write_byte(2)?; + + self.sent_pal = false; } else { bw.write_byte(0)?; } @@ -361,7 +365,7 @@ impl ZMBVEncoder { bw.write_buf(&self.zbuf)?; } - + Ok(()) } } @@ -400,7 +404,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); @@ -429,6 +433,21 @@ impl NAEncoder for ZMBVEncoder { false }; self.pkt = Some(NAPacket::new(self.stream.clone().unwrap(), frm.ts, is_intra, dbuf)); + if self.bpp == 8 && !self.sent_pal { + if let NABufferType::Video(ref buf) = frm.get_buffer() { + let paloff = buf.get_offset(1); + let data = buf.get_data(); + let mut pal = [0; 1024]; + let srcpal = &data[paloff..][..768]; + for (dclr, sclr) in pal.chunks_exact_mut(4).zip(srcpal.chunks_exact(3)) { + dclr[..3].copy_from_slice(sclr); + } + if let Some(ref mut pkt) = &mut self.pkt { + pkt.side_data.push(NASideData::Palette(true, Arc::new(pal))); + } + } + self.sent_pal = true; + } self.frmcount += 1; if self.frmcount == self.key_int { self.frmcount = 0; @@ -569,8 +588,9 @@ 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, + let enc_options = &[]; + //test_encoding_to_file(&dec_config, &enc_config, enc_params, enc_options); + test_encoding_md5(&dec_config, &enc_config, enc_params, enc_options, &[0x50df10e2, 0x606f3268, 0xdd4bc2ff, 0x844e7d87]); } @@ -613,8 +633,9 @@ 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, + let enc_options = &[]; + //test_encoding_to_file(&dec_config, &enc_config, enc_params, enc_options); + test_encoding_md5(&dec_config, &enc_config, enc_params, enc_options, &[0x0b4cb528, 0x66c91f6c, 0x1c2187a5, 0x2723a08d]); } @@ -657,8 +678,9 @@ 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, + let enc_options = &[]; + //test_encoding_to_file(&dec_config, &enc_config, enc_params, enc_options); + test_encoding_md5(&dec_config, &enc_config, enc_params, enc_options, &[0x1a522743, 0x6c320a6e, 0xd08539e1, 0x03fc17ea]); } @@ -701,8 +723,9 @@ 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, + let enc_options = &[]; + //test_encoding_to_file(&dec_config, &enc_config, enc_params, enc_options); + test_encoding_md5(&dec_config, &enc_config, enc_params, enc_options, &[0x3880e045, 0xe6c88dc7, 0x21066058, 0xc789f1e9]); } }