if capacity < self.num_mb {
self.obmc_blk.reserve(self.num_mb - capacity);
}
- self.obmc_blk.truncate(0);
+ self.obmc_blk.clear();
}
if self.has_b {
- self.mv_data.truncate(0);
+ self.mv_data.clear();
}
let save_b_data = pinfo.mode.is_ref() && self.may_have_b_frames;
if save_b_data {
- self.mv_data.truncate(0);
+ self.mv_data.clear();
}
let is_b = pinfo.mode == Type::B;
let mut mb_pos = 0;
let apply_acpred = /*(pinfo.mode == Type::I) && */pinfo.plusinfo.is_some() && pinfo.plusinfo.unwrap().aic;
if apply_acpred {
- self.pred_coeffs.truncate(0);
+ self.pred_coeffs.clear();
if !self.pred_quant {
self.pred_coeffs.resize(self.mb_w * self.mb_h, ZERO_PRED_COEFFS);
} else {
recon_b_frame(b_buf, bck_buf.clone(), fwd_buf.clone(), self.mb_w, self.mb_h, self.b_data.as_slice(), bdsp);
}
- self.b_data.truncate(0);
+ self.b_data.clear();
Ok(bufinfo)
}
}
fn new() -> Self { CBPInfo{ cbp: Vec::new(), q: Vec::new(), mb_w: 0 } }
fn reset(&mut self, mb_w: usize) {
self.mb_w = mb_w;
- self.cbp.truncate(0);
+ self.cbp.clear();
self.cbp.resize(self.mb_w * 2, 0);
- self.q.truncate(0);
+ self.q.clear();
self.q.resize(self.mb_w * 2, 0);
}
fn update_row(&mut self) {
pub fn full_size(&self) -> usize { self.stride * (self.height + 1) + 1 }
/// Resets the cache state.
pub fn reset(&mut self) {
- self.data.truncate(0);
+ self.data.clear();
let size = self.full_size();
self.data.resize(size, self.default);
self.xpos = self.stride + 1;
}
// put points into the nearest clusters
- indices.truncate(0);
+ indices.clear();
for entry in entries.iter() {
let mut bestidx = 0;
let mut bestdist = std::u32::MAX;
}
let dmean = dist / (dst.len() as u64);
- low_u.truncate(0);
- high_u.truncate(0);
+ low_u.clear();
+ high_u.clear();
let mut used = vec![false; dst.len()];
for (i, cluster) in self.clusters.iter().enumerate() {
if cluster.dist < dmean {
}
}
fn reset(&mut self) {
- self.masks.truncate(0);
+ self.masks.clear();
self.mask = 0;
self.pos = 0;
}
let mut voff = in_frm.get_offset(2) + start / 2 * vstride;
let (width, _) = in_frm.get_dimensions(0);
let data = in_frm.get_data();
- self.v1_entries.truncate(0);
- self.v4_entries.truncate(0);
+ self.v1_entries.clear();
+ self.v4_entries.clear();
for _ in (start..end).step_by(4) {
for x in (0..width).step_by(4) {
let mut yblk = [0; 16];
}
}
fn calc_skip_dist(&mut self, in_frm: &NAVideoBuffer<u8>, start: usize, end: usize) {
- self.skip_dist.truncate(0);
+ self.skip_dist.clear();
if let Some(ref ref_frm) = self.lastfrm {
let rystride = ref_frm.get_stride(0);
let mut ryoff = ref_frm.get_offset(0) + start * rystride;
}
}
- self.v1_idx.truncate(0);
- self.v4_idx.truncate(0);
+ self.v1_idx.clear();
+ self.v4_idx.clear();
self.masks.reset();
for (v1_entry, v4_entries) in self.v1_entries.iter().zip(self.v4_entries.chunks(4)) {
}
}
- self.v1_idx.truncate(0);
- self.v4_idx.truncate(0);
+ self.v1_idx.clear();
+ self.v4_idx.clear();
self.masks.reset();
let mut skip_iter = self.skip_dist.iter();
}
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);
}
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);
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;
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);
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);
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);
validate!(tb_num != 0);
track.rescale(tb_num);
} else {
- track.time_to_sample.truncate(0);
+ track.time_to_sample.clear();
track.time_to_sample.reserve(entries);
for _ in 0..entries {
let count = br.read_u32be()?;
impl<T:Default+Copy> RLESearcher<T> {
fn new() -> Self { Self::default() }
fn resize(&mut self, size: usize) {
- self.array.truncate(0);
+ self.array.clear();
self.array.reserve(size);
}
fn reserve(&mut self, size: usize) {
self.bw.write_u32le(0)?; // reserved
self.bw.write_u32le(0)?; // reserved
- self.pal_pos.truncate(0);
+ self.pal_pos.clear();
self.pal_pos.resize(strmgr.get_num_streams(), 0);
for (strno, str) in strmgr.iter().enumerate() {
let strl_pos = self.bw.tell() + 8;
let mask_bits = &src[hdr_size..][..mask_size];
let index_bytes = &src[hdr_size+mask_size..];
validate!(src.len() >= hdr_size + mask_size);
- self.vert_pred.truncate(0);
+ self.vert_pred.clear();
self.vert_pred.resize(out_width, 0);
if is_intra || is_sprite {
impl TM2Stream {
fn read_header(&mut self, src: &[u8], br: &mut ByteReader) -> DecoderResult<()> {
- self.tokens.truncate(0);
+ self.tokens.clear();
self.pos = 0;
let len = br.read_u32le()? as usize;
}
self.apts = 0;
self.vpts = 0;
- self.side_data.truncate(0);
+ self.side_data.clear();
Ok(())
}
fn reset(&mut self) {
self.width = 0;
self.height = 0;
- self.sbuf.truncate(0);
- self.dbuf.truncate(0);
+ self.sbuf.clear();
+ self.dbuf.clear();
}
fn alloc(&mut self, w: usize, h: usize) {
self.width = w;
let nvec = br.read_u32le()?;
validate!(nvec == 0); // for intra there should be no mc_vecs
- self.mvs.truncate(0);
+ self.mvs.clear();
for _ in 0..nvec {
let x = br.read_byte()? as i8;
let y = br.read_byte()? as i8;
let nvec = br.read_u32le()?;
validate!(nvec <= 256); // for intra there should be no mc_vecs
- self.mvs.truncate(0);
+ self.mvs.clear();
for _ in 0..nvec {
let y = br.read_byte()? as i8;
let x = br.read_byte()? as i8;
fn realloc(&mut self, pic_hdr: &PictureHeader) -> DecoderResult<()> {
let planes = if pic_hdr.transparent { 4 } else { 3 };
- //self.bands.truncate(0);
- self.tiles.truncate(0);
+ //self.bands.clear();
+ self.tiles.clear();
self.num_tiles = [[0; 4]; 4];
self.tile_start = [[0; 4]; 4];
let mut tstart: usize = 0;
let mb_h = (tile.h + mb_size - 1) / mb_size;
tile.mb_w = mb_w;
tile.mb_h = mb_h;
- tile.mb.truncate(0);
+ tile.mb.clear();
tile.mb.resize(mb_w * mb_h, MB::new(0, 0));
}
fn unescape_nal(src: &[u8], dst: &mut Vec<u8>) -> usize {
let mut off = 0;
let mut zrun = 0;
- dst.truncate(0);
+ dst.clear();
dst.reserve(src.len());
while off < src.len() {
dst.push(src[off]);
self.long_term.resize(arg1 as usize, None);
},
5 => {
- self.ref_pics.truncate(0);
- self.long_term.truncate(0);
+ self.ref_pics.clear();
+ self.long_term.clear();
},
6 => {
// assign an long term index to current pic - done elsewhere
Ok(())
}
pub fn clear_refs(&mut self) {
- self.ref_pics.truncate(0);
- self.long_term.truncate(0);
+ self.ref_pics.clear();
+ self.long_term.clear();
}
#[allow(clippy::cognitive_complexity)]
pub fn select_refs(&mut self, sps: &SeqParameterSet, slice_hdr: &SliceHeader, cur_id: u32) {
- self.ref_list0.truncate(0);
- self.ref_list1.truncate(0);
+ self.ref_list0.clear();
+ self.ref_list1.clear();
let pic_num_mask = if sps.log2_max_frame_num == 16 {
0xFFFF
} else {
}
fn read_nal(src: &mut ByteReader, dst: &mut Vec<u8>) -> DemuxerResult<()> {
- dst.truncate(0);
+ dst.clear();
loop {
let b = src.read_byte()?;
if b == 0 {
let mut buf: Vec<u8> = Vec::with_capacity(65536);
if !self.frame_buf.is_empty() {
put_nal(&mut buf, &self.frame_buf);
- self.frame_buf.truncate(0);
+ self.frame_buf.clear();
}
let strres = strmgr.get_stream(0);
if strres.is_none() {
validate!(nblocks > 0);
let bits = u32::from(pktbuf[4]);
validate!(bits < 32);
- self.data.truncate(0);
+ self.data.clear();
self.data.reserve((pktbuf.len() & !3) + 2);
for word in pktbuf[8..].chunks_exact(4) {
self.data.push(word[3]);
self.block_samps = (self.block_len / channels - 7) * 2 + 2;
self.ainfo = NAAudioInfo::new(ainfo.get_sample_rate(), channels as u8, SND_S16P_FORMAT, self.block_samps);
self.chmap = NAChannelMap::from_str(if channels == 1 { "C" } else { "L,R" }).unwrap();
- self.adapt_coeffs.truncate(0);
+ self.adapt_coeffs.clear();
if let Some(ref buf) = info.get_extradata() {
validate!(buf.len() >= 6);
validate!((buf.len() & 3) == 0);
}
fn read_wave_data(&mut self, br: &mut BitReader) -> DecoderResult<()> {
for tone in self.tones.iter_mut() {
- tone.truncate(0);
+ tone.clear();
}
for group in 0..5 {
let group_size = 1 << (self.frame_bits - group - 1);
((self.width / 4 + 15) & !15, (self.height / 4 + 15) & !15)
};
let mvstride = w / 8;
- self.mvs.truncate(0);
+ self.mvs.clear();
self.mvs.resize(mvstride * (h / 8), ZERO_MV);
let mut mv_idx = 0;
}
fn reset(&mut self) {
let size = self.w * self.h;
- self.mv_f.truncate(0);
+ self.mv_f.clear();
self.mv_f.resize(size, ZERO_MV);
- self.mv_b.truncate(0);
+ self.mv_b.clear();
self.mv_b.resize(size, ZERO_MV);
- self.has_f.truncate(0);
+ self.has_f.clear();
self.has_f.resize(size >> 4, false);
- self.has_b.truncate(0);
+ self.has_b.clear();
self.has_b.resize(size >> 4, false);
}
fn fill(&mut self, mb_x: usize, mb_y: usize, fwd: bool, mv: MV) {
};
let slice_len = length + llen + 1;
validate!(src.len() >= slice_len);
- self.slice_buf.truncate(0);
+ self.slice_buf.clear();
if llen > 1 {
self.slice_buf.extend_from_slice(&src[slice_len - llen + 1..][..llen - 1]);
}
}
}
fn reset_state(&mut self) {
- self.queued_packets.truncate(0);
+ self.queued_packets.clear();
}
}
let table_bits = ((self.pkt_buf[0] as usize) << 8) | (self.pkt_buf[1] as usize);
let table_bytes = (table_bits + 7) >> 3;
validate!(src_len > table_bytes + 3);
- self.blocks.truncate(0);
+ self.blocks.clear();
{
let mut br = BitReader::new(&self.pkt_buf[2..][..table_bytes], BitReaderMode::BE);
while br.tell() < table_bits {
}
fn reset(&mut self) {
let size = self.w * self.h;
- self.mv_f.truncate(0);
+ self.mv_f.clear();
self.mv_f.resize(size, ZERO_MV);
- self.mv_b.truncate(0);
+ self.mv_b.clear();
self.mv_b.resize(size, ZERO_MV);
- self.has_f.truncate(0);
+ self.has_f.clear();
self.has_f.resize(size >> 2, false);
- self.has_b.truncate(0);
+ self.has_b.clear();
self.has_b.resize(size >> 2, false);
}
fn fill(&mut self, mb_x: usize, mb_y: usize, fwd: bool, mv: MV) {
fn parse_slice_offsets(src: &[u8], offsets: &mut Vec<usize>) -> DecoderResult<()> {
let num_slices = (src[0] as usize) + 1;
let ini_off = num_slices * 8 + 1;
- offsets.truncate(0);
+ offsets.clear();
if ini_off >= src.len() { return Err(DecoderError::ShortData); }
signs.push(sign);
}
validate!(signs[0]);
- sizes.truncate(0);
+ sizes.clear();
let mut sum = 0;
let first_size = br.read(nbits)? as usize;
validate!(first_size > 0);
self.pu_stride = cu_w << 3;
self.pu_info.resize(self.pu_stride * (cu_h << 3), PUInfo::default());
self.blk_stride = cu_w << 4;
- self.blk_info.truncate(0);
+ self.blk_info.clear();
self.blk_info.resize(self.blk_stride * (cu_h << 4), BlockInfo::default());
if hdr.deblock {
self.dblk.reinit(hdr.width, hdr.height);
}
}
fn flush(&mut self) {
- self.frame.truncate(0);
+ self.frame.clear();
self.frame_size = 0;
self.frame_pos = 0;
}