impl DeltaState {
fn apply_y(&mut self, dst: &mut [u8], mut yoff: usize, ystride: usize, ydeltas: &[i32; 16], last: &mut [i32]) {
for y in 0..4 {
impl DeltaState {
fn apply_y(&mut self, dst: &mut [u8], mut yoff: usize, ystride: usize, ydeltas: &[i32; 16], last: &mut [i32]) {
for y in 0..4 {
}
fn recalc_y(&mut self, dst: &[u8], yoff: usize, ystride: usize, last: &mut [i32]) {
let src = &dst[yoff+3..];
}
fn recalc_y(&mut self, dst: &[u8], yoff: usize, ystride: usize, last: &mut [i32]) {
let src = &dst[yoff+3..];
- self.dy[0] = (src[ystride * 0] as i32) - last[3];
- self.dy[1] = (src[ystride * 1] as i32) - (src[ystride * 0] as i32);
- self.dy[2] = (src[ystride * 2] as i32) - (src[ystride * 1] as i32);
- self.dy[3] = (src[ystride * 3] as i32) - (src[ystride * 2] as i32);
+ self.dy[0] = i32::from(src[ystride * 0]) - last[3];
+ self.dy[1] = i32::from(src[ystride * 1]) - i32::from(src[ystride * 0]);
+ self.dy[2] = i32::from(src[ystride * 2]) - i32::from(src[ystride * 1]);
+ self.dy[3] = i32::from(src[ystride * 3]) - i32::from(src[ystride * 2]);
}
}
fn recalc_c(&mut self, dst: &[i16], coff: usize, cstride: usize, idx: usize, last: &mut [i32]) {
}
}
fn recalc_c(&mut self, dst: &[i16], coff: usize, cstride: usize, idx: usize, last: &mut [i32]) {
- self.dc[idx][0] = (dst[coff + 1] as i32) - last[1];
- self.dc[idx][1] = (dst[coff + 1 + cstride] as i32) - (dst[coff + 1] as i32);
- last[0] = dst[coff + cstride + 0] as i32;
- last[1] = dst[coff + cstride + 1] as i32;
+ self.dc[idx][0] = i32::from(dst[coff + 1]) - last[1];
+ self.dc[idx][1] = i32::from(dst[coff + 1 + cstride]) - i32::from(dst[coff + 1]);
+ last[0] = i32::from(dst[coff + cstride + 0]);
+ last[1] = i32::from(dst[coff + cstride + 1]);
fn alloc(width: usize, height: usize) -> Self {
let ystride = (width + 3) & !3;
let ysize = ystride * ((height + 3) & !3);
fn alloc(width: usize, height: usize) -> Self {
let ystride = (width + 3) & !3;
let ysize = ystride * ((height + 3) & !3);
- let mut udata = Vec::with_capacity(csize);
- udata.resize(csize, 0);
- let mut vdata = Vec::with_capacity(csize);
- vdata.resize(csize, 0);
- Self { ydata, udata, vdata, ystride, cstride }
+ Self { ydata: vec![0; ysize], udata: vec![0; csize], vdata: vec![0; csize], ystride, cstride }
- let mut lasty: Vec<i32> = Vec::with_capacity(self.width + 1);
- lasty.resize(self.width + 1, 0);
- let mut lastu: Vec<i32> = Vec::with_capacity(self.width/2 + 1);
- lastu.resize(self.width/2 + 1, 0);
- let mut lastv: Vec<i32> = Vec::with_capacity(self.width/2 + 1);
- lastv.resize(self.width/2 + 1, 0);
+ let mut lasty: Vec<i32> = vec![0; self.width + 1];
+ let mut lastu: Vec<i32> = vec![0; self.width/2 + 1];
+ let mut lastv: Vec<i32> = vec![0; self.width/2 + 1];
fmt.get_chromaton(1).unwrap().get_offset() as usize,
fmt.get_chromaton(2).unwrap().get_offset() as usize];
let stride = buf.get_stride(0);
fmt.get_chromaton(1).unwrap().get_offset() as usize,
fmt.get_chromaton(2).unwrap().get_offset() as usize];
let stride = buf.get_stride(0);
for y in 0..self.height {
let out = &mut dst[off..];
for (x, pic) in out.chunks_exact_mut(3).take(self.width).enumerate() {
for y in 0..self.height {
let out = &mut dst[off..];
for (x, pic) in out.chunks_exact_mut(3).take(self.width).enumerate() {
let u = self.cur_frame.udata[csrc + (x >> 1)];
let v = self.cur_frame.vdata[csrc + (x >> 1)];
pic[offs[0]] = (y + u).max(0).min(255) as u8;
let u = self.cur_frame.udata[csrc + (x >> 1)];
let v = self.cur_frame.vdata[csrc + (x >> 1)];
pic[offs[0]] = (y + u).max(0).min(255) as u8;
if let NACodecTypeInfo::Video(vinfo) = info.get_properties() {
let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), false, YUV410_FORMAT));
self.width = vinfo.get_width();
self.height = vinfo.get_height();
self.cur_frame = TM2Frame::alloc(self.width, self.height);
self.prev_frame = TM2Frame::alloc(self.width, self.height);
if let NACodecTypeInfo::Video(vinfo) = info.get_properties() {
let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), false, YUV410_FORMAT));
self.width = vinfo.get_width();
self.height = vinfo.get_height();
self.cur_frame = TM2Frame::alloc(self.width, self.height);
self.prev_frame = TM2Frame::alloc(self.width, self.height);
let src = pkt.get_buffer();
validate!(src.len() >= 40 + (TM2StreamType::Num as usize) * 4 + 4);
let mut mr = MemoryReader::new_read(&src);
let src = pkt.get_buffer();
validate!(src.len() >= 40 + (TM2StreamType::Num as usize) * 4 + 4);
let mut mr = MemoryReader::new_read(&src);
}
let myinfo = NAVideoInfo::new(self.width, self.height, false, RGB24_FORMAT);
}
let myinfo = NAVideoInfo::new(self.width, self.height, false, RGB24_FORMAT);
- let bufret = alloc_video_buffer(myinfo, 2);
- if let Err(_) = bufret { return Err(DecoderError::InvalidData); }
- let bufinfo = bufret.unwrap();
+ let bufinfo = alloc_video_buffer(myinfo, 2)?;
let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), bufinfo);
frm.set_keyframe(is_intra);
frm.set_frame_type(if is_intra { FrameType::I } else { FrameType::P });
let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), bufinfo);
frm.set_keyframe(is_intra);
frm.set_frame_type(if is_intra { FrameType::I } else { FrameType::P });