]>
Commit | Line | Data |
---|---|---|
47527732 KS |
1 | #[allow(dead_code)] |
2 | #[derive(Debug,Clone,Copy)] | |
3 | pub enum PredType4x4 { | |
4 | Ver, | |
5 | Hor, | |
6 | DC, | |
7 | DiagDownLeft, | |
8 | DiagDownRight, | |
9 | VerRight, | |
10 | HorDown, | |
11 | VerLeft, | |
12 | HorUp, | |
13 | LeftDC, | |
14 | TopDC, | |
15 | DC128, | |
16 | DiagDownLeftNoDown, | |
17 | HorUpNoDown, | |
18 | VerLeftNoDown | |
19 | } | |
20 | ||
21 | #[allow(dead_code)] | |
22 | #[derive(Debug,Clone,Copy)] | |
23 | pub enum PredType8x8 { | |
24 | DC, | |
25 | Hor, | |
26 | Ver, | |
27 | Plane, | |
28 | LeftDC, | |
29 | TopDC, | |
30 | DC128 | |
31 | } | |
32 | ||
e07387c7 KS |
33 | type IPred4x4Func = fn(buf: &mut [u8], idx: usize, stride: usize, tr: &[u8]); |
34 | ||
47527732 | 35 | pub struct RV34CommonDSP { |
e07387c7 | 36 | pub ipred4x4: [IPred4x4Func; 15], |
47527732 KS |
37 | pub ipred8x8: [fn(buf: &mut [u8], idx: usize, stride: usize); 7], |
38 | pub ipred16x16: [fn(buf: &mut [u8], idx: usize, stride: usize); 7], | |
39 | } | |
40 | ||
61d3e294 | 41 | #[allow(clippy::erasing_op)] |
47527732 KS |
42 | fn row_transform(src: &[i16], dst: &mut [i32]) { |
43 | for i in 0..4 { | |
44 | let z0 = 13 * ((src[i + 4*0] as i32) + (src[i + 4*2] as i32)); | |
45 | let z1 = 13 * ((src[i + 4*0] as i32) - (src[i + 4*2] as i32)); | |
46 | let z2 = 7 * (src[i + 4*1] as i32) - 17 * (src[i + 4*3] as i32); | |
47 | let z3 = 17 * (src[i + 4*1] as i32) + 7 * (src[i + 4*3] as i32); | |
48 | dst[4 * i + 0] = z0 + z3; | |
49 | dst[4 * i + 1] = z1 + z2; | |
50 | dst[4 * i + 2] = z1 - z2; | |
51 | dst[4 * i + 3] = z0 - z3; | |
52 | } | |
53 | } | |
54 | ||
55 | fn clip8(a: i16) -> u8 { | |
56 | if a < 0 { 0 } | |
57 | else if a > 255 { 255 } | |
58 | else { a as u8 } | |
59 | } | |
60 | ||
61 | #[inline(always)] | |
62 | fn mclip8(a: i32) -> u8 { | |
63 | if (a as u32) > 255 { !(a >> 16) as u8 } | |
64 | else { a as u8 } | |
65 | } | |
66 | ||
61d3e294 | 67 | #[allow(clippy::erasing_op)] |
47527732 KS |
68 | impl RV34CommonDSP { |
69 | pub fn new() -> Self { | |
70 | Self { | |
71 | ipred4x4: IPRED_FUNCS4X4, | |
72 | ipred8x8: IPRED_FUNCS8X8, | |
73 | ipred16x16: IPRED_FUNCS16X16, | |
74 | } | |
75 | } | |
76 | pub fn add_coeffs(&self, dst: &mut [u8], idx: usize, stride: usize, coeffs: &[i16]) { | |
77 | let out = &mut dst[idx..][..stride * 3 + 4]; | |
78 | let mut sidx: usize = 0; | |
79 | for el in out.chunks_mut(stride).take(4) { | |
80 | assert!(el.len() >= 4); | |
81 | el[0] = mclip8((el[0] as i32) + (coeffs[0 + sidx] as i32)); | |
82 | el[1] = mclip8((el[1] as i32) + (coeffs[1 + sidx] as i32)); | |
83 | el[2] = mclip8((el[2] as i32) + (coeffs[2 + sidx] as i32)); | |
84 | el[3] = mclip8((el[3] as i32) + (coeffs[3 + sidx] as i32)); | |
85 | sidx += 4; | |
86 | } | |
87 | } | |
88 | pub fn transform(&self, coeffs: &mut [i16]) { | |
89 | let mut tmp: [i32; 16] = [0; 16]; | |
90 | row_transform(coeffs, &mut tmp); | |
91 | for i in 0..4 { | |
92 | let z0 = 13*(tmp[4*0+i] + tmp[4*2+i]) + 0x200; | |
93 | let z1 = 13*(tmp[4*0+i] - tmp[4*2+i]) + 0x200; | |
94 | let z2 = 7* tmp[4*1+i] - 17*tmp[4*3+i]; | |
95 | let z3 = 17* tmp[4*1+i] + 7*tmp[4*3+i]; | |
96 | coeffs[i * 4 + 0] = ((z0 + z3) >> 10) as i16; | |
97 | coeffs[i * 4 + 1] = ((z1 + z2) >> 10) as i16; | |
98 | coeffs[i * 4 + 2] = ((z1 - z2) >> 10) as i16; | |
99 | coeffs[i * 4 + 3] = ((z0 - z3) >> 10) as i16; | |
100 | } | |
101 | } | |
102 | pub fn transform_dc(&self, coeffs: &mut [i16]) { | |
103 | let val = (((coeffs[0] as i32) * 13 * 13 + 0x200) >> 10) as i16; | |
104 | for i in 0..16 { coeffs[i] = val; } | |
105 | } | |
106 | pub fn transform16(&self, coeffs: &mut [i16]) { | |
107 | let mut tmp: [i32; 16] = [0; 16]; | |
108 | row_transform(coeffs, &mut tmp); | |
109 | for i in 0..4 { | |
110 | let z0 = 39*(tmp[4*0+i] + tmp[4*2+i]); | |
111 | let z1 = 39*(tmp[4*0+i] - tmp[4*2+i]); | |
112 | let z2 = 21* tmp[4*1+i] - 51*tmp[4*3+i]; | |
113 | let z3 = 51* tmp[4*1+i] + 21*tmp[4*3+i]; | |
114 | ||
115 | coeffs[i * 4 + 0] = ((z0 + z3) >> 11) as i16; | |
116 | coeffs[i * 4 + 1] = ((z1 + z2) >> 11) as i16; | |
117 | coeffs[i * 4 + 2] = ((z1 - z2) >> 11) as i16; | |
118 | coeffs[i * 4 + 3] = ((z0 - z3) >> 11) as i16; | |
119 | } | |
120 | } | |
121 | pub fn transform16_dc(&self, coeffs: &mut [i16]) { | |
122 | let val = (((coeffs[0] as i32) * 13 * 13 * 3) >> 11) as i16; | |
123 | for i in 0..16 { coeffs[i] = val; } | |
124 | } | |
125 | pub fn weight(&self, dst: &mut [u8], mut didx: usize, dstride: usize, | |
126 | src: &[u8], mut sidx: usize, sstride: usize, ratio1: u32, ratio2: u32, | |
127 | size: usize) { | |
128 | for _ in 0..size { | |
129 | for x in 0..size { | |
130 | dst[didx + x] = (((((dst[didx + x] as u32) * ratio1) >> 9) | |
131 | + (((src[sidx + x] as u32) * ratio2) >> 9) + 0x10) >> 5) as u8; | |
132 | } | |
133 | didx += dstride; | |
134 | sidx += sstride; | |
135 | } | |
136 | } | |
137 | pub fn avg(&self, dst: &mut [u8], mut didx: usize, dstride: usize, | |
138 | src: &[u8], mut sidx: usize, sstride: usize, | |
139 | size: usize) { | |
140 | for _ in 0..size { | |
141 | for x in 0..size { | |
142 | dst[didx + x] = (((dst[didx + x] as u16) + (src[sidx + x] as u16) + 1) >> 1) as u8; | |
143 | } | |
144 | didx += dstride; | |
145 | sidx += sstride; | |
146 | } | |
147 | } | |
148 | } | |
149 | ||
150 | fn ipred_dc128(buf: &mut [u8], mut idx: usize, stride: usize, bsize: usize) { | |
151 | for _ in 0..bsize { | |
152 | for x in 0..bsize { buf[idx + x] = 128; } | |
153 | idx += stride; | |
154 | } | |
155 | } | |
156 | fn ipred_ver(buf: &mut [u8], mut idx: usize, stride: usize, bsize: usize) { | |
157 | let oidx = idx - stride; | |
158 | for _ in 0..bsize { | |
159 | for x in 0..bsize { buf[idx + x] = buf[oidx + x]; } | |
160 | idx += stride; | |
161 | } | |
162 | } | |
163 | fn ipred_hor(buf: &mut [u8], mut idx: usize, stride: usize, bsize: usize) { | |
164 | for _ in 0..bsize { | |
165 | for x in 0..bsize { buf[idx + x] = buf[idx - 1]; } | |
166 | idx += stride; | |
167 | } | |
168 | } | |
169 | fn ipred_dc(buf: &mut [u8], mut idx: usize, stride: usize, bsize: usize, shift: u8) { | |
170 | let mut adc: u16 = 0; | |
171 | for i in 0..bsize { adc += buf[idx - stride + i] as u16; } | |
172 | for i in 0..bsize { adc += buf[idx - 1 + i * stride] as u16; } | |
173 | let dc = ((adc + (1 << (shift - 1))) >> shift) as u8; | |
174 | ||
175 | for _ in 0..bsize { | |
176 | for x in 0..bsize { buf[idx + x] = dc; } | |
177 | idx += stride; | |
178 | } | |
179 | } | |
180 | fn ipred_left_dc(buf: &mut [u8], mut idx: usize, stride: usize, bsize: usize, shift: u8) { | |
181 | let mut adc: u16 = 0; | |
182 | for i in 0..bsize { adc += buf[idx - 1 + i * stride] as u16; } | |
183 | let dc = ((adc + (1 << (shift - 1))) >> shift) as u8; | |
184 | ||
185 | for _ in 0..bsize { | |
186 | for x in 0..bsize { buf[idx + x] = dc; } | |
187 | idx += stride; | |
188 | } | |
189 | } | |
190 | fn ipred_top_dc(buf: &mut [u8], mut idx: usize, stride: usize, bsize: usize, shift: u8) { | |
191 | let mut adc: u16 = 0; | |
192 | for i in 0..bsize { adc += buf[idx - stride + i] as u16; } | |
193 | let dc = ((adc + (1 << (shift - 1))) >> shift) as u8; | |
194 | ||
195 | for _ in 0..bsize { | |
196 | for x in 0..bsize { buf[idx + x] = dc; } | |
197 | idx += stride; | |
198 | } | |
199 | } | |
200 | ||
201 | fn load_top(dst: &mut [u16], buf: &mut [u8], idx: usize, stride: usize, len: usize) { | |
202 | for i in 0..len { dst[i] = buf[idx - stride + i] as u16; } | |
203 | } | |
204 | fn load_left(dst: &mut [u16], buf: &mut [u8], idx: usize, stride: usize, len: usize) { | |
205 | for i in 0..len { dst[i] = buf[idx - 1 + i * stride] as u16; } | |
206 | } | |
207 | ||
208 | fn ipred_4x4_ver(buf: &mut [u8], idx: usize, stride: usize, _tr: &[u8]) { | |
209 | ipred_ver(buf, idx, stride, 4); | |
210 | } | |
211 | fn ipred_4x4_hor(buf: &mut [u8], idx: usize, stride: usize, _tr: &[u8]) { | |
212 | ipred_hor(buf, idx, stride, 4); | |
213 | } | |
214 | fn ipred_4x4_diag_down_left(buf: &mut [u8], idx: usize, stride: usize, tr: &[u8]) { | |
215 | let mut t: [u16; 8] = [0; 8]; | |
216 | let mut l: [u16; 8] = [0; 8]; | |
217 | load_top(&mut t, buf, idx, stride, 4); | |
218 | for i in 0..4 { t[i + 4] = tr[i] as u16; } | |
219 | load_left(&mut l, buf, idx, stride, 8); | |
220 | let dst = &mut buf[idx..]; | |
221 | ||
222 | dst[0 + 0 * stride] = ((t[0] + t[2] + 2*t[1] + 2 + l[0] + l[2] + 2*l[1] + 2) >> 3) as u8; | |
223 | let pix = ((t[1] + t[3] + 2*t[2] + 2 + l[1] + l[3] + 2*l[2] + 2) >> 3) as u8; | |
224 | dst[1 + 0 * stride] = pix; | |
225 | dst[0 + 1 * stride] = pix; | |
226 | let pix = ((t[2] + t[4] + 2*t[3] + 2 + l[2] + l[4] + 2*l[3] + 2) >> 3) as u8; | |
227 | dst[2 + 0 * stride] = pix; | |
228 | dst[1 + 1 * stride] = pix; | |
229 | dst[0 + 2 * stride] = pix; | |
230 | let pix = ((t[3] + t[5] + 2*t[4] + 2 + l[3] + l[5] + 2*l[4] + 2) >> 3) as u8; | |
231 | dst[3 + 0 * stride] = pix; | |
232 | dst[2 + 1 * stride] = pix; | |
233 | dst[1 + 2 * stride] = pix; | |
234 | dst[0 + 3 * stride] = pix; | |
235 | let pix = ((t[4] + t[6] + 2*t[5] + 2 + l[4] + l[6] + 2*l[5] + 2) >> 3) as u8; | |
236 | dst[3 + 1 * stride] = pix; | |
237 | dst[2 + 2 * stride] = pix; | |
238 | dst[1 + 3 * stride] = pix; | |
239 | let pix = ((t[5] + t[7] + 2*t[6] + 2 + l[5] + l[7] + 2*l[6] + 2) >> 3) as u8; | |
240 | dst[3 + 2 * stride] = pix; | |
241 | dst[2 + 3 * stride] = pix; | |
242 | dst[3 + 3 * stride] = ((t[6] + t[7] + 1 + l[6] + l[7] + 1) >> 2) as u8; | |
243 | } | |
244 | fn ipred_4x4_diag_down_left_nodown(buf: &mut [u8], idx: usize, stride: usize, tr: &[u8]) { | |
245 | let mut t: [u16; 8] = [0; 8]; | |
246 | let mut l: [u16; 4] = [0; 4]; | |
247 | load_top(&mut t, buf, idx, stride, 4); | |
248 | for i in 0..4 { t[i + 4] = tr[i] as u16; } | |
249 | load_left(&mut l, buf, idx, stride, 4); | |
250 | let dst = &mut buf[idx..]; | |
251 | ||
252 | dst[0 + 0 * stride] = ((t[0] + t[2] + 2*t[1] + 2 + l[0] + l[2] + 2*l[1] + 2) >> 3) as u8; | |
253 | let pix = ((t[1] + t[3] + 2*t[2] + 2 + l[1] + l[3] + 2*l[2] + 2) >> 3) as u8; | |
254 | dst[1 + 0 * stride] = pix; | |
255 | dst[0 + 1 * stride] = pix; | |
256 | let pix = ((t[2] + t[4] + 2*t[3] + 2 + l[2] + 3*l[3] + 2) >> 3) as u8; | |
257 | dst[2 + 0 * stride] = pix; | |
258 | dst[1 + 1 * stride] = pix; | |
259 | dst[0 + 2 * stride] = pix; | |
260 | let pix = ((t[3] + t[5] + 2*t[4] + 2 + l[3]*4 + 2) >> 3) as u8; | |
261 | dst[3 + 0 * stride] = pix; | |
262 | dst[2 + 1 * stride] = pix; | |
263 | dst[1 + 2 * stride] = pix; | |
264 | dst[0 + 3 * stride] = pix; | |
265 | let pix = ((t[4] + t[6] + 2*t[5] + 2 + l[3]*4 + 2) >> 3) as u8; | |
266 | dst[3 + 1 * stride] = pix; | |
267 | dst[2 + 2 * stride] = pix; | |
268 | dst[1 + 3 * stride] = pix; | |
269 | let pix = ((t[5] + t[7] + 2*t[6] + 2 + l[3]*4 + 2) >> 3) as u8; | |
270 | dst[3 + 2 * stride] = pix; | |
271 | dst[2 + 3 * stride] = pix; | |
272 | dst[3 + 3 * stride] = ((t[6] + t[7] + 1 + 2*l[3] + 1) >> 2) as u8; | |
273 | } | |
274 | fn ipred_4x4_diag_down_right(buf: &mut [u8], idx: usize, stride: usize, _tr: &[u8]) { | |
275 | let mut t: [u16; 5] = [0; 5]; | |
276 | let mut l: [u16; 5] = [0; 5]; | |
277 | load_top(&mut t, buf, idx - 1, stride, 5); | |
278 | load_left(&mut l, buf, idx - stride, stride, 5); | |
279 | let dst = &mut buf[idx..]; | |
280 | ||
281 | for j in 0..4 { | |
282 | for i in 0..j { | |
283 | dst[i + j * stride] = ((l[j - i - 1] + 2 * l[j - i] + l[j - i + 1] + 2) >> 2) as u8; | |
284 | } | |
285 | dst[j + j * stride] = ((l[1] + 2 * l[0] + t[1] + 2) >> 2) as u8; | |
286 | for i in (j+1)..4 { | |
287 | dst[i + j * stride] = ((t[i - j - 1] + 2 * t[i - j] + t[i - j + 1] + 2) >> 2) as u8; | |
288 | } | |
289 | } | |
290 | } | |
291 | fn ipred_4x4_ver_right(buf: &mut [u8], idx: usize, stride: usize, _tr: &[u8]) { | |
292 | let mut t: [u16; 5] = [0; 5]; | |
293 | let mut l: [u16; 5] = [0; 5]; | |
294 | load_top(&mut t, buf, idx - 1, stride, 5); | |
295 | load_left(&mut l, buf, idx - stride, stride, 5); | |
296 | let dst = &mut buf[idx..]; | |
297 | ||
298 | for j in 0..4 { | |
299 | for i in 0..4 { | |
300 | let zvr = ((2 * i) as i8) - (j as i8); | |
301 | let pix; | |
302 | if zvr >= 0 { | |
303 | if (zvr & 1) == 0 { | |
304 | pix = (t[i - (j >> 1)] + t[i - (j >> 1) + 1] + 1) >> 1; | |
305 | } else { | |
306 | pix = (t[i - (j >> 1) - 1] + 2 * t[i - (j >> 1)] + t[i - (j >> 1) + 1] + 2) >> 2; | |
307 | } | |
308 | } else { | |
309 | if zvr == -1 { | |
310 | pix = (l[1] + 2 * l[0] + t[1] + 2) >> 2; | |
311 | } else { | |
312 | pix = (l[j] + 2 * l[j - 1] + l[j - 2] + 2) >> 2; | |
313 | } | |
314 | } | |
315 | dst[i + j * stride] = pix as u8; | |
316 | } | |
317 | } | |
318 | } | |
319 | fn ipred_4x4_ver_left_common(buf: &mut [u8], idx: usize, stride: usize, tr: &[u8], no_down: bool) { | |
320 | let mut t: [u16; 8] = [0; 8]; | |
321 | let mut l: [u16; 5] = [0; 5]; | |
322 | load_top(&mut t, buf, idx, stride, 4); | |
323 | for i in 0..4 { t[i + 4] = tr[i] as u16; } | |
324 | load_left(&mut l, buf, idx, stride, 4); | |
325 | l[4] = if no_down { l[3] } else { buf[idx - 1 + 4 * stride] as u16 }; | |
326 | let dst = &mut buf[idx..]; | |
327 | ||
328 | dst[0 + 0 * stride] = ((2*t[0] + 2*t[1] + l[1] + 2*l[2] + l[3] + 4) >> 3) as u8; | |
329 | let pix = ((t[1] + t[2] + 1) >> 1) as u8; | |
330 | dst[1 + 0 * stride] = pix; | |
331 | dst[0 + 2 * stride] = pix; | |
332 | let pix = ((t[2] + t[3] + 1) >> 1) as u8; | |
333 | dst[2 + 0 * stride] = pix; | |
334 | dst[1 + 2 * stride] = pix; | |
335 | let pix = ((t[3] + t[4] + 1) >> 1) as u8; | |
336 | dst[3 + 0 * stride] = pix; | |
337 | dst[2 + 2 * stride] = pix; | |
338 | dst[3 + 2 * stride] = ((t[4] + t[5] + 1) >> 1) as u8; | |
339 | dst[0 + 1 * stride] = ((t[0] + 2*t[1] + t[2] + l[2] + 2*l[3] + l[4] + 4) >> 3) as u8; | |
340 | let pix = ((t[1] + 2*t[2] + t[3] + 2) >> 2) as u8; | |
341 | dst[1 + 1 * stride] = pix; | |
342 | dst[0 + 3 * stride] = pix; | |
343 | let pix = ((t[2] + 2*t[3] + t[4] + 2) >> 2) as u8; | |
344 | dst[2 + 1 * stride] = pix; | |
345 | dst[1 + 3 * stride] = pix; | |
346 | let pix = ((t[3] + 2*t[4] + t[5] + 2) >> 2) as u8; | |
347 | dst[3 + 1 * stride] = pix; | |
348 | dst[2 + 3 * stride] = pix; | |
349 | dst[3 + 3 * stride] = ((t[4] + 2*t[5] + t[6] + 2) >> 2) as u8; | |
350 | } | |
351 | ||
352 | fn ipred_4x4_ver_left(buf: &mut [u8], idx: usize, stride: usize, tr: &[u8]) { | |
353 | ipred_4x4_ver_left_common(buf, idx, stride, tr, false); | |
354 | } | |
355 | fn ipred_4x4_ver_left_nodown(buf: &mut [u8], idx: usize, stride: usize, tr: &[u8]) { | |
356 | ipred_4x4_ver_left_common(buf, idx, stride, tr, true); | |
357 | } | |
358 | fn ipred_4x4_hor_down(buf: &mut [u8], idx: usize, stride: usize, _tr: &[u8]) { | |
359 | let mut t: [u16; 5] = [0; 5]; | |
360 | let mut l: [u16; 5] = [0; 5]; | |
361 | load_top(&mut t, buf, idx - 1, stride, 5); | |
362 | load_left(&mut l, buf, idx - stride, stride, 5); | |
363 | let dst = &mut buf[idx..]; | |
364 | ||
365 | for j in 0..4 { | |
366 | for i in 0..4 { | |
367 | let zhd = ((2 * j) as i8) - (i as i8); | |
368 | let pix; | |
369 | if zhd >= 0 { | |
370 | if (zhd & 1) == 0 { | |
371 | pix = (l[j - (i >> 1)] + l[j - (i >> 1) + 1] + 1) >> 1; | |
372 | } else { | |
373 | pix = (l[j - (i >> 1) - 1] + 2 * l[j - (i >> 1)] + l[j - (i >> 1) + 1] + 2) >> 2; | |
374 | } | |
375 | } else { | |
376 | if zhd == -1 { | |
377 | pix = (l[1] + 2 * l[0] + t[1] + 2) >> 2; | |
378 | } else { | |
379 | pix = (t[i - 2] + 2 * t[i - 1] + t[i] + 2) >> 2; | |
380 | } | |
381 | } | |
382 | dst[i + j * stride] = pix as u8; | |
383 | } | |
384 | } | |
385 | } | |
386 | fn ipred_4x4_hor_up(buf: &mut [u8], idx: usize, stride: usize, tr: &[u8]) { | |
387 | let mut t: [u16; 8] = [0; 8]; | |
388 | let mut l: [u16; 8] = [0; 8]; | |
389 | load_top(&mut t, buf, idx, stride, 4); | |
390 | for i in 0..4 { t[i + 4] = tr[i] as u16; } | |
391 | load_left(&mut l, buf, idx, stride, 8); | |
392 | let dst = &mut buf[idx..]; | |
393 | ||
394 | dst[0 + 0 * stride] = ((t[1] + 2*t[2] + t[3] + 2*l[0] + 2*l[1] + 4) >> 3) as u8; | |
395 | dst[1 + 0 * stride] = ((t[2] + 2*t[3] + t[4] + l[0] + 2*l[1] + l[2] + 4) >> 3) as u8; | |
396 | let pix = ((t[3] + 2*t[4] + t[5] + 2*l[1] + 2*l[2] + 4) >> 3) as u8; | |
397 | dst[2 + 0 * stride] = pix; | |
398 | dst[0 + 1 * stride] = pix; | |
399 | let pix = ((t[4] + 2*t[5] + t[6] + l[1] + 2*l[2] + l[3] + 4) >> 3) as u8; | |
400 | dst[3 + 0 * stride] = pix; | |
401 | dst[1 + 1 * stride] = pix; | |
402 | let pix = ((t[5] + 2*t[6] + t[7] + 2*l[2] + 2*l[3] + 4) >> 3) as u8; | |
403 | dst[2 + 1 * stride] = pix; | |
404 | dst[0 + 2 * stride] = pix; | |
405 | let pix = ((t[6] + 3*t[7] + l[2] + 3*l[3] + 4) >> 3) as u8; | |
406 | dst[3 + 1 * stride] = pix; | |
407 | dst[1 + 2 * stride] = pix; | |
408 | let pix = ((l[3] + 2*l[4] + l[5] + 2) >> 2) as u8; | |
409 | dst[3 + 2 * stride] = pix; | |
410 | dst[1 + 3 * stride] = pix; | |
411 | let pix = ((t[6] + t[7] + l[3] + l[4] + 2) >> 2) as u8; | |
412 | dst[0 + 3 * stride] = pix; | |
413 | dst[2 + 2 * stride] = pix; | |
414 | dst[2 + 3 * stride] = ((l[4] + l[5] + 1) >> 1) as u8; | |
415 | dst[3 + 3 * stride] = ((l[4] + 2*l[5] + l[6] + 2) >> 2) as u8; | |
416 | } | |
417 | fn ipred_4x4_hor_up_nodown(buf: &mut [u8], idx: usize, stride: usize, tr: &[u8]) { | |
418 | let mut t: [u16; 8] = [0; 8]; | |
419 | let mut l: [u16; 4] = [0; 4]; | |
420 | load_top(&mut t, buf, idx, stride, 4); | |
421 | for i in 0..4 { t[i + 4] = tr[i] as u16; } | |
422 | load_left(&mut l, buf, idx, stride, 4); | |
423 | let dst = &mut buf[idx..]; | |
424 | ||
425 | dst[0 + 0 * stride] = ((t[1] + 2*t[2] + t[3] + 2*l[0] + 2*l[1] + 4) >> 3) as u8; | |
426 | dst[1 + 0 * stride] = ((t[2] + 2*t[3] + t[4] + l[0] + 2*l[1] + l[2] + 4) >> 3) as u8; | |
427 | let pix = ((t[3] + 2*t[4] + t[5] + 2*l[1] + 2*l[2] + 4) >> 3) as u8; | |
428 | dst[2 + 0 * stride] = pix; | |
429 | dst[0 + 1 * stride] = pix; | |
430 | let pix = ((t[4] + 2*t[5] + t[6] + l[1] + 2*l[2] + l[3] + 4) >> 3) as u8; | |
431 | dst[3 + 0 * stride] = pix; | |
432 | dst[1 + 1 * stride] = pix; | |
433 | let pix = ((t[5] + 2*t[6] + t[7] + 2*l[2] + 2*l[3] + 4) >> 3) as u8; | |
434 | dst[2 + 1 * stride] = pix; | |
435 | dst[0 + 2 * stride] = pix; | |
436 | let pix = ((t[6] + 3*t[7] + l[2] + 3*l[3] + 4) >> 3) as u8; | |
437 | dst[3 + 1 * stride] = pix; | |
438 | dst[1 + 2 * stride] = pix; | |
439 | dst[3 + 2 * stride] = l[3] as u8; | |
440 | dst[1 + 3 * stride] = l[3] as u8; | |
441 | let pix = ((t[6] + t[7] + 2*l[3] + 2) >> 2) as u8; | |
442 | dst[0 + 3 * stride] = pix; | |
443 | dst[2 + 2 * stride] = pix; | |
444 | dst[2 + 3 * stride] = l[3] as u8; | |
445 | dst[3 + 3 * stride] = l[3] as u8; | |
446 | } | |
447 | fn ipred_4x4_dc(buf: &mut [u8], idx: usize, stride: usize, _tr: &[u8]) { | |
448 | ipred_dc(buf, idx, stride, 4, 3); | |
449 | } | |
450 | fn ipred_4x4_left_dc(buf: &mut [u8], idx: usize, stride: usize, _tr: &[u8]) { | |
451 | ipred_left_dc(buf, idx, stride, 4, 2); | |
452 | } | |
453 | fn ipred_4x4_top_dc(buf: &mut [u8], idx: usize, stride: usize, _tr: &[u8]) { | |
454 | ipred_top_dc(buf, idx, stride, 4, 2); | |
455 | } | |
456 | fn ipred_4x4_dc128(buf: &mut [u8], idx: usize, stride: usize, _tr: &[u8]) { | |
457 | ipred_dc128(buf, idx, stride, 4); | |
458 | } | |
459 | ||
460 | fn ipred_8x8_ver(buf: &mut [u8], idx: usize, stride: usize) { | |
461 | ipred_ver(buf, idx, stride, 8); | |
462 | } | |
463 | fn ipred_8x8_hor(buf: &mut [u8], idx: usize, stride: usize) { | |
464 | ipred_hor(buf, idx, stride, 8); | |
465 | } | |
466 | fn ipred_8x8_dc(buf: &mut [u8], idx: usize, stride: usize) { | |
467 | ipred_dc(buf, idx, stride, 8, 4); | |
468 | } | |
469 | fn ipred_8x8_left_dc(buf: &mut [u8], idx: usize, stride: usize) { | |
470 | ipred_left_dc(buf, idx, stride, 8, 3); | |
471 | } | |
472 | fn ipred_8x8_top_dc(buf: &mut [u8], idx: usize, stride: usize) { | |
473 | ipred_top_dc(buf, idx, stride, 8, 3); | |
474 | } | |
475 | fn ipred_8x8_dc128(buf: &mut [u8], idx: usize, stride: usize) { | |
476 | ipred_dc128(buf, idx, stride, 8); | |
477 | } | |
478 | fn ipred_8x8_plane(_buf: &mut [u8], _idx: usize, _stride: usize) { | |
479 | unreachable!(); | |
480 | /* let mut h: i16 = 0; | |
481 | let mut v: i16 = 0; | |
482 | for i in 0..4 { | |
483 | let i1 = (i + 1) as i16; | |
484 | h += i1 * ((buf[idx + (4 + i) - stride] as i16) - (buf[idx + (2 - i) - stride] as i16)); | |
485 | v += i1 * ((buf[idx + (4 + i) * stride - 1] as i16) - (buf[idx + (2 - i) * stride - 1] as i16)); | |
486 | } | |
487 | let a = 16 * ((buf[idx - 1 + 7 * stride] as i16) + (buf[idx + 7 - stride] as i16)); | |
488 | let b = (17 * h + 16) >> 5; | |
489 | let c = (17 * v + 16) >> 5; | |
490 | for y in 0..8 { | |
491 | let j3 = (y as i16) - 3; | |
492 | for x in 0..8 { | |
493 | let i3 = (x as i16) - 3; | |
494 | buf[idx + x] = clip8((a + b * i3 + c * j3 + 16) >> 5); | |
495 | } | |
496 | idx += stride; | |
497 | }*/ | |
498 | } | |
499 | ||
500 | fn ipred_16x16_ver(buf: &mut [u8], idx: usize, stride: usize) { | |
501 | ipred_ver(buf, idx, stride, 16); | |
502 | } | |
503 | fn ipred_16x16_hor(buf: &mut [u8], idx: usize, stride: usize) { | |
504 | ipred_hor(buf, idx, stride, 16); | |
505 | } | |
506 | fn ipred_16x16_dc(buf: &mut [u8], idx: usize, stride: usize) { | |
507 | ipred_dc(buf, idx, stride, 16, 5); | |
508 | } | |
509 | fn ipred_16x16_left_dc(buf: &mut [u8], idx: usize, stride: usize) { | |
510 | ipred_left_dc(buf, idx, stride, 16, 4); | |
511 | } | |
512 | fn ipred_16x16_top_dc(buf: &mut [u8], idx: usize, stride: usize) { | |
513 | ipred_top_dc(buf, idx, stride, 16, 4); | |
514 | } | |
515 | fn ipred_16x16_dc128(buf: &mut [u8], idx: usize, stride: usize) { | |
516 | ipred_dc128(buf, idx, stride, 16); | |
517 | } | |
518 | fn ipred_16x16_plane(buf: &mut [u8], mut idx: usize, stride: usize) { | |
519 | let idx0 = idx + 7 - stride; | |
520 | let mut idx1 = idx + 8*stride - 1; | |
521 | let mut idx2 = idx1 - 2*stride; | |
522 | ||
523 | let mut h = (buf[idx0 + 1] as i16) - (buf[idx0 - 1] as i16); | |
524 | let mut v = (buf[idx1 + 0] as i16) - (buf[idx2 + 0] as i16); | |
525 | ||
526 | for k in 2..9 { | |
527 | idx1 += stride; | |
528 | idx2 -= stride; | |
529 | h += (k as i16) * ((buf[idx0 + k] as i16) - (buf[idx0 - k] as i16)); | |
530 | v += (k as i16) * ((buf[idx1 + 0] as i16) - (buf[idx2 + 0] as i16)); | |
531 | } | |
532 | h = (h + (h >> 2)) >> 4; | |
533 | v = (v + (v >> 2)) >> 4; | |
534 | ||
535 | let mut a = 16 * ((buf[idx1 + 0] as i16) + (buf[idx2 + 16] as i16) + 1) - 7 * (v + h); | |
536 | ||
537 | for _ in 0..16 { | |
538 | let mut b = a; | |
539 | a += v; | |
540 | ||
541 | for x in 0..4 { | |
542 | buf[idx + x * 4 + 0] = clip8((b ) >> 5); | |
543 | buf[idx + x * 4 + 1] = clip8((b + h) >> 5); | |
544 | buf[idx + x * 4 + 2] = clip8((b + 2*h) >> 5); | |
545 | buf[idx + x * 4 + 3] = clip8((b + 3*h) >> 5); | |
546 | b += h * 4; | |
547 | } | |
548 | idx += stride; | |
549 | } | |
550 | } | |
551 | ||
e07387c7 | 552 | const IPRED_FUNCS4X4: [IPred4x4Func; 15] = [ |
47527732 KS |
553 | ipred_4x4_ver, ipred_4x4_hor, ipred_4x4_dc, |
554 | ipred_4x4_diag_down_left, ipred_4x4_diag_down_right, | |
555 | ipred_4x4_ver_right, ipred_4x4_hor_down, ipred_4x4_ver_left, ipred_4x4_hor_up, | |
556 | ipred_4x4_left_dc, ipred_4x4_top_dc, ipred_4x4_dc128, | |
557 | ipred_4x4_diag_down_left_nodown, ipred_4x4_hor_up_nodown, ipred_4x4_ver_left_nodown | |
558 | ]; | |
559 | ||
560 | const IPRED_FUNCS8X8: [fn(buf: &mut [u8], idx: usize, stride: usize); 7] = [ | |
561 | ipred_8x8_dc, ipred_8x8_hor, ipred_8x8_ver, ipred_8x8_plane, | |
562 | ipred_8x8_left_dc, ipred_8x8_top_dc, ipred_8x8_dc128 | |
563 | ]; | |
564 | ||
565 | const IPRED_FUNCS16X16: [fn(buf: &mut [u8], idx: usize, stride: usize); 7] = [ | |
566 | ipred_16x16_dc, ipred_16x16_hor, ipred_16x16_ver, ipred_16x16_plane, | |
567 | ipred_16x16_left_dc, ipred_16x16_top_dc, ipred_16x16_dc128 | |
568 | ]; |