3 pub fn put_blocks(buf: &mut NAVideoBuffer<u8>, xpos: usize, ypos: usize, blk: &[[i16;64]; 6]) {
4 let stridey = buf.get_stride(0);
5 let strideu = buf.get_stride(1);
6 let stridev = buf.get_stride(2);
7 let mut idxy = buf.get_offset(0) + xpos * 16 + ypos * 16 * stridey;
8 let mut idxu = buf.get_offset(1) + xpos * 8 + ypos * 8 * strideu;
9 let mut idxv = buf.get_offset(2) + xpos * 8 + ypos * 8 * stridev;
11 let data = buf.get_data_mut().unwrap();
12 let framebuf: &mut [u8] = data.as_mut_slice();
16 let mut v = blk[0][k + j * 8];
17 if v < 0 { v = 0; } else if v > 255 { v = 255; }
18 framebuf[idxy + k] = v as u8;
21 let mut v = blk[1][k + j * 8];
22 if v < 0 { v = 0; } else if v > 255 { v = 255; }
23 framebuf[idxy + k + 8] = v as u8;
29 let mut v = blk[2][k + j * 8];
30 if v < 0 { v = 0; } else if v > 255 { v = 255; }
31 framebuf[idxy + k] = v as u8;
34 let mut v = blk[3][k + j * 8];
35 if v < 0 { v = 0; } else if v > 255 { v = 255; }
36 framebuf[idxy + k + 8] = v as u8;
43 let mut v = blk[4][k + j * 8];
44 if v < 0 { v = 0; } else if v > 255 { v = 255; }
45 framebuf[idxu + k] = v as u8;
48 let mut v = blk[5][k + j * 8];
49 if v < 0 { v = 0; } else if v > 255 { v = 255; }
50 framebuf[idxv + k] = v as u8;
57 pub fn add_blocks(buf: &mut NAVideoBuffer<u8>, xpos: usize, ypos: usize, blk: &[[i16;64]; 6]) {
58 let stridey = buf.get_stride(0);
59 let strideu = buf.get_stride(1);
60 let stridev = buf.get_stride(2);
61 let mut idxy = buf.get_offset(0) + xpos * 16 + ypos * 16 * stridey;
62 let mut idxu = buf.get_offset(1) + xpos * 8 + ypos * 8 * strideu;
63 let mut idxv = buf.get_offset(2) + xpos * 8 + ypos * 8 * stridev;
65 let data = buf.get_data_mut().unwrap();
66 let framebuf: &mut [u8] = data.as_mut_slice();
70 let mut v = blk[0][k + j * 8] + i16::from(framebuf[idxy + k]);
71 if v < 0 { v = 0; } else if v > 255 { v = 255; }
72 framebuf[idxy + k] = v as u8;
75 let mut v = blk[1][k + j * 8] + i16::from(framebuf[idxy + k + 8]);
76 if v < 0 { v = 0; } else if v > 255 { v = 255; }
77 framebuf[idxy + k + 8] = v as u8;
83 let mut v = blk[2][k + j * 8] + i16::from(framebuf[idxy + k]);
84 if v < 0 { v = 0; } else if v > 255 { v = 255; }
85 framebuf[idxy + k] = v as u8;
88 let mut v = blk[3][k + j * 8] + i16::from(framebuf[idxy + k + 8]);
89 if v < 0 { v = 0; } else if v > 255 { v = 255; }
90 framebuf[idxy + k + 8] = v as u8;
97 let mut v = blk[4][k + j * 8] + i16::from(framebuf[idxu + k]);
98 if v < 0 { v = 0; } else if v > 255 { v = 255; }
99 framebuf[idxu + k] = v as u8;
102 let mut v = blk[5][k + j * 8] + i16::from(framebuf[idxv + k]);
103 if v < 0 { v = 0; } else if v > 255 { v = 255; }
104 framebuf[idxv + k] = v as u8;
111 pub fn edge_emu(src: &NAVideoBuffer<u8>, xpos: isize, ypos: isize, bw: usize, bh: usize, dst: &mut [u8], dstride: usize, comp: usize) {
112 let stride = src.get_stride(comp);
113 let offs = src.get_offset(comp);
114 let (w, h) = src.get_dimensions(comp);
115 let data = src.get_data();
116 let framebuf: &[u8] = data.as_slice();
120 if (y as isize) + ypos < 0 { srcy = 0; }
121 else if (y as isize) + ypos >= (h as isize) { srcy = h - 1; }
122 else { srcy = ((y as isize) + ypos) as usize; }
126 if (x as isize) + xpos < 0 { srcx = 0; }
127 else if (x as isize) + xpos >= (w as isize) { srcx = w - 1; }
128 else { srcx = ((x as isize) + xpos) as usize; }
129 dst[x + y * dstride] = framebuf[offs + srcx + srcy * stride];
134 pub type BlkInterpFunc = fn(&mut [u8], usize, &[u8], usize, usize, usize);
136 pub fn copy_blocks(dst: &mut NAVideoBuffer<u8>, src: &NAVideoBuffer<u8>,
137 dx: usize, dy: usize, sx: isize, sy: isize, bw: usize, bh: usize,
138 preborder: usize, postborder: usize,
139 mode: usize, interp: &[BlkInterpFunc])
141 let pre = if mode != 0 { preborder as isize } else { 0 };
142 let post = if mode != 0 { postborder as isize } else { 0 };
143 let (w, h) = src.get_dimensions(0);
145 if (sx - pre < 0) || ((sx >> 1) - pre < 0) || (sx + (bw as isize) + post > (w as isize)) ||
146 (sy - pre < 0) || ((sy >> 1) - pre < 0) || (sy + (bh as isize) + post > (h as isize)) {
147 let ebuf_stride: usize = 32;
148 let mut ebuf: Vec<u8> = vec![0; ebuf_stride * (bh + ((pre + post) as usize))];
151 let dstride = dst.get_stride(comp);
152 let doff = dst.get_offset(comp);
153 let ddta = dst.get_data_mut().unwrap();
154 let dbuf: &mut [u8] = ddta.as_mut_slice();
155 let x = if comp > 0 { dx/2 } else { dx };
156 let y = if comp > 0 { dy/2 } else { dy };
157 let sx_ = (if comp > 0 { sx >> 1 } else { sx }) - pre;
158 let sy_ = (if comp > 0 { sy >> 1 } else { sy }) - pre;
159 let bw_ = (if comp > 0 { bw/2 } else { bw }) + ((pre + post) as usize);
160 let bh_ = (if comp > 0 { bh/2 } else { bh }) + ((pre + post) as usize);
161 edge_emu(src, sx_ - pre, sy_ - pre, bw_, bh_,
162 ebuf.as_mut_slice(), ebuf_stride, comp);
163 let bw_ = if comp > 0 { bw/2 } else { bw };
164 let bh_ = if comp > 0 { bh/2 } else { bh };
165 (interp[mode])(&mut dbuf[doff + x + y * dstride..], dstride, ebuf.as_slice(), ebuf_stride, bw_, bh_);
169 let sstride = src.get_stride(comp);
170 let soff = src.get_offset(comp);
171 let sdta = src.get_data();
172 let sbuf: &[u8] = sdta.as_slice();
173 let dstride = dst.get_stride(comp);
174 let doff = dst.get_offset(comp);
175 let ddta = dst.get_data_mut().unwrap();
176 let dbuf: &mut [u8] = ddta.as_mut_slice();
177 let x = if comp > 0 { dx/2 } else { dx };
178 let y = if comp > 0 { dy/2 } else { dy };
179 let sx_ = ((if comp > 0 { sx >> 1 } else { sx }) - pre) as usize;
180 let sy_ = ((if comp > 0 { sy >> 1 } else { sy }) - pre) as usize;
181 let bw_ = if comp > 0 { bw/2 } else { bw };
182 let bh_ = if comp > 0 { bh/2 } else { bh };
183 (interp[mode])(&mut dbuf[doff + x + y * dstride..], dstride, &sbuf[(soff + sx_ + sy_ * sstride)..], sstride, bw_, bh_);
188 pub fn copy_block(dst: &mut NASimpleVideoFrame<u8>, src: NAVideoBufferRef<u8>, comp: usize,
189 dx: usize, dy: usize, mv_x: i16, mv_y: i16, bw: usize, bh: usize,
190 preborder: usize, postborder: usize,
191 mode: usize, interp: &[BlkInterpFunc])
193 let pre = if mode != 0 { preborder as isize } else { 0 };
194 let post = if mode != 0 { postborder as isize } else { 0 };
195 let (w, h) = src.get_dimensions(comp);
196 let sx = (dx as isize) + (mv_x as isize);
197 let sy = (dy as isize) + (mv_y as isize);
199 if (sx - pre < 0) || (sx + (bw as isize) + post > (w as isize)) ||
200 (sy - pre < 0) || (sy + (bh as isize) + post > (h as isize)) {
201 let ebuf_stride: usize = 32;
202 let mut ebuf: Vec<u8> = vec![0; ebuf_stride * (bh + ((pre + post) as usize))];
204 let dstride = dst.stride[comp];
205 let doff = dst.offset[comp];
206 let edge = (pre + post) as usize;
207 edge_emu(&src, sx - pre, sy - pre, bw + edge, bh + edge,
208 ebuf.as_mut_slice(), ebuf_stride, comp);
209 (interp[mode])(&mut dst.data[doff + dx + dy * dstride..], dstride,
210 ebuf.as_slice(), ebuf_stride, bw, bh);
212 let sstride = src.get_stride(comp);
213 let soff = src.get_offset(comp);
214 let sdta = src.get_data();
215 let sbuf: &[u8] = sdta.as_slice();
216 let dstride = dst.stride[comp];
217 let doff = dst.offset[comp];
218 let saddr = soff + ((sx - pre) as usize) + ((sy - pre) as usize) * sstride;
219 (interp[mode])(&mut dst.data[doff + dx + dy * dstride..], dstride,
220 &sbuf[saddr..], sstride, bw, bh);