let mut off = [adata.get_offset(0), adata.get_offset(1)];
let dst = adata.get_data_mut().unwrap();
- let mut mr = MemoryReader::new_read(pktbuf.as_slice());
- let mut br = ByteReader::new(&mut mr);
+ let mut br = MemoryReader::new_read(pktbuf.as_slice());
for ch in 0..channels {
let pred = br.read_u16le()? as i16;
let step = br.read_byte()?;
use nihav_codec_support::codecs::imaadpcm::*;
struct NibbleWriter<'a> {
- bw: ByteWriter<'a>,
+ bw: &'a mut dyn ByteIO,
val: u8,
first: bool,
}
impl<'a> NibbleWriter<'a> {
- fn new(bw: ByteWriter<'a>) -> Self {
+ fn new(bw: &'a mut dyn ByteIO) -> Self {
Self { bw, val: 0, first: true }
}
fn write(&mut self, nib: u8) -> EncoderResult<()> {
}
let mut dbuf = vec![0u8; self.block_size];
- let mut mw = MemoryWriter::new_write(dbuf.as_mut_slice());
- let mut bw = ByteWriter::new(&mut mw);
+ let mut bw = MemoryWriter::new_write(dbuf.as_mut_slice());
for ch in 0..self.channels {
self.first[ch].predictor = i32::from(self.samples[ch]);
bw.write_byte(self.first[ch].step as u8)?;
bw.write_byte(0)?;
}
- let mut nw = NibbleWriter::new(bw);
+ let mut nw = NibbleWriter::new(&mut bw);
for samples in self.samples.chunks(self.channels).take(self.block_len).skip(1) {
for (state, &samp) in self.first.iter_mut().zip(samples.iter()) {
let nib = state.compress_sample(samp);
bw.write_byte(self.nibs[ch][0])?;
bw.write_byte(0)?;
}
- let mut nw = NibbleWriter::new(bw);
+ let mut nw = NibbleWriter::new(&mut bw);
for i in 1..self.block_len {
for ch in 0..self.channels {
nw.write(self.nibs[ch][i])?;
if let Some(ref buf) = info.get_extradata() {
validate!(buf.len() >= 6);
validate!((buf.len() & 3) == 0);
- let mut mr = MemoryReader::new_read(buf.as_slice());
- let mut br = ByteReader::new(&mut mr);
+ let mut br = MemoryReader::new_read(buf.as_slice());
let _smth = br.read_u16le()?;
let ncoeffs = br.read_u16le()? as usize;
validate!(buf.len() == ncoeffs * 4 + 4);
let mut pred = [Predictor::default(), Predictor::default()];
for blk in pktbuf.chunks(self.block_len) {
- let mut mr = MemoryReader::new_read(blk);
- let mut br = ByteReader::new(&mut mr);
+ let mut br = MemoryReader::new_read(blk);
for p in pred[..channels].iter_mut() {
let coef_idx = br.read_byte()? as usize;
validate!(coef_idx < self.adapt_coeffs.len());
}
let mut dbuf = vec![0u8; Self::calc_block_size(len, self.channels)];
- let mut mw = MemoryWriter::new_write(dbuf.as_mut_slice());
- let mut bw = ByteWriter::new(&mut mw);
+ let mut bw = MemoryWriter::new_write(dbuf.as_mut_slice());
let mut best_idx = [0usize; 2];
for (ch, best_idx) in best_idx[..self.channels].iter_mut().enumerate() {
fn new() -> Self {
Self::default()
}
- fn decode_8bit(&self, br: &mut ByteReader, frm: &mut NASimpleVideoFrame<u8>) -> DecoderResult<FrameType> {
+ fn decode_8bit(&self, br: &mut dyn ByteIO, frm: &mut NASimpleVideoFrame<u8>) -> DecoderResult<FrameType> {
let mut has_skips = false;
if (br.left() as usize) == self.width * self.height {
Ok(if has_skips { FrameType::P } else { FrameType::I })
}
- fn decode_4bit(&self, br: &mut ByteReader, frm: &mut NASimpleVideoFrame<u8>) -> DecoderResult<FrameType> {
+ fn decode_4bit(&self, br: &mut dyn ByteIO, frm: &mut NASimpleVideoFrame<u8>) -> DecoderResult<FrameType> {
let mut has_skips = false;
if (br.left() as usize) == (self.width + 1) / 2 * self.height {
fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
let src = pkt.get_buffer();
validate!(src.len() >= 2);
- let mut mr = MemoryReader::new_read(src.as_slice());
- let mut br = ByteReader::new(&mut mr);
+ let mut br = MemoryReader::new_read(src.as_slice());
let bufret = self.hams.clone_ref();
let mut buf;
fn new() -> Self {
Self::default()
}
- fn decode_frame(&self, br: &mut ByteReader, frm: &mut NASimpleVideoFrame<u8>) -> DecoderResult<FrameType> {
+ fn decode_frame(&self, br: &mut dyn ByteIO, frm: &mut NASimpleVideoFrame<u8>) -> DecoderResult<FrameType> {
let off = frm.offset[0];
let stride = frm.stride[0];
let mut skip_count = 0;
Ok(FrameType::Skip)
}
}
- fn decode_frame16(&self, br: &mut ByteReader, frm: &mut NASimpleVideoFrame<u16>) -> DecoderResult<FrameType> {
+ fn decode_frame16(&self, br: &mut dyn ByteIO, frm: &mut NASimpleVideoFrame<u16>) -> DecoderResult<FrameType> {
let off = frm.offset[0];
let stride = frm.stride[0];
let mut skip_count = 0;
fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
let src = pkt.get_buffer();
validate!(src.len() >= 2);
- let mut mr = MemoryReader::new_read(src.as_slice());
- let mut br = ByteReader::new(&mut mr);
+ let mut br = MemoryReader::new_read(src.as_slice());
let buftype;
let ftype;
struct BlockWriterPal {}
impl BlockWriterPal {
- fn write_fill(bw: &mut ByteWriter, fill_val: u8) -> EncoderResult<()> {
+ fn write_fill(bw: &mut dyn ByteIO, fill_val: u8) -> EncoderResult<()> {
bw.write_byte(fill_val)?;
bw.write_byte(0x80)?;
Ok(())
}
- fn write_clr2(bw: &mut ByteWriter, clr2_flags: u16, clr2: [u8; 2]) -> EncoderResult<()> {
+ fn write_clr2(bw: &mut dyn ByteIO, clr2_flags: u16, clr2: [u8; 2]) -> EncoderResult<()> {
bw.write_u16le(clr2_flags)?;
bw.write_byte(clr2[0])?;
bw.write_byte(clr2[1])?;
Ok(())
}
- fn write_clr8(bw: &mut ByteWriter, mut clr8_flags: u16, mut clr8: [[u8; 4]; 4]) -> EncoderResult<()> {
+ fn write_clr8(bw: &mut dyn ByteIO, mut clr8_flags: u16, mut clr8: [[u8; 4]; 4]) -> EncoderResult<()> {
if (clr8_flags & 0x8000) == 0 {
clr8_flags ^= 0xFF00;
clr8[2].swap(0, 1);
struct BlockWriter15 {}
impl BlockWriter15 {
- fn write_fill(bw: &mut ByteWriter, fill_val: u16) -> EncoderResult<()> {
+ fn write_fill(bw: &mut dyn ByteIO, fill_val: u16) -> EncoderResult<()> {
bw.write_u16le(fill_val | 0x8000)?;
Ok(())
}
- fn write_clr2(bw: &mut ByteWriter, clr2_flags: u16, clr2: [u16; 2]) -> EncoderResult<()> {
+ fn write_clr2(bw: &mut dyn ByteIO, clr2_flags: u16, clr2: [u16; 2]) -> EncoderResult<()> {
bw.write_u16le(clr2_flags)?;
bw.write_u16le(clr2[0])?;
bw.write_u16le(clr2[1])?;
Ok(())
}
- fn write_clr8(bw: &mut ByteWriter, mut clr8_flags: u16, mut clr8: [[u16; 4]; 4]) -> EncoderResult<()> {
+ fn write_clr8(bw: &mut dyn ByteIO, mut clr8_flags: u16, mut clr8: [[u16; 4]; 4]) -> EncoderResult<()> {
if (clr8_flags & 0x8000) != 0 {
clr8_flags ^= 0xFF00;
clr8[2].swap(0, 1);
}
}
}
- fn write_skips(bw: &mut ByteWriter, skips: usize) -> EncoderResult<()> {
+ fn write_skips(bw: &mut dyn ByteIO, skips: usize) -> EncoderResult<()> {
bw.write_u16le((skips as u16) | 0x8400)?;
Ok(())
}
- fn encode_inter_rgb555(bw: &mut ByteWriter, cur_frm: &mut NAVideoBuffer<u16>, in_frm: &NAVideoBuffer<u16>, prev_frm: &NAVideoBuffer<u16>, quality: u8) -> EncoderResult<bool> {
+ fn encode_inter_rgb555(bw: &mut dyn ByteIO, cur_frm: &mut NAVideoBuffer<u16>, in_frm: &NAVideoBuffer<u16>, prev_frm: &NAVideoBuffer<u16>, quality: u8) -> EncoderResult<bool> {
let (skip_threshold, fill_threshold) = map_quality_15bit(quality);
let mut is_intra = true;
let src = in_frm.get_data();
} //xxx: something for inter?
Ok(is_intra)
}
- fn encode_intra_rgb555(bw: &mut ByteWriter, cur_frm: &mut NAVideoBuffer<u16>, in_frm: &NAVideoBuffer<u16>, quality: u8) -> EncoderResult<bool> {
+ fn encode_intra_rgb555(bw: &mut dyn ByteIO, cur_frm: &mut NAVideoBuffer<u16>, in_frm: &NAVideoBuffer<u16>, quality: u8) -> EncoderResult<bool> {
let (_, fill_threshold) = map_quality_15bit(quality);
let src = in_frm.get_data();
let sstride = in_frm.get_stride(0);
bw.write_u16le(0)?;
Ok(true)
}
- fn encode_inter_pal(bw: &mut ByteWriter, cur_frm: &mut NAVideoBuffer<u8>, in_frm: &NAVideoBuffer<u8>, prev_frm: &NAVideoBuffer<u8>, quality: u8, pal: &[UnpackedPixel; 256], ls: &LocalSearch) -> EncoderResult<bool> {
+ fn encode_inter_pal(bw: &mut dyn ByteIO, cur_frm: &mut NAVideoBuffer<u8>, in_frm: &NAVideoBuffer<u8>, prev_frm: &NAVideoBuffer<u8>, quality: u8, pal: &[UnpackedPixel; 256], ls: &LocalSearch) -> EncoderResult<bool> {
let (skip_threshold, fill_threshold) = map_quality_pal(quality);
let mut is_intra = true;
let src = in_frm.get_data();
} //xxx: something for inter?
Ok(is_intra)
}
- fn encode_intra_pal(bw: &mut ByteWriter, cur_frm: &mut NAVideoBuffer<u8>, in_frm: &NAVideoBuffer<u8>, quality: u8, pal: &[UnpackedPixel; 256], ls: &LocalSearch) -> EncoderResult<bool> {
+ fn encode_intra_pal(bw: &mut dyn ByteIO, cur_frm: &mut NAVideoBuffer<u8>, in_frm: &NAVideoBuffer<u8>, quality: u8, pal: &[UnpackedPixel; 256], ls: &LocalSearch) -> EncoderResult<bool> {
let (_, fill_threshold) = map_quality_pal(quality);
let src = in_frm.get_data();
let sstride = in_frm.get_stride(0);
if frm.frame_type == FrameType::Skip {
if let Some(ref stream) = self.stream {
let mut dbuf = Vec::with_capacity(4);
- let mut gw = GrowableMemoryWriter::new_write(&mut dbuf);
- let mut bw = ByteWriter::new(&mut gw);
+ let mut bw = GrowableMemoryWriter::new_write(&mut dbuf);
let vinfo = stream.get_info().get_properties().get_video_info().unwrap();
let mut nskips = ((vinfo.get_width() + 3) / 4) * ((vinfo.get_height() + 3) / 4);
}
let mut cur_frm = self.pool15.get_free().unwrap();
let mut dbuf = Vec::with_capacity(4);
- let mut gw = GrowableMemoryWriter::new_write(&mut dbuf);
- let mut bw = ByteWriter::new(&mut gw);
+ let mut bw = GrowableMemoryWriter::new_write(&mut dbuf);
if self.frmcount == 0 {
self.lastfrm15 = None;
}
let mut cur_frm = self.pool8.get_free().unwrap();
let mut dbuf = Vec::with_capacity(4);
- let mut gw = GrowableMemoryWriter::new_write(&mut dbuf);
- let mut bw = ByteWriter::new(&mut gw);
+ let mut bw = GrowableMemoryWriter::new_write(&mut dbuf);
if self.frmcount == 0 {
self.lastfrm8 = None;
}