2 * Copyright (c) 2015 The WebM project authors. All Rights Reserved.
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.
11 #include "./vpx_config.h"
12 #include "./vpx_dsp_rtcd.h"
14 #include "vpx_dsp/vpx_dsp_common.h"
15 #include "vpx_mem/vpx_mem.h"
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)
21 static INLINE void d207_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
22 const uint8_t *above, const uint8_t *left) {
26 for (r = 0; r < bs - 1; ++r) dst[r * stride] = AVG2(left[r], left[r + 1]);
27 dst[(bs - 1) * stride] = left[bs - 1];
31 for (r = 0; r < bs - 2; ++r)
32 dst[r * stride] = AVG3(left[r], left[r + 1], left[r + 2]);
33 dst[(bs - 2) * stride] = AVG3(left[bs - 2], left[bs - 1], left[bs - 1]);
34 dst[(bs - 1) * stride] = left[bs - 1];
38 for (c = 0; c < bs - 2; ++c) dst[(bs - 1) * stride + c] = left[bs - 1];
40 for (r = bs - 2; r >= 0; --r)
41 for (c = 0; c < bs - 2; ++c)
42 dst[r * stride + c] = dst[(r + 1) * stride + c - 2];
45 static INLINE void d63_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
46 const uint8_t *above, const uint8_t *left) {
50 for (c = 0; c < bs; ++c) {
51 dst[c] = AVG2(above[c], above[c + 1]);
52 dst[stride + c] = AVG3(above[c], above[c + 1], above[c + 2]);
54 for (r = 2, size = bs - 2; r < bs; r += 2, --size) {
55 memcpy(dst + (r + 0) * stride, dst + (r >> 1), size);
56 memset(dst + (r + 0) * stride + size, above[bs - 1], bs - size);
57 memcpy(dst + (r + 1) * stride, dst + stride + (r >> 1), size);
58 memset(dst + (r + 1) * stride + size, above[bs - 1], bs - size);
62 static INLINE void d45_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
63 const uint8_t *above, const uint8_t *left) {
64 const uint8_t above_right = above[bs - 1];
65 const uint8_t *const dst_row0 = dst;
69 for (x = 0; x < bs - 1; ++x) {
70 dst[x] = AVG3(above[x], above[x + 1], above[x + 2]);
72 dst[bs - 1] = above_right;
74 for (x = 1, size = bs - 2; x < bs; ++x, --size) {
75 memcpy(dst, dst_row0 + x, size);
76 memset(dst + size, above_right, x + 1);
81 static INLINE void d117_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
82 const uint8_t *above, const uint8_t *left) {
86 for (c = 0; c < bs; c++) dst[c] = AVG2(above[c - 1], above[c]);
90 dst[0] = AVG3(left[0], above[-1], above[0]);
91 for (c = 1; c < bs; c++) dst[c] = AVG3(above[c - 2], above[c - 1], above[c]);
94 // the rest of first col
95 dst[0] = AVG3(above[-1], left[0], left[1]);
96 for (r = 3; r < bs; ++r)
97 dst[(r - 2) * stride] = AVG3(left[r - 3], left[r - 2], left[r - 1]);
99 // the rest of the block
100 for (r = 2; r < bs; ++r) {
101 for (c = 1; c < bs; c++) dst[c] = dst[-2 * stride + c - 1];
106 static INLINE void d135_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
107 const uint8_t *above, const uint8_t *left) {
109 #if defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ > 7
110 // silence a spurious -Warray-bounds warning, possibly related to:
111 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56273
114 uint8_t border[32 + 32 - 1]; // outer border from bottom-left to top-right
117 // dst(bs, bs - 2)[0], i.e., border starting at bottom-left
118 for (i = 0; i < bs - 2; ++i) {
119 border[i] = AVG3(left[bs - 3 - i], left[bs - 2 - i], left[bs - 1 - i]);
121 border[bs - 2] = AVG3(above[-1], left[0], left[1]);
122 border[bs - 1] = AVG3(left[0], above[-1], above[0]);
123 border[bs - 0] = AVG3(above[-1], above[0], above[1]);
124 // dst[0][2, size), i.e., remaining top border ascending
125 for (i = 0; i < bs - 2; ++i) {
126 border[bs + 1 + i] = AVG3(above[i], above[i + 1], above[i + 2]);
129 for (i = 0; i < bs; ++i) {
130 memcpy(dst + i * stride, border + bs - 1 - i, bs);
134 static INLINE void d153_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
135 const uint8_t *above, const uint8_t *left) {
137 dst[0] = AVG2(above[-1], left[0]);
138 for (r = 1; r < bs; r++) dst[r * stride] = AVG2(left[r - 1], left[r]);
141 dst[0] = AVG3(left[0], above[-1], above[0]);
142 dst[stride] = AVG3(above[-1], left[0], left[1]);
143 for (r = 2; r < bs; r++)
144 dst[r * stride] = AVG3(left[r - 2], left[r - 1], left[r]);
147 for (c = 0; c < bs - 2; c++)
148 dst[c] = AVG3(above[c - 1], above[c], above[c + 1]);
151 for (r = 1; r < bs; ++r) {
152 for (c = 0; c < bs - 2; c++) dst[c] = dst[-stride + c - 2];
157 static INLINE void v_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
158 const uint8_t *above, const uint8_t *left) {
162 for (r = 0; r < bs; r++) {
163 memcpy(dst, above, bs);
168 static INLINE void h_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
169 const uint8_t *above, const uint8_t *left) {
173 for (r = 0; r < bs; r++) {
174 memset(dst, left[r], bs);
179 static INLINE void tm_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
180 const uint8_t *above, const uint8_t *left) {
182 int ytop_left = above[-1];
184 for (r = 0; r < bs; r++) {
185 for (c = 0; c < bs; c++)
186 dst[c] = clip_pixel(left[r] + above[c] - ytop_left);
191 static INLINE void dc_128_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
192 const uint8_t *above, const uint8_t *left) {
197 for (r = 0; r < bs; r++) {
198 memset(dst, 128, bs);
203 static INLINE void dc_left_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
204 const uint8_t *above,
205 const uint8_t *left) {
206 int i, r, expected_dc, sum = 0;
209 for (i = 0; i < bs; i++) sum += left[i];
210 expected_dc = (sum + (bs >> 1)) / bs;
212 for (r = 0; r < bs; r++) {
213 memset(dst, expected_dc, bs);
218 static INLINE void dc_top_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
219 const uint8_t *above, const uint8_t *left) {
220 int i, r, expected_dc, sum = 0;
223 for (i = 0; i < bs; i++) sum += above[i];
224 expected_dc = (sum + (bs >> 1)) / bs;
226 for (r = 0; r < bs; r++) {
227 memset(dst, expected_dc, bs);
232 static INLINE void dc_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
233 const uint8_t *above, const uint8_t *left) {
234 int i, r, expected_dc, sum = 0;
235 const int count = 2 * bs;
237 for (i = 0; i < bs; i++) {
242 expected_dc = (sum + (count >> 1)) / count;
244 for (r = 0; r < bs; r++) {
245 memset(dst, expected_dc, bs);
250 void vpx_he_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
251 const uint8_t *above, const uint8_t *left) {
252 const int H = above[-1];
253 const int I = left[0];
254 const int J = left[1];
255 const int K = left[2];
256 const int L = left[3];
258 memset(dst + stride * 0, AVG3(H, I, J), 4);
259 memset(dst + stride * 1, AVG3(I, J, K), 4);
260 memset(dst + stride * 2, AVG3(J, K, L), 4);
261 memset(dst + stride * 3, AVG3(K, L, L), 4);
264 void vpx_ve_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
265 const uint8_t *above, const uint8_t *left) {
266 const int H = above[-1];
267 const int I = above[0];
268 const int J = above[1];
269 const int K = above[2];
270 const int L = above[3];
271 const int M = above[4];
274 dst[0] = AVG3(H, I, J);
275 dst[1] = AVG3(I, J, K);
276 dst[2] = AVG3(J, K, L);
277 dst[3] = AVG3(K, L, M);
278 memcpy(dst + stride * 1, dst, 4);
279 memcpy(dst + stride * 2, dst, 4);
280 memcpy(dst + stride * 3, dst, 4);
283 void vpx_d207_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
284 const uint8_t *above, const uint8_t *left) {
285 const int I = left[0];
286 const int J = left[1];
287 const int K = left[2];
288 const int L = left[3];
290 DST(0, 0) = AVG2(I, J);
291 DST(2, 0) = DST(0, 1) = AVG2(J, K);
292 DST(2, 1) = DST(0, 2) = AVG2(K, L);
293 DST(1, 0) = AVG3(I, J, K);
294 DST(3, 0) = DST(1, 1) = AVG3(J, K, L);
295 DST(3, 1) = DST(1, 2) = AVG3(K, L, L);
296 DST(3, 2) = DST(2, 2) = DST(0, 3) = DST(1, 3) = DST(2, 3) = DST(3, 3) = L;
299 void vpx_d63_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
300 const uint8_t *above, const uint8_t *left) {
301 const int A = above[0];
302 const int B = above[1];
303 const int C = above[2];
304 const int D = above[3];
305 const int E = above[4];
306 const int F = above[5];
307 const int G = above[6];
309 DST(0, 0) = AVG2(A, B);
310 DST(1, 0) = DST(0, 2) = AVG2(B, C);
311 DST(2, 0) = DST(1, 2) = AVG2(C, D);
312 DST(3, 0) = DST(2, 2) = AVG2(D, E);
313 DST(3, 2) = AVG2(E, F); // differs from vp8
315 DST(0, 1) = AVG3(A, B, C);
316 DST(1, 1) = DST(0, 3) = AVG3(B, C, D);
317 DST(2, 1) = DST(1, 3) = AVG3(C, D, E);
318 DST(3, 1) = DST(2, 3) = AVG3(D, E, F);
319 DST(3, 3) = AVG3(E, F, G); // differs from vp8
322 void vpx_d63e_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
323 const uint8_t *above, const uint8_t *left) {
324 const int A = above[0];
325 const int B = above[1];
326 const int C = above[2];
327 const int D = above[3];
328 const int E = above[4];
329 const int F = above[5];
330 const int G = above[6];
331 const int H = above[7];
333 DST(0, 0) = AVG2(A, B);
334 DST(1, 0) = DST(0, 2) = AVG2(B, C);
335 DST(2, 0) = DST(1, 2) = AVG2(C, D);
336 DST(3, 0) = DST(2, 2) = AVG2(D, E);
337 DST(3, 2) = AVG3(E, F, G);
339 DST(0, 1) = AVG3(A, B, C);
340 DST(1, 1) = DST(0, 3) = AVG3(B, C, D);
341 DST(2, 1) = DST(1, 3) = AVG3(C, D, E);
342 DST(3, 1) = DST(2, 3) = AVG3(D, E, F);
343 DST(3, 3) = AVG3(F, G, H);
346 void vpx_d45_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
347 const uint8_t *above, const uint8_t *left) {
348 const int A = above[0];
349 const int B = above[1];
350 const int C = above[2];
351 const int D = above[3];
352 const int E = above[4];
353 const int F = above[5];
354 const int G = above[6];
355 const int H = above[7];
358 DST(0, 0) = AVG3(A, B, C);
359 DST(1, 0) = DST(0, 1) = AVG3(B, C, D);
360 DST(2, 0) = DST(1, 1) = DST(0, 2) = AVG3(C, D, E);
361 DST(3, 0) = DST(2, 1) = DST(1, 2) = DST(0, 3) = AVG3(D, E, F);
362 DST(3, 1) = DST(2, 2) = DST(1, 3) = AVG3(E, F, G);
363 DST(3, 2) = DST(2, 3) = AVG3(F, G, H);
364 DST(3, 3) = H; // differs from vp8
367 void vpx_d45e_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
368 const uint8_t *above, const uint8_t *left) {
369 const int A = above[0];
370 const int B = above[1];
371 const int C = above[2];
372 const int D = above[3];
373 const int E = above[4];
374 const int F = above[5];
375 const int G = above[6];
376 const int H = above[7];
379 DST(0, 0) = AVG3(A, B, C);
380 DST(1, 0) = DST(0, 1) = AVG3(B, C, D);
381 DST(2, 0) = DST(1, 1) = DST(0, 2) = AVG3(C, D, E);
382 DST(3, 0) = DST(2, 1) = DST(1, 2) = DST(0, 3) = AVG3(D, E, F);
383 DST(3, 1) = DST(2, 2) = DST(1, 3) = AVG3(E, F, G);
384 DST(3, 2) = DST(2, 3) = AVG3(F, G, H);
385 DST(3, 3) = AVG3(G, H, H);
388 void vpx_d117_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
389 const uint8_t *above, const uint8_t *left) {
390 const int I = left[0];
391 const int J = left[1];
392 const int K = left[2];
393 const int X = above[-1];
394 const int A = above[0];
395 const int B = above[1];
396 const int C = above[2];
397 const int D = above[3];
398 DST(0, 0) = DST(1, 2) = AVG2(X, A);
399 DST(1, 0) = DST(2, 2) = AVG2(A, B);
400 DST(2, 0) = DST(3, 2) = AVG2(B, C);
401 DST(3, 0) = AVG2(C, D);
403 DST(0, 3) = AVG3(K, J, I);
404 DST(0, 2) = AVG3(J, I, X);
405 DST(0, 1) = DST(1, 3) = AVG3(I, X, A);
406 DST(1, 1) = DST(2, 3) = AVG3(X, A, B);
407 DST(2, 1) = DST(3, 3) = AVG3(A, B, C);
408 DST(3, 1) = AVG3(B, C, D);
411 void vpx_d135_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
412 const uint8_t *above, const uint8_t *left) {
413 const int I = left[0];
414 const int J = left[1];
415 const int K = left[2];
416 const int L = left[3];
417 const int X = above[-1];
418 const int A = above[0];
419 const int B = above[1];
420 const int C = above[2];
421 const int D = above[3];
423 DST(0, 3) = AVG3(J, K, L);
424 DST(1, 3) = DST(0, 2) = AVG3(I, J, K);
425 DST(2, 3) = DST(1, 2) = DST(0, 1) = AVG3(X, I, J);
426 DST(3, 3) = DST(2, 2) = DST(1, 1) = DST(0, 0) = AVG3(A, X, I);
427 DST(3, 2) = DST(2, 1) = DST(1, 0) = AVG3(B, A, X);
428 DST(3, 1) = DST(2, 0) = AVG3(C, B, A);
429 DST(3, 0) = AVG3(D, C, B);
432 void vpx_d153_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
433 const uint8_t *above, const uint8_t *left) {
434 const int I = left[0];
435 const int J = left[1];
436 const int K = left[2];
437 const int L = left[3];
438 const int X = above[-1];
439 const int A = above[0];
440 const int B = above[1];
441 const int C = above[2];
443 DST(0, 0) = DST(2, 1) = AVG2(I, X);
444 DST(0, 1) = DST(2, 2) = AVG2(J, I);
445 DST(0, 2) = DST(2, 3) = AVG2(K, J);
446 DST(0, 3) = AVG2(L, K);
448 DST(3, 0) = AVG3(A, B, C);
449 DST(2, 0) = AVG3(X, A, B);
450 DST(1, 0) = DST(3, 1) = AVG3(I, X, A);
451 DST(1, 1) = DST(3, 2) = AVG3(J, I, X);
452 DST(1, 2) = DST(3, 3) = AVG3(K, J, I);
453 DST(1, 3) = AVG3(L, K, J);
456 #if CONFIG_VP9_HIGHBITDEPTH
457 static INLINE void highbd_d207_predictor(uint16_t *dst, ptrdiff_t stride,
458 int bs, const uint16_t *above,
459 const uint16_t *left, int bd) {
465 for (r = 0; r < bs - 1; ++r) {
466 dst[r * stride] = AVG2(left[r], left[r + 1]);
468 dst[(bs - 1) * stride] = left[bs - 1];
472 for (r = 0; r < bs - 2; ++r) {
473 dst[r * stride] = AVG3(left[r], left[r + 1], left[r + 2]);
475 dst[(bs - 2) * stride] = AVG3(left[bs - 2], left[bs - 1], left[bs - 1]);
476 dst[(bs - 1) * stride] = left[bs - 1];
480 for (c = 0; c < bs - 2; ++c) dst[(bs - 1) * stride + c] = left[bs - 1];
482 for (r = bs - 2; r >= 0; --r) {
483 for (c = 0; c < bs - 2; ++c)
484 dst[r * stride + c] = dst[(r + 1) * stride + c - 2];
488 static INLINE void highbd_d63_predictor(uint16_t *dst, ptrdiff_t stride, int bs,
489 const uint16_t *above,
490 const uint16_t *left, int bd) {
494 for (r = 0; r < bs; ++r) {
495 for (c = 0; c < bs; ++c) {
496 dst[c] = r & 1 ? AVG3(above[(r >> 1) + c], above[(r >> 1) + c + 1],
497 above[(r >> 1) + c + 2])
498 : AVG2(above[(r >> 1) + c], above[(r >> 1) + c + 1]);
504 static INLINE void highbd_d45_predictor(uint16_t *dst, ptrdiff_t stride, int bs,
505 const uint16_t *above,
506 const uint16_t *left, int bd) {
510 for (r = 0; r < bs; ++r) {
511 for (c = 0; c < bs; ++c) {
512 dst[c] = r + c + 2 < bs * 2
513 ? AVG3(above[r + c], above[r + c + 1], above[r + c + 2])
520 static INLINE void highbd_d117_predictor(uint16_t *dst, ptrdiff_t stride,
521 int bs, const uint16_t *above,
522 const uint16_t *left, int bd) {
527 for (c = 0; c < bs; c++) dst[c] = AVG2(above[c - 1], above[c]);
531 dst[0] = AVG3(left[0], above[-1], above[0]);
532 for (c = 1; c < bs; c++) dst[c] = AVG3(above[c - 2], above[c - 1], above[c]);
535 // the rest of first col
536 dst[0] = AVG3(above[-1], left[0], left[1]);
537 for (r = 3; r < bs; ++r)
538 dst[(r - 2) * stride] = AVG3(left[r - 3], left[r - 2], left[r - 1]);
540 // the rest of the block
541 for (r = 2; r < bs; ++r) {
542 for (c = 1; c < bs; c++) dst[c] = dst[-2 * stride + c - 1];
547 static INLINE void highbd_d135_predictor(uint16_t *dst, ptrdiff_t stride,
548 int bs, const uint16_t *above,
549 const uint16_t *left, int bd) {
551 #if defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ > 7
552 // silence a spurious -Warray-bounds warning, possibly related to:
553 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56273
556 uint16_t border[32 + 32 - 1]; // outer border from bottom-left to top-right
560 // dst(bs, bs - 2)[0], i.e., border starting at bottom-left
561 for (i = 0; i < bs - 2; ++i) {
562 border[i] = AVG3(left[bs - 3 - i], left[bs - 2 - i], left[bs - 1 - i]);
564 border[bs - 2] = AVG3(above[-1], left[0], left[1]);
565 border[bs - 1] = AVG3(left[0], above[-1], above[0]);
566 border[bs - 0] = AVG3(above[-1], above[0], above[1]);
567 // dst[0][2, size), i.e., remaining top border ascending
568 for (i = 0; i < bs - 2; ++i) {
569 border[bs + 1 + i] = AVG3(above[i], above[i + 1], above[i + 2]);
572 for (i = 0; i < bs; ++i) {
573 memcpy(dst + i * stride, border + bs - 1 - i, bs * sizeof(dst[0]));
577 static INLINE void highbd_d153_predictor(uint16_t *dst, ptrdiff_t stride,
578 int bs, const uint16_t *above,
579 const uint16_t *left, int bd) {
582 dst[0] = AVG2(above[-1], left[0]);
583 for (r = 1; r < bs; r++) dst[r * stride] = AVG2(left[r - 1], left[r]);
586 dst[0] = AVG3(left[0], above[-1], above[0]);
587 dst[stride] = AVG3(above[-1], left[0], left[1]);
588 for (r = 2; r < bs; r++)
589 dst[r * stride] = AVG3(left[r - 2], left[r - 1], left[r]);
592 for (c = 0; c < bs - 2; c++)
593 dst[c] = AVG3(above[c - 1], above[c], above[c + 1]);
596 for (r = 1; r < bs; ++r) {
597 for (c = 0; c < bs - 2; c++) dst[c] = dst[-stride + c - 2];
602 static INLINE void highbd_v_predictor(uint16_t *dst, ptrdiff_t stride, int bs,
603 const uint16_t *above,
604 const uint16_t *left, int bd) {
608 for (r = 0; r < bs; r++) {
609 memcpy(dst, above, bs * sizeof(uint16_t));
614 static INLINE void highbd_h_predictor(uint16_t *dst, ptrdiff_t stride, int bs,
615 const uint16_t *above,
616 const uint16_t *left, int bd) {
620 for (r = 0; r < bs; r++) {
621 vpx_memset16(dst, left[r], bs);
626 static INLINE void highbd_tm_predictor(uint16_t *dst, ptrdiff_t stride, int bs,
627 const uint16_t *above,
628 const uint16_t *left, int bd) {
630 int ytop_left = above[-1];
633 for (r = 0; r < bs; r++) {
634 for (c = 0; c < bs; c++)
635 dst[c] = clip_pixel_highbd(left[r] + above[c] - ytop_left, bd);
640 static INLINE void highbd_dc_128_predictor(uint16_t *dst, ptrdiff_t stride,
641 int bs, const uint16_t *above,
642 const uint16_t *left, int bd) {
647 for (r = 0; r < bs; r++) {
648 vpx_memset16(dst, 128 << (bd - 8), bs);
653 static INLINE void highbd_dc_left_predictor(uint16_t *dst, ptrdiff_t stride,
654 int bs, const uint16_t *above,
655 const uint16_t *left, int bd) {
656 int i, r, expected_dc, sum = 0;
660 for (i = 0; i < bs; i++) sum += left[i];
661 expected_dc = (sum + (bs >> 1)) / bs;
663 for (r = 0; r < bs; r++) {
664 vpx_memset16(dst, expected_dc, bs);
669 static INLINE void highbd_dc_top_predictor(uint16_t *dst, ptrdiff_t stride,
670 int bs, const uint16_t *above,
671 const uint16_t *left, int bd) {
672 int i, r, expected_dc, sum = 0;
676 for (i = 0; i < bs; i++) sum += above[i];
677 expected_dc = (sum + (bs >> 1)) / bs;
679 for (r = 0; r < bs; r++) {
680 vpx_memset16(dst, expected_dc, bs);
685 static INLINE void highbd_dc_predictor(uint16_t *dst, ptrdiff_t stride, int bs,
686 const uint16_t *above,
687 const uint16_t *left, int bd) {
688 int i, r, expected_dc, sum = 0;
689 const int count = 2 * bs;
692 for (i = 0; i < bs; i++) {
697 expected_dc = (sum + (count >> 1)) / count;
699 for (r = 0; r < bs; r++) {
700 vpx_memset16(dst, expected_dc, bs);
705 void vpx_highbd_d207_predictor_4x4_c(uint16_t *dst, ptrdiff_t stride,
706 const uint16_t *above,
707 const uint16_t *left, int bd) {
708 const int I = left[0];
709 const int J = left[1];
710 const int K = left[2];
711 const int L = left[3];
714 DST(0, 0) = AVG2(I, J);
715 DST(2, 0) = DST(0, 1) = AVG2(J, K);
716 DST(2, 1) = DST(0, 2) = AVG2(K, L);
717 DST(1, 0) = AVG3(I, J, K);
718 DST(3, 0) = DST(1, 1) = AVG3(J, K, L);
719 DST(3, 1) = DST(1, 2) = AVG3(K, L, L);
720 DST(3, 2) = DST(2, 2) = DST(0, 3) = DST(1, 3) = DST(2, 3) = DST(3, 3) = L;
723 void vpx_highbd_d63_predictor_4x4_c(uint16_t *dst, ptrdiff_t stride,
724 const uint16_t *above, const uint16_t *left,
726 const int A = above[0];
727 const int B = above[1];
728 const int C = above[2];
729 const int D = above[3];
730 const int E = above[4];
731 const int F = above[5];
732 const int G = above[6];
735 DST(0, 0) = AVG2(A, B);
736 DST(1, 0) = DST(0, 2) = AVG2(B, C);
737 DST(2, 0) = DST(1, 2) = AVG2(C, D);
738 DST(3, 0) = DST(2, 2) = AVG2(D, E);
739 DST(3, 2) = AVG2(E, F); // differs from vp8
741 DST(0, 1) = AVG3(A, B, C);
742 DST(1, 1) = DST(0, 3) = AVG3(B, C, D);
743 DST(2, 1) = DST(1, 3) = AVG3(C, D, E);
744 DST(3, 1) = DST(2, 3) = AVG3(D, E, F);
745 DST(3, 3) = AVG3(E, F, G); // differs from vp8
748 void vpx_highbd_d45_predictor_4x4_c(uint16_t *dst, ptrdiff_t stride,
749 const uint16_t *above, const uint16_t *left,
751 const int A = above[0];
752 const int B = above[1];
753 const int C = above[2];
754 const int D = above[3];
755 const int E = above[4];
756 const int F = above[5];
757 const int G = above[6];
758 const int H = above[7];
761 DST(0, 0) = AVG3(A, B, C);
762 DST(1, 0) = DST(0, 1) = AVG3(B, C, D);
763 DST(2, 0) = DST(1, 1) = DST(0, 2) = AVG3(C, D, E);
764 DST(3, 0) = DST(2, 1) = DST(1, 2) = DST(0, 3) = AVG3(D, E, F);
765 DST(3, 1) = DST(2, 2) = DST(1, 3) = AVG3(E, F, G);
766 DST(3, 2) = DST(2, 3) = AVG3(F, G, H);
767 DST(3, 3) = H; // differs from vp8
770 void vpx_highbd_d117_predictor_4x4_c(uint16_t *dst, ptrdiff_t stride,
771 const uint16_t *above,
772 const uint16_t *left, int bd) {
773 const int I = left[0];
774 const int J = left[1];
775 const int K = left[2];
776 const int X = above[-1];
777 const int A = above[0];
778 const int B = above[1];
779 const int C = above[2];
780 const int D = above[3];
782 DST(0, 0) = DST(1, 2) = AVG2(X, A);
783 DST(1, 0) = DST(2, 2) = AVG2(A, B);
784 DST(2, 0) = DST(3, 2) = AVG2(B, C);
785 DST(3, 0) = AVG2(C, D);
787 DST(0, 3) = AVG3(K, J, I);
788 DST(0, 2) = AVG3(J, I, X);
789 DST(0, 1) = DST(1, 3) = AVG3(I, X, A);
790 DST(1, 1) = DST(2, 3) = AVG3(X, A, B);
791 DST(2, 1) = DST(3, 3) = AVG3(A, B, C);
792 DST(3, 1) = AVG3(B, C, D);
795 void vpx_highbd_d135_predictor_4x4_c(uint16_t *dst, ptrdiff_t stride,
796 const uint16_t *above,
797 const uint16_t *left, int bd) {
798 const int I = left[0];
799 const int J = left[1];
800 const int K = left[2];
801 const int L = left[3];
802 const int X = above[-1];
803 const int A = above[0];
804 const int B = above[1];
805 const int C = above[2];
806 const int D = above[3];
808 DST(0, 3) = AVG3(J, K, L);
809 DST(1, 3) = DST(0, 2) = AVG3(I, J, K);
810 DST(2, 3) = DST(1, 2) = DST(0, 1) = AVG3(X, I, J);
811 DST(3, 3) = DST(2, 2) = DST(1, 1) = DST(0, 0) = AVG3(A, X, I);
812 DST(3, 2) = DST(2, 1) = DST(1, 0) = AVG3(B, A, X);
813 DST(3, 1) = DST(2, 0) = AVG3(C, B, A);
814 DST(3, 0) = AVG3(D, C, B);
817 void vpx_highbd_d153_predictor_4x4_c(uint16_t *dst, ptrdiff_t stride,
818 const uint16_t *above,
819 const uint16_t *left, int bd) {
820 const int I = left[0];
821 const int J = left[1];
822 const int K = left[2];
823 const int L = left[3];
824 const int X = above[-1];
825 const int A = above[0];
826 const int B = above[1];
827 const int C = above[2];
830 DST(0, 0) = DST(2, 1) = AVG2(I, X);
831 DST(0, 1) = DST(2, 2) = AVG2(J, I);
832 DST(0, 2) = DST(2, 3) = AVG2(K, J);
833 DST(0, 3) = AVG2(L, K);
835 DST(3, 0) = AVG3(A, B, C);
836 DST(2, 0) = AVG3(X, A, B);
837 DST(1, 0) = DST(3, 1) = AVG3(I, X, A);
838 DST(1, 1) = DST(3, 2) = AVG3(J, I, X);
839 DST(1, 2) = DST(3, 3) = AVG3(K, J, I);
840 DST(1, 3) = AVG3(L, K, J);
842 #endif // CONFIG_VP9_HIGHBITDEPTH
844 // This serves as a wrapper function, so that all the prediction functions
845 // can be unified and accessed as a pointer array. Note that the boundary
846 // above and left are not necessarily used all the time.
847 #define intra_pred_sized(type, size) \
848 void vpx_##type##_predictor_##size##x##size##_c( \
849 uint8_t *dst, ptrdiff_t stride, const uint8_t *above, \
850 const uint8_t *left) { \
851 type##_predictor(dst, stride, size, above, left); \
854 #if CONFIG_VP9_HIGHBITDEPTH
855 #define intra_pred_highbd_sized(type, size) \
856 void vpx_highbd_##type##_predictor_##size##x##size##_c( \
857 uint16_t *dst, ptrdiff_t stride, const uint16_t *above, \
858 const uint16_t *left, int bd) { \
859 highbd_##type##_predictor(dst, stride, size, above, left, bd); \
862 /* clang-format off */
863 #define intra_pred_allsizes(type) \
864 intra_pred_sized(type, 4) \
865 intra_pred_sized(type, 8) \
866 intra_pred_sized(type, 16) \
867 intra_pred_sized(type, 32) \
868 intra_pred_highbd_sized(type, 4) \
869 intra_pred_highbd_sized(type, 8) \
870 intra_pred_highbd_sized(type, 16) \
871 intra_pred_highbd_sized(type, 32)
873 #define intra_pred_no_4x4(type) \
874 intra_pred_sized(type, 8) \
875 intra_pred_sized(type, 16) \
876 intra_pred_sized(type, 32) \
877 intra_pred_highbd_sized(type, 8) \
878 intra_pred_highbd_sized(type, 16) \
879 intra_pred_highbd_sized(type, 32)
882 #define intra_pred_allsizes(type) \
883 intra_pred_sized(type, 4) \
884 intra_pred_sized(type, 8) \
885 intra_pred_sized(type, 16) \
886 intra_pred_sized(type, 32)
888 #define intra_pred_no_4x4(type) \
889 intra_pred_sized(type, 8) \
890 intra_pred_sized(type, 16) \
891 intra_pred_sized(type, 32)
892 #endif // CONFIG_VP9_HIGHBITDEPTH
894 intra_pred_no_4x4(d207)
895 intra_pred_no_4x4(d63)
896 intra_pred_no_4x4(d45)
897 intra_pred_no_4x4(d117)
898 intra_pred_no_4x4(d135)
899 intra_pred_no_4x4(d153)
900 intra_pred_allsizes(v)
901 intra_pred_allsizes(h)
902 intra_pred_allsizes(tm)
903 intra_pred_allsizes(dc_128)
904 intra_pred_allsizes(dc_left)
905 intra_pred_allsizes(dc_top)
906 intra_pred_allsizes(dc)
907 /* clang-format on */
908 #undef intra_pred_allsizes