blob: b1076f8f01aaf771e970791927c9d713311509a2 [file] [log] [blame]
hui su79718462015-07-19 15:02:56 -07001/*
2 * Copyright (c) 2015 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "./vpx_config.h"
12#include "./vpx_dsp_rtcd.h"
13
14#include "vpx_dsp/vpx_dsp_common.h"
15#include "vpx_mem/vpx_mem.h"
16
17#define DST(x, y) dst[(x) + (y) * stride]
18#define AVG3(a, b, c) (((a) + 2 * (b) + (c) + 2) >> 2)
19#define AVG2(a, b) (((a) + (b) + 1) >> 1)
20
21static INLINE void d207_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
22 const uint8_t *above, const uint8_t *left) {
23 int r, c;
24 (void) above;
25 // first column
26 for (r = 0; r < bs - 1; ++r)
27 dst[r * stride] = AVG2(left[r], left[r + 1]);
28 dst[(bs - 1) * stride] = left[bs - 1];
29 dst++;
30
31 // second column
32 for (r = 0; r < bs - 2; ++r)
33 dst[r * stride] = AVG3(left[r], left[r + 1], left[r + 2]);
34 dst[(bs - 2) * stride] = AVG3(left[bs - 2], left[bs - 1], left[bs - 1]);
35 dst[(bs - 1) * stride] = left[bs - 1];
36 dst++;
37
38 // rest of last row
39 for (c = 0; c < bs - 2; ++c)
40 dst[(bs - 1) * stride + c] = left[bs - 1];
41
42 for (r = bs - 2; r >= 0; --r)
43 for (c = 0; c < bs - 2; ++c)
44 dst[r * stride + c] = dst[(r + 1) * stride + c - 2];
45}
46
Ronald S. Bultjec7dc1d72015-10-12 10:35:46 -040047static INLINE void d207e_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
48 const uint8_t *above, const uint8_t *left) {
49 int r, c;
50 (void) above;
51
52 for (r = 0; r < bs; ++r) {
53 for (c = 0; c < bs; ++c) {
54 dst[c] = c & 1 ? AVG3(left[(c >> 1) + r], left[(c >> 1) + r + 1],
55 left[(c >> 1) + r + 2])
56 : AVG2(left[(c >> 1) + r], left[(c >> 1) + r + 1]);
57 }
58 dst += stride;
59 }
60}
61
hui su79718462015-07-19 15:02:56 -070062static INLINE void d63_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
63 const uint8_t *above, const uint8_t *left) {
64 int r, c;
65 int size;
66 (void)left;
67 for (c = 0; c < bs; ++c) {
68 dst[c] = AVG2(above[c], above[c + 1]);
69 dst[stride + c] = AVG3(above[c], above[c + 1], above[c + 2]);
70 }
71 for (r = 2, size = bs - 2; r < bs; r += 2, --size) {
72 memcpy(dst + (r + 0) * stride, dst + (r >> 1), size);
73 memset(dst + (r + 0) * stride + size, above[bs - 1], bs - size);
74 memcpy(dst + (r + 1) * stride, dst + stride + (r >> 1), size);
75 memset(dst + (r + 1) * stride + size, above[bs - 1], bs - size);
76 }
77}
78
Ronald S. Bultjec7dc1d72015-10-12 10:35:46 -040079static INLINE void d63e_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
80 const uint8_t *above, const uint8_t *left) {
81 int r, c;
82 (void) left;
83 for (r = 0; r < bs; ++r) {
84 for (c = 0; c < bs; ++c) {
85 dst[c] = r & 1 ? AVG3(above[(r >> 1) + c], above[(r >> 1) + c + 1],
86 above[(r >> 1) + c + 2])
87 : AVG2(above[(r >> 1) + c], above[(r >> 1) + c + 1]);
88 }
89 dst += stride;
90 }
91}
92
hui su79718462015-07-19 15:02:56 -070093static INLINE void d45_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
94 const uint8_t *above, const uint8_t *left) {
95 const uint8_t above_right = above[bs - 1];
96 const uint8_t *const dst_row0 = dst;
97 int x, size;
98 (void)left;
99
100 for (x = 0; x < bs - 1; ++x) {
101 dst[x] = AVG3(above[x], above[x + 1], above[x + 2]);
102 }
103 dst[bs - 1] = above_right;
104 dst += stride;
105 for (x = 1, size = bs - 2; x < bs; ++x, --size) {
106 memcpy(dst, dst_row0 + x, size);
107 memset(dst + size, above_right, x + 1);
108 dst += stride;
109 }
110}
111
Ronald S. Bultjec7dc1d72015-10-12 10:35:46 -0400112static INLINE void d45e_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
113 const uint8_t *above, const uint8_t *left) {
114 int r, c;
115 (void) left;
116 for (r = 0; r < bs; ++r) {
117 for (c = 0; c < bs; ++c) {
118 dst[c] = AVG3(above[r + c], above[r + c + 1],
119 above[r + c + 1 + (r + c + 2 < bs * 2)]);
120 }
121 dst += stride;
122 }
123}
124
hui su79718462015-07-19 15:02:56 -0700125static INLINE void d117_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
126 const uint8_t *above, const uint8_t *left) {
127 int r, c;
128
129 // first row
130 for (c = 0; c < bs; c++)
131 dst[c] = AVG2(above[c - 1], above[c]);
132 dst += stride;
133
134 // second row
135 dst[0] = AVG3(left[0], above[-1], above[0]);
136 for (c = 1; c < bs; c++)
137 dst[c] = AVG3(above[c - 2], above[c - 1], above[c]);
138 dst += stride;
139
140 // the rest of first col
141 dst[0] = AVG3(above[-1], left[0], left[1]);
142 for (r = 3; r < bs; ++r)
143 dst[(r - 2) * stride] = AVG3(left[r - 3], left[r - 2], left[r - 1]);
144
145 // the rest of the block
146 for (r = 2; r < bs; ++r) {
147 for (c = 1; c < bs; c++)
148 dst[c] = dst[-2 * stride + c - 1];
149 dst += stride;
150 }
151}
152
153static INLINE void d135_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
154 const uint8_t *above, const uint8_t *left) {
James Zern05437802016-02-05 12:31:48 -0800155 int i;
156#if defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ > 7
157 // silence a spurious -Warray-bounds warning, possibly related to:
158 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56273
159 uint8_t border[69];
160#else
161 uint8_t border[32 + 32 - 1]; // outer border from bottom-left to top-right
162#endif
hui su79718462015-07-19 15:02:56 -0700163
James Zern05437802016-02-05 12:31:48 -0800164 // dst(bs, bs - 2)[0], i.e., border starting at bottom-left
165 for (i = 0; i < bs - 2; ++i) {
166 border[i] = AVG3(left[bs - 3 - i], left[bs - 2 - i], left[bs - 1 - i]);
167 }
168 border[bs - 2] = AVG3(above[-1], left[0], left[1]);
169 border[bs - 1] = AVG3(left[0], above[-1], above[0]);
170 border[bs - 0] = AVG3(above[-1], above[0], above[1]);
171 // dst[0][2, size), i.e., remaining top border ascending
172 for (i = 0; i < bs - 2; ++i) {
173 border[bs + 1 + i] = AVG3(above[i], above[i + 1], above[i + 2]);
174 }
hui su79718462015-07-19 15:02:56 -0700175
James Zern05437802016-02-05 12:31:48 -0800176 for (i = 0; i < bs; ++i) {
177 memcpy(dst + i * stride, border + bs - 1 - i, bs);
hui su79718462015-07-19 15:02:56 -0700178 }
179}
180
181static INLINE void d153_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
182 const uint8_t *above, const uint8_t *left) {
183 int r, c;
184 dst[0] = AVG2(above[-1], left[0]);
185 for (r = 1; r < bs; r++)
186 dst[r * stride] = AVG2(left[r - 1], left[r]);
187 dst++;
188
189 dst[0] = AVG3(left[0], above[-1], above[0]);
190 dst[stride] = AVG3(above[-1], left[0], left[1]);
191 for (r = 2; r < bs; r++)
192 dst[r * stride] = AVG3(left[r - 2], left[r - 1], left[r]);
193 dst++;
194
195 for (c = 0; c < bs - 2; c++)
196 dst[c] = AVG3(above[c - 1], above[c], above[c + 1]);
197 dst += stride;
198
199 for (r = 1; r < bs; ++r) {
200 for (c = 0; c < bs - 2; c++)
201 dst[c] = dst[-stride + c - 2];
202 dst += stride;
203 }
204}
205
206static INLINE void v_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
207 const uint8_t *above, const uint8_t *left) {
208 int r;
209 (void) left;
210
211 for (r = 0; r < bs; r++) {
212 memcpy(dst, above, bs);
213 dst += stride;
214 }
215}
216
217static INLINE void h_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
218 const uint8_t *above, const uint8_t *left) {
219 int r;
220 (void) above;
221
222 for (r = 0; r < bs; r++) {
223 memset(dst, left[r], bs);
224 dst += stride;
225 }
226}
227
228static INLINE void tm_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
229 const uint8_t *above, const uint8_t *left) {
230 int r, c;
231 int ytop_left = above[-1];
232
233 for (r = 0; r < bs; r++) {
234 for (c = 0; c < bs; c++)
235 dst[c] = clip_pixel(left[r] + above[c] - ytop_left);
236 dst += stride;
237 }
238}
239
240static INLINE void dc_128_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
241 const uint8_t *above, const uint8_t *left) {
242 int r;
243 (void) above;
244 (void) left;
245
246 for (r = 0; r < bs; r++) {
247 memset(dst, 128, bs);
248 dst += stride;
249 }
250}
251
252static INLINE void dc_left_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
253 const uint8_t *above,
254 const uint8_t *left) {
255 int i, r, expected_dc, sum = 0;
256 (void) above;
257
258 for (i = 0; i < bs; i++)
259 sum += left[i];
260 expected_dc = (sum + (bs >> 1)) / bs;
261
262 for (r = 0; r < bs; r++) {
263 memset(dst, expected_dc, bs);
264 dst += stride;
265 }
266}
267
268static INLINE void dc_top_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
269 const uint8_t *above, const uint8_t *left) {
270 int i, r, expected_dc, sum = 0;
271 (void) left;
272
273 for (i = 0; i < bs; i++)
274 sum += above[i];
275 expected_dc = (sum + (bs >> 1)) / bs;
276
277 for (r = 0; r < bs; r++) {
278 memset(dst, expected_dc, bs);
279 dst += stride;
280 }
281}
282
283static INLINE void dc_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
284 const uint8_t *above, const uint8_t *left) {
285 int i, r, expected_dc, sum = 0;
286 const int count = 2 * bs;
287
288 for (i = 0; i < bs; i++) {
289 sum += above[i];
290 sum += left[i];
291 }
292
293 expected_dc = (sum + (count >> 1)) / count;
294
295 for (r = 0; r < bs; r++) {
296 memset(dst, expected_dc, bs);
297 dst += stride;
298 }
299}
300
Ronald S. Bultjec26a9ec2015-09-30 18:44:37 -0400301void vpx_he_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
302 const uint8_t *above, const uint8_t *left) {
303 const int H = above[-1];
304 const int I = left[0];
305 const int J = left[1];
306 const int K = left[2];
307 const int L = left[3];
308
309 memset(dst + stride * 0, AVG3(H, I, J), 4);
310 memset(dst + stride * 1, AVG3(I, J, K), 4);
311 memset(dst + stride * 2, AVG3(J, K, L), 4);
312 memset(dst + stride * 3, AVG3(K, L, L), 4);
313}
314
315void vpx_ve_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
316 const uint8_t *above, const uint8_t *left) {
317 const int H = above[-1];
318 const int I = above[0];
319 const int J = above[1];
320 const int K = above[2];
321 const int L = above[3];
322 const int M = above[4];
James Zern26c6fbd2016-02-11 18:31:40 -0800323 (void)left;
Ronald S. Bultjec26a9ec2015-09-30 18:44:37 -0400324
325 dst[0] = AVG3(H, I, J);
326 dst[1] = AVG3(I, J, K);
327 dst[2] = AVG3(J, K, L);
328 dst[3] = AVG3(K, L, M);
329 memcpy(dst + stride * 1, dst, 4);
330 memcpy(dst + stride * 2, dst, 4);
331 memcpy(dst + stride * 3, dst, 4);
332}
333
hui su40136452015-07-21 09:39:46 -0700334void vpx_d207_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
hui su79718462015-07-19 15:02:56 -0700335 const uint8_t *above, const uint8_t *left) {
336 const int I = left[0];
337 const int J = left[1];
338 const int K = left[2];
339 const int L = left[3];
340 (void)above;
341 DST(0, 0) = AVG2(I, J);
342 DST(2, 0) = DST(0, 1) = AVG2(J, K);
343 DST(2, 1) = DST(0, 2) = AVG2(K, L);
344 DST(1, 0) = AVG3(I, J, K);
345 DST(3, 0) = DST(1, 1) = AVG3(J, K, L);
346 DST(3, 1) = DST(1, 2) = AVG3(K, L, L);
347 DST(3, 2) = DST(2, 2) =
348 DST(0, 3) = DST(1, 3) = DST(2, 3) = DST(3, 3) = L;
349}
350
hui su40136452015-07-21 09:39:46 -0700351void vpx_d63_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
hui su79718462015-07-19 15:02:56 -0700352 const uint8_t *above, const uint8_t *left) {
353 const int A = above[0];
354 const int B = above[1];
355 const int C = above[2];
356 const int D = above[3];
357 const int E = above[4];
358 const int F = above[5];
359 const int G = above[6];
360 (void)left;
361 DST(0, 0) = AVG2(A, B);
362 DST(1, 0) = DST(0, 2) = AVG2(B, C);
363 DST(2, 0) = DST(1, 2) = AVG2(C, D);
364 DST(3, 0) = DST(2, 2) = AVG2(D, E);
365 DST(3, 2) = AVG2(E, F); // differs from vp8
366
367 DST(0, 1) = AVG3(A, B, C);
368 DST(1, 1) = DST(0, 3) = AVG3(B, C, D);
369 DST(2, 1) = DST(1, 3) = AVG3(C, D, E);
370 DST(3, 1) = DST(2, 3) = AVG3(D, E, F);
371 DST(3, 3) = AVG3(E, F, G); // differs from vp8
372}
373
Ronald S. Bultjec7dc1d72015-10-12 10:35:46 -0400374void vpx_d63f_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
Ronald S. Bultjec26a9ec2015-09-30 18:44:37 -0400375 const uint8_t *above, const uint8_t *left) {
376 const int A = above[0];
377 const int B = above[1];
378 const int C = above[2];
379 const int D = above[3];
380 const int E = above[4];
381 const int F = above[5];
382 const int G = above[6];
383 const int H = above[7];
384 (void)left;
385 DST(0, 0) = AVG2(A, B);
386 DST(1, 0) = DST(0, 2) = AVG2(B, C);
387 DST(2, 0) = DST(1, 2) = AVG2(C, D);
388 DST(3, 0) = DST(2, 2) = AVG2(D, E);
389 DST(3, 2) = AVG3(E, F, G);
390
391 DST(0, 1) = AVG3(A, B, C);
392 DST(1, 1) = DST(0, 3) = AVG3(B, C, D);
393 DST(2, 1) = DST(1, 3) = AVG3(C, D, E);
394 DST(3, 1) = DST(2, 3) = AVG3(D, E, F);
395 DST(3, 3) = AVG3(F, G, H);
396}
397
hui su40136452015-07-21 09:39:46 -0700398void vpx_d45_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
hui su79718462015-07-19 15:02:56 -0700399 const uint8_t *above, const uint8_t *left) {
400 const int A = above[0];
401 const int B = above[1];
402 const int C = above[2];
403 const int D = above[3];
404 const int E = above[4];
405 const int F = above[5];
406 const int G = above[6];
407 const int H = above[7];
408 (void)stride;
409 (void)left;
410 DST(0, 0) = AVG3(A, B, C);
411 DST(1, 0) = DST(0, 1) = AVG3(B, C, D);
412 DST(2, 0) = DST(1, 1) = DST(0, 2) = AVG3(C, D, E);
413 DST(3, 0) = DST(2, 1) = DST(1, 2) = DST(0, 3) = AVG3(D, E, F);
414 DST(3, 1) = DST(2, 2) = DST(1, 3) = AVG3(E, F, G);
415 DST(3, 2) = DST(2, 3) = AVG3(F, G, H);
416 DST(3, 3) = H; // differs from vp8
417}
418
Ronald S. Bultjec26a9ec2015-09-30 18:44:37 -0400419void vpx_d45e_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
420 const uint8_t *above, const uint8_t *left) {
421 const int A = above[0];
422 const int B = above[1];
423 const int C = above[2];
424 const int D = above[3];
425 const int E = above[4];
426 const int F = above[5];
427 const int G = above[6];
428 const int H = above[7];
429 (void)stride;
430 (void)left;
431 DST(0, 0) = AVG3(A, B, C);
432 DST(1, 0) = DST(0, 1) = AVG3(B, C, D);
433 DST(2, 0) = DST(1, 1) = DST(0, 2) = AVG3(C, D, E);
434 DST(3, 0) = DST(2, 1) = DST(1, 2) = DST(0, 3) = AVG3(D, E, F);
435 DST(3, 1) = DST(2, 2) = DST(1, 3) = AVG3(E, F, G);
436 DST(3, 2) = DST(2, 3) = AVG3(F, G, H);
437 DST(3, 3) = AVG3(G, H, H);
438}
439
hui su40136452015-07-21 09:39:46 -0700440void vpx_d117_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
hui su79718462015-07-19 15:02:56 -0700441 const uint8_t *above, const uint8_t *left) {
442 const int I = left[0];
443 const int J = left[1];
444 const int K = left[2];
445 const int X = above[-1];
446 const int A = above[0];
447 const int B = above[1];
448 const int C = above[2];
449 const int D = above[3];
450 DST(0, 0) = DST(1, 2) = AVG2(X, A);
451 DST(1, 0) = DST(2, 2) = AVG2(A, B);
452 DST(2, 0) = DST(3, 2) = AVG2(B, C);
453 DST(3, 0) = AVG2(C, D);
454
455 DST(0, 3) = AVG3(K, J, I);
456 DST(0, 2) = AVG3(J, I, X);
457 DST(0, 1) = DST(1, 3) = AVG3(I, X, A);
458 DST(1, 1) = DST(2, 3) = AVG3(X, A, B);
459 DST(2, 1) = DST(3, 3) = AVG3(A, B, C);
460 DST(3, 1) = AVG3(B, C, D);
461}
462
hui su40136452015-07-21 09:39:46 -0700463void vpx_d135_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
hui su79718462015-07-19 15:02:56 -0700464 const uint8_t *above, const uint8_t *left) {
465 const int I = left[0];
466 const int J = left[1];
467 const int K = left[2];
468 const int L = left[3];
469 const int X = above[-1];
470 const int A = above[0];
471 const int B = above[1];
472 const int C = above[2];
473 const int D = above[3];
474 (void)stride;
475 DST(0, 3) = AVG3(J, K, L);
476 DST(1, 3) = DST(0, 2) = AVG3(I, J, K);
477 DST(2, 3) = DST(1, 2) = DST(0, 1) = AVG3(X, I, J);
478 DST(3, 3) = DST(2, 2) = DST(1, 1) = DST(0, 0) = AVG3(A, X, I);
479 DST(3, 2) = DST(2, 1) = DST(1, 0) = AVG3(B, A, X);
480 DST(3, 1) = DST(2, 0) = AVG3(C, B, A);
481 DST(3, 0) = AVG3(D, C, B);
482}
483
hui su40136452015-07-21 09:39:46 -0700484void vpx_d153_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
hui su79718462015-07-19 15:02:56 -0700485 const uint8_t *above, const uint8_t *left) {
486 const int I = left[0];
487 const int J = left[1];
488 const int K = left[2];
489 const int L = left[3];
490 const int X = above[-1];
491 const int A = above[0];
492 const int B = above[1];
493 const int C = above[2];
494
495 DST(0, 0) = DST(2, 1) = AVG2(I, X);
496 DST(0, 1) = DST(2, 2) = AVG2(J, I);
497 DST(0, 2) = DST(2, 3) = AVG2(K, J);
498 DST(0, 3) = AVG2(L, K);
499
500 DST(3, 0) = AVG3(A, B, C);
501 DST(2, 0) = AVG3(X, A, B);
502 DST(1, 0) = DST(3, 1) = AVG3(I, X, A);
503 DST(1, 1) = DST(3, 2) = AVG3(J, I, X);
504 DST(1, 2) = DST(3, 3) = AVG3(K, J, I);
505 DST(1, 3) = AVG3(L, K, J);
506}
507
508#if CONFIG_VP9_HIGHBITDEPTH
509static INLINE void highbd_d207_predictor(uint16_t *dst, ptrdiff_t stride,
510 int bs, const uint16_t *above,
511 const uint16_t *left, int bd) {
512 int r, c;
513 (void) above;
514 (void) bd;
515
516 // First column.
517 for (r = 0; r < bs - 1; ++r) {
518 dst[r * stride] = AVG2(left[r], left[r + 1]);
519 }
520 dst[(bs - 1) * stride] = left[bs - 1];
521 dst++;
522
523 // Second column.
524 for (r = 0; r < bs - 2; ++r) {
525 dst[r * stride] = AVG3(left[r], left[r + 1], left[r + 2]);
526 }
527 dst[(bs - 2) * stride] = AVG3(left[bs - 2], left[bs - 1], left[bs - 1]);
528 dst[(bs - 1) * stride] = left[bs - 1];
529 dst++;
530
531 // Rest of last row.
532 for (c = 0; c < bs - 2; ++c)
533 dst[(bs - 1) * stride + c] = left[bs - 1];
534
535 for (r = bs - 2; r >= 0; --r) {
536 for (c = 0; c < bs - 2; ++c)
537 dst[r * stride + c] = dst[(r + 1) * stride + c - 2];
538 }
539}
540
Ronald S. Bultjec7dc1d72015-10-12 10:35:46 -0400541static INLINE void highbd_d207e_predictor(uint16_t *dst, ptrdiff_t stride,
542 int bs, const uint16_t *above,
543 const uint16_t *left, int bd) {
544 int r, c;
545 (void) above;
546 (void) bd;
547
548 for (r = 0; r < bs; ++r) {
549 for (c = 0; c < bs; ++c) {
550 dst[c] = c & 1 ? AVG3(left[(c >> 1) + r], left[(c >> 1) + r + 1],
551 left[(c >> 1) + r + 2])
552 : AVG2(left[(c >> 1) + r], left[(c >> 1) + r + 1]);
553 }
554 dst += stride;
555 }
556}
557
hui su79718462015-07-19 15:02:56 -0700558static INLINE void highbd_d63_predictor(uint16_t *dst, ptrdiff_t stride,
559 int bs, const uint16_t *above,
560 const uint16_t *left, int bd) {
561 int r, c;
562 (void) left;
563 (void) bd;
564 for (r = 0; r < bs; ++r) {
565 for (c = 0; c < bs; ++c) {
566 dst[c] = r & 1 ? AVG3(above[(r >> 1) + c], above[(r >> 1) + c + 1],
567 above[(r >> 1) + c + 2])
568 : AVG2(above[(r >> 1) + c], above[(r >> 1) + c + 1]);
569 }
570 dst += stride;
571 }
572}
573
Ronald S. Bultjec7dc1d72015-10-12 10:35:46 -0400574#define highbd_d63e_predictor highbd_d63_predictor
575
hui su79718462015-07-19 15:02:56 -0700576static INLINE void highbd_d45_predictor(uint16_t *dst, ptrdiff_t stride, int bs,
577 const uint16_t *above,
578 const uint16_t *left, int bd) {
579 int r, c;
580 (void) left;
581 (void) bd;
582 for (r = 0; r < bs; ++r) {
583 for (c = 0; c < bs; ++c) {
584 dst[c] = r + c + 2 < bs * 2 ? AVG3(above[r + c], above[r + c + 1],
585 above[r + c + 2])
586 : above[bs * 2 - 1];
587 }
588 dst += stride;
589 }
590}
591
Ronald S. Bultje62a15792015-09-30 18:45:08 -0400592static INLINE void highbd_d45e_predictor(uint16_t *dst, ptrdiff_t stride,
593 int bs, const uint16_t *above,
594 const uint16_t *left, int bd) {
595 int r, c;
596 (void) left;
597 (void) bd;
598 for (r = 0; r < bs; ++r) {
599 for (c = 0; c < bs; ++c) {
600 dst[c] = AVG3(above[r + c], above[r + c + 1],
Ronald S. Bultjec7dc1d72015-10-12 10:35:46 -0400601 above[r + c + 1 + (r + c + 2 < bs * 2)]);
Ronald S. Bultje62a15792015-09-30 18:45:08 -0400602 }
603 dst += stride;
604 }
605}
606
hui su79718462015-07-19 15:02:56 -0700607static INLINE void highbd_d117_predictor(uint16_t *dst, ptrdiff_t stride,
608 int bs, const uint16_t *above,
609 const uint16_t *left, int bd) {
610 int r, c;
611 (void) bd;
612
613 // first row
614 for (c = 0; c < bs; c++)
615 dst[c] = AVG2(above[c - 1], above[c]);
616 dst += stride;
617
618 // second row
619 dst[0] = AVG3(left[0], above[-1], above[0]);
620 for (c = 1; c < bs; c++)
621 dst[c] = AVG3(above[c - 2], above[c - 1], above[c]);
622 dst += stride;
623
624 // the rest of first col
625 dst[0] = AVG3(above[-1], left[0], left[1]);
626 for (r = 3; r < bs; ++r)
627 dst[(r - 2) * stride] = AVG3(left[r - 3], left[r - 2], left[r - 1]);
628
629 // the rest of the block
630 for (r = 2; r < bs; ++r) {
631 for (c = 1; c < bs; c++)
632 dst[c] = dst[-2 * stride + c - 1];
633 dst += stride;
634 }
635}
636
637static INLINE void highbd_d135_predictor(uint16_t *dst, ptrdiff_t stride,
638 int bs, const uint16_t *above,
639 const uint16_t *left, int bd) {
640 int r, c;
641 (void) bd;
642 dst[0] = AVG3(left[0], above[-1], above[0]);
643 for (c = 1; c < bs; c++)
644 dst[c] = AVG3(above[c - 2], above[c - 1], above[c]);
645
646 dst[stride] = AVG3(above[-1], left[0], left[1]);
647 for (r = 2; r < bs; ++r)
648 dst[r * stride] = AVG3(left[r - 2], left[r - 1], left[r]);
649
650 dst += stride;
651 for (r = 1; r < bs; ++r) {
652 for (c = 1; c < bs; c++)
653 dst[c] = dst[-stride + c - 1];
654 dst += stride;
655 }
656}
657
658static INLINE void highbd_d153_predictor(uint16_t *dst, ptrdiff_t stride,
659 int bs, const uint16_t *above,
660 const uint16_t *left, int bd) {
661 int r, c;
662 (void) bd;
663 dst[0] = AVG2(above[-1], left[0]);
664 for (r = 1; r < bs; r++)
665 dst[r * stride] = AVG2(left[r - 1], left[r]);
666 dst++;
667
668 dst[0] = AVG3(left[0], above[-1], above[0]);
669 dst[stride] = AVG3(above[-1], left[0], left[1]);
670 for (r = 2; r < bs; r++)
671 dst[r * stride] = AVG3(left[r - 2], left[r - 1], left[r]);
672 dst++;
673
674 for (c = 0; c < bs - 2; c++)
675 dst[c] = AVG3(above[c - 1], above[c], above[c + 1]);
676 dst += stride;
677
678 for (r = 1; r < bs; ++r) {
679 for (c = 0; c < bs - 2; c++)
680 dst[c] = dst[-stride + c - 2];
681 dst += stride;
682 }
683}
684
685static INLINE void highbd_v_predictor(uint16_t *dst, ptrdiff_t stride,
686 int bs, const uint16_t *above,
687 const uint16_t *left, int bd) {
688 int r;
689 (void) left;
690 (void) bd;
691 for (r = 0; r < bs; r++) {
692 memcpy(dst, above, bs * sizeof(uint16_t));
693 dst += stride;
694 }
695}
696
697static INLINE void highbd_h_predictor(uint16_t *dst, ptrdiff_t stride,
698 int bs, const uint16_t *above,
699 const uint16_t *left, int bd) {
700 int r;
701 (void) above;
702 (void) bd;
703 for (r = 0; r < bs; r++) {
704 vpx_memset16(dst, left[r], bs);
705 dst += stride;
706 }
707}
708
709static INLINE void highbd_tm_predictor(uint16_t *dst, ptrdiff_t stride,
710 int bs, const uint16_t *above,
711 const uint16_t *left, int bd) {
712 int r, c;
713 int ytop_left = above[-1];
714 (void) bd;
715
716 for (r = 0; r < bs; r++) {
717 for (c = 0; c < bs; c++)
718 dst[c] = clip_pixel_highbd(left[r] + above[c] - ytop_left, bd);
719 dst += stride;
720 }
721}
722
723static INLINE void highbd_dc_128_predictor(uint16_t *dst, ptrdiff_t stride,
724 int bs, const uint16_t *above,
725 const uint16_t *left, int bd) {
726 int r;
727 (void) above;
728 (void) left;
729
730 for (r = 0; r < bs; r++) {
731 vpx_memset16(dst, 128 << (bd - 8), bs);
732 dst += stride;
733 }
734}
735
736static INLINE void highbd_dc_left_predictor(uint16_t *dst, ptrdiff_t stride,
737 int bs, const uint16_t *above,
738 const uint16_t *left, int bd) {
739 int i, r, expected_dc, sum = 0;
740 (void) above;
741 (void) bd;
742
743 for (i = 0; i < bs; i++)
744 sum += left[i];
745 expected_dc = (sum + (bs >> 1)) / bs;
746
747 for (r = 0; r < bs; r++) {
748 vpx_memset16(dst, expected_dc, bs);
749 dst += stride;
750 }
751}
752
753static INLINE void highbd_dc_top_predictor(uint16_t *dst, ptrdiff_t stride,
754 int bs, const uint16_t *above,
755 const uint16_t *left, int bd) {
756 int i, r, expected_dc, sum = 0;
757 (void) left;
758 (void) bd;
759
760 for (i = 0; i < bs; i++)
761 sum += above[i];
762 expected_dc = (sum + (bs >> 1)) / bs;
763
764 for (r = 0; r < bs; r++) {
765 vpx_memset16(dst, expected_dc, bs);
766 dst += stride;
767 }
768}
769
770static INLINE void highbd_dc_predictor(uint16_t *dst, ptrdiff_t stride,
771 int bs, const uint16_t *above,
772 const uint16_t *left, int bd) {
773 int i, r, expected_dc, sum = 0;
774 const int count = 2 * bs;
775 (void) bd;
776
777 for (i = 0; i < bs; i++) {
778 sum += above[i];
779 sum += left[i];
780 }
781
782 expected_dc = (sum + (count >> 1)) / count;
783
784 for (r = 0; r < bs; r++) {
785 vpx_memset16(dst, expected_dc, bs);
786 dst += stride;
787 }
788}
789#endif // CONFIG_VP9_HIGHBITDEPTH
790
791// This serves as a wrapper function, so that all the prediction functions
792// can be unified and accessed as a pointer array. Note that the boundary
793// above and left are not necessarily used all the time.
794#define intra_pred_sized(type, size) \
hui su40136452015-07-21 09:39:46 -0700795 void vpx_##type##_predictor_##size##x##size##_c(uint8_t *dst, \
hui su79718462015-07-19 15:02:56 -0700796 ptrdiff_t stride, \
797 const uint8_t *above, \
798 const uint8_t *left) { \
799 type##_predictor(dst, stride, size, above, left); \
800 }
801
802#if CONFIG_VP9_HIGHBITDEPTH
803#define intra_pred_highbd_sized(type, size) \
hui su40136452015-07-21 09:39:46 -0700804 void vpx_highbd_##type##_predictor_##size##x##size##_c( \
hui su79718462015-07-19 15:02:56 -0700805 uint16_t *dst, ptrdiff_t stride, const uint16_t *above, \
806 const uint16_t *left, int bd) { \
807 highbd_##type##_predictor(dst, stride, size, above, left, bd); \
808 }
809
810#define intra_pred_allsizes(type) \
811 intra_pred_sized(type, 4) \
812 intra_pred_sized(type, 8) \
813 intra_pred_sized(type, 16) \
814 intra_pred_sized(type, 32) \
815 intra_pred_highbd_sized(type, 4) \
816 intra_pred_highbd_sized(type, 8) \
817 intra_pred_highbd_sized(type, 16) \
818 intra_pred_highbd_sized(type, 32)
819
820#define intra_pred_no_4x4(type) \
821 intra_pred_sized(type, 8) \
822 intra_pred_sized(type, 16) \
823 intra_pred_sized(type, 32) \
824 intra_pred_highbd_sized(type, 4) \
825 intra_pred_highbd_sized(type, 8) \
826 intra_pred_highbd_sized(type, 16) \
827 intra_pred_highbd_sized(type, 32)
828
829#else
830#define intra_pred_allsizes(type) \
831 intra_pred_sized(type, 4) \
832 intra_pred_sized(type, 8) \
833 intra_pred_sized(type, 16) \
834 intra_pred_sized(type, 32)
835
836#define intra_pred_no_4x4(type) \
837 intra_pred_sized(type, 8) \
838 intra_pred_sized(type, 16) \
839 intra_pred_sized(type, 32)
840#endif // CONFIG_VP9_HIGHBITDEPTH
841
842intra_pred_no_4x4(d207)
843intra_pred_no_4x4(d63)
844intra_pred_no_4x4(d45)
Debargha Mukherjee104636a2015-12-10 15:00:33 -0800845intra_pred_allsizes(d207e)
846intra_pred_allsizes(d63e)
847intra_pred_no_4x4(d45e)
hui su79718462015-07-19 15:02:56 -0700848intra_pred_no_4x4(d117)
849intra_pred_no_4x4(d135)
850intra_pred_no_4x4(d153)
851intra_pred_allsizes(v)
852intra_pred_allsizes(h)
853intra_pred_allsizes(tm)
854intra_pred_allsizes(dc_128)
855intra_pred_allsizes(dc_left)
856intra_pred_allsizes(dc_top)
857intra_pred_allsizes(dc)
hui su79718462015-07-19 15:02:56 -0700858#undef intra_pred_allsizes