intrapred.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  1. /*
  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. #include "./vpx_config.h"
  11. #include "./vpx_dsp_rtcd.h"
  12. #include "vpx_dsp/vpx_dsp_common.h"
  13. #include "vpx_mem/vpx_mem.h"
  14. #define DST(x, y) dst[(x) + (y) * stride]
  15. #define AVG3(a, b, c) (((a) + 2 * (b) + (c) + 2) >> 2)
  16. #define AVG2(a, b) (((a) + (b) + 1) >> 1)
  17. static INLINE void d207_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
  18. const uint8_t *above, const uint8_t *left) {
  19. int r, c;
  20. (void) above;
  21. // first column
  22. for (r = 0; r < bs - 1; ++r)
  23. dst[r * stride] = AVG2(left[r], left[r + 1]);
  24. dst[(bs - 1) * stride] = left[bs - 1];
  25. dst++;
  26. // second column
  27. for (r = 0; r < bs - 2; ++r)
  28. dst[r * stride] = AVG3(left[r], left[r + 1], left[r + 2]);
  29. dst[(bs - 2) * stride] = AVG3(left[bs - 2], left[bs - 1], left[bs - 1]);
  30. dst[(bs - 1) * stride] = left[bs - 1];
  31. dst++;
  32. // rest of last row
  33. for (c = 0; c < bs - 2; ++c)
  34. dst[(bs - 1) * stride + c] = left[bs - 1];
  35. for (r = bs - 2; r >= 0; --r)
  36. for (c = 0; c < bs - 2; ++c)
  37. dst[r * stride + c] = dst[(r + 1) * stride + c - 2];
  38. }
  39. #if CONFIG_MISC_FIXES
  40. static INLINE void d207e_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
  41. const uint8_t *above, const uint8_t *left) {
  42. int r, c;
  43. (void) above;
  44. for (r = 0; r < bs; ++r) {
  45. for (c = 0; c < bs; ++c) {
  46. dst[c] = c & 1 ? AVG3(left[(c >> 1) + r], left[(c >> 1) + r + 1],
  47. left[(c >> 1) + r + 2])
  48. : AVG2(left[(c >> 1) + r], left[(c >> 1) + r + 1]);
  49. }
  50. dst += stride;
  51. }
  52. }
  53. #endif // CONFIG_MISC_FIXES
  54. static INLINE void d63_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
  55. const uint8_t *above, const uint8_t *left) {
  56. int r, c;
  57. int size;
  58. (void)left;
  59. for (c = 0; c < bs; ++c) {
  60. dst[c] = AVG2(above[c], above[c + 1]);
  61. dst[stride + c] = AVG3(above[c], above[c + 1], above[c + 2]);
  62. }
  63. for (r = 2, size = bs - 2; r < bs; r += 2, --size) {
  64. memcpy(dst + (r + 0) * stride, dst + (r >> 1), size);
  65. memset(dst + (r + 0) * stride + size, above[bs - 1], bs - size);
  66. memcpy(dst + (r + 1) * stride, dst + stride + (r >> 1), size);
  67. memset(dst + (r + 1) * stride + size, above[bs - 1], bs - size);
  68. }
  69. }
  70. #if CONFIG_MISC_FIXES
  71. static INLINE void d63e_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
  72. const uint8_t *above, const uint8_t *left) {
  73. int r, c;
  74. (void) left;
  75. for (r = 0; r < bs; ++r) {
  76. for (c = 0; c < bs; ++c) {
  77. dst[c] = r & 1 ? AVG3(above[(r >> 1) + c], above[(r >> 1) + c + 1],
  78. above[(r >> 1) + c + 2])
  79. : AVG2(above[(r >> 1) + c], above[(r >> 1) + c + 1]);
  80. }
  81. dst += stride;
  82. }
  83. }
  84. #endif // CONFIG_MISC_FIXES
  85. static INLINE void d45_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
  86. const uint8_t *above, const uint8_t *left) {
  87. const uint8_t above_right = above[bs - 1];
  88. const uint8_t *const dst_row0 = dst;
  89. int x, size;
  90. (void)left;
  91. for (x = 0; x < bs - 1; ++x) {
  92. dst[x] = AVG3(above[x], above[x + 1], above[x + 2]);
  93. }
  94. dst[bs - 1] = above_right;
  95. dst += stride;
  96. for (x = 1, size = bs - 2; x < bs; ++x, --size) {
  97. memcpy(dst, dst_row0 + x, size);
  98. memset(dst + size, above_right, x + 1);
  99. dst += stride;
  100. }
  101. }
  102. #if CONFIG_MISC_FIXES
  103. static INLINE void d45e_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
  104. const uint8_t *above, const uint8_t *left) {
  105. int r, c;
  106. (void) left;
  107. for (r = 0; r < bs; ++r) {
  108. for (c = 0; c < bs; ++c) {
  109. dst[c] = AVG3(above[r + c], above[r + c + 1],
  110. above[r + c + 1 + (r + c + 2 < bs * 2)]);
  111. }
  112. dst += stride;
  113. }
  114. }
  115. #endif // CONFIG_MISC_FIXES
  116. static INLINE void d117_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
  117. const uint8_t *above, const uint8_t *left) {
  118. int r, c;
  119. // first row
  120. for (c = 0; c < bs; c++)
  121. dst[c] = AVG2(above[c - 1], above[c]);
  122. dst += stride;
  123. // second row
  124. dst[0] = AVG3(left[0], above[-1], above[0]);
  125. for (c = 1; c < bs; c++)
  126. dst[c] = AVG3(above[c - 2], above[c - 1], above[c]);
  127. dst += stride;
  128. // the rest of first col
  129. dst[0] = AVG3(above[-1], left[0], left[1]);
  130. for (r = 3; r < bs; ++r)
  131. dst[(r - 2) * stride] = AVG3(left[r - 3], left[r - 2], left[r - 1]);
  132. // the rest of the block
  133. for (r = 2; r < bs; ++r) {
  134. for (c = 1; c < bs; c++)
  135. dst[c] = dst[-2 * stride + c - 1];
  136. dst += stride;
  137. }
  138. }
  139. static INLINE void d135_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
  140. const uint8_t *above, const uint8_t *left) {
  141. int i;
  142. #if defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ > 7
  143. // silence a spurious -Warray-bounds warning, possibly related to:
  144. // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56273
  145. uint8_t border[69];
  146. #else
  147. uint8_t border[32 + 32 - 1]; // outer border from bottom-left to top-right
  148. #endif
  149. // dst(bs, bs - 2)[0], i.e., border starting at bottom-left
  150. for (i = 0; i < bs - 2; ++i) {
  151. border[i] = AVG3(left[bs - 3 - i], left[bs - 2 - i], left[bs - 1 - i]);
  152. }
  153. border[bs - 2] = AVG3(above[-1], left[0], left[1]);
  154. border[bs - 1] = AVG3(left[0], above[-1], above[0]);
  155. border[bs - 0] = AVG3(above[-1], above[0], above[1]);
  156. // dst[0][2, size), i.e., remaining top border ascending
  157. for (i = 0; i < bs - 2; ++i) {
  158. border[bs + 1 + i] = AVG3(above[i], above[i + 1], above[i + 2]);
  159. }
  160. for (i = 0; i < bs; ++i) {
  161. memcpy(dst + i * stride, border + bs - 1 - i, bs);
  162. }
  163. }
  164. static INLINE void d153_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
  165. const uint8_t *above, const uint8_t *left) {
  166. int r, c;
  167. dst[0] = AVG2(above[-1], left[0]);
  168. for (r = 1; r < bs; r++)
  169. dst[r * stride] = AVG2(left[r - 1], left[r]);
  170. dst++;
  171. dst[0] = AVG3(left[0], above[-1], above[0]);
  172. dst[stride] = AVG3(above[-1], left[0], left[1]);
  173. for (r = 2; r < bs; r++)
  174. dst[r * stride] = AVG3(left[r - 2], left[r - 1], left[r]);
  175. dst++;
  176. for (c = 0; c < bs - 2; c++)
  177. dst[c] = AVG3(above[c - 1], above[c], above[c + 1]);
  178. dst += stride;
  179. for (r = 1; r < bs; ++r) {
  180. for (c = 0; c < bs - 2; c++)
  181. dst[c] = dst[-stride + c - 2];
  182. dst += stride;
  183. }
  184. }
  185. static INLINE void v_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
  186. const uint8_t *above, const uint8_t *left) {
  187. int r;
  188. (void) left;
  189. for (r = 0; r < bs; r++) {
  190. memcpy(dst, above, bs);
  191. dst += stride;
  192. }
  193. }
  194. static INLINE void h_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
  195. const uint8_t *above, const uint8_t *left) {
  196. int r;
  197. (void) above;
  198. for (r = 0; r < bs; r++) {
  199. memset(dst, left[r], bs);
  200. dst += stride;
  201. }
  202. }
  203. static INLINE void tm_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
  204. const uint8_t *above, const uint8_t *left) {
  205. int r, c;
  206. int ytop_left = above[-1];
  207. for (r = 0; r < bs; r++) {
  208. for (c = 0; c < bs; c++)
  209. dst[c] = clip_pixel(left[r] + above[c] - ytop_left);
  210. dst += stride;
  211. }
  212. }
  213. static INLINE void dc_128_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
  214. const uint8_t *above, const uint8_t *left) {
  215. int r;
  216. (void) above;
  217. (void) left;
  218. for (r = 0; r < bs; r++) {
  219. memset(dst, 128, bs);
  220. dst += stride;
  221. }
  222. }
  223. static INLINE void dc_left_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
  224. const uint8_t *above,
  225. const uint8_t *left) {
  226. int i, r, expected_dc, sum = 0;
  227. (void) above;
  228. for (i = 0; i < bs; i++)
  229. sum += left[i];
  230. expected_dc = (sum + (bs >> 1)) / bs;
  231. for (r = 0; r < bs; r++) {
  232. memset(dst, expected_dc, bs);
  233. dst += stride;
  234. }
  235. }
  236. static INLINE void dc_top_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
  237. const uint8_t *above, const uint8_t *left) {
  238. int i, r, expected_dc, sum = 0;
  239. (void) left;
  240. for (i = 0; i < bs; i++)
  241. sum += above[i];
  242. expected_dc = (sum + (bs >> 1)) / bs;
  243. for (r = 0; r < bs; r++) {
  244. memset(dst, expected_dc, bs);
  245. dst += stride;
  246. }
  247. }
  248. static INLINE void dc_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
  249. const uint8_t *above, const uint8_t *left) {
  250. int i, r, expected_dc, sum = 0;
  251. const int count = 2 * bs;
  252. for (i = 0; i < bs; i++) {
  253. sum += above[i];
  254. sum += left[i];
  255. }
  256. expected_dc = (sum + (count >> 1)) / count;
  257. for (r = 0; r < bs; r++) {
  258. memset(dst, expected_dc, bs);
  259. dst += stride;
  260. }
  261. }
  262. void vpx_he_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
  263. const uint8_t *above, const uint8_t *left) {
  264. const int H = above[-1];
  265. const int I = left[0];
  266. const int J = left[1];
  267. const int K = left[2];
  268. const int L = left[3];
  269. memset(dst + stride * 0, AVG3(H, I, J), 4);
  270. memset(dst + stride * 1, AVG3(I, J, K), 4);
  271. memset(dst + stride * 2, AVG3(J, K, L), 4);
  272. memset(dst + stride * 3, AVG3(K, L, L), 4);
  273. }
  274. void vpx_ve_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
  275. const uint8_t *above, const uint8_t *left) {
  276. const int H = above[-1];
  277. const int I = above[0];
  278. const int J = above[1];
  279. const int K = above[2];
  280. const int L = above[3];
  281. const int M = above[4];
  282. (void)left;
  283. dst[0] = AVG3(H, I, J);
  284. dst[1] = AVG3(I, J, K);
  285. dst[2] = AVG3(J, K, L);
  286. dst[3] = AVG3(K, L, M);
  287. memcpy(dst + stride * 1, dst, 4);
  288. memcpy(dst + stride * 2, dst, 4);
  289. memcpy(dst + stride * 3, dst, 4);
  290. }
  291. void vpx_d207_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
  292. const uint8_t *above, const uint8_t *left) {
  293. const int I = left[0];
  294. const int J = left[1];
  295. const int K = left[2];
  296. const int L = left[3];
  297. (void)above;
  298. DST(0, 0) = AVG2(I, J);
  299. DST(2, 0) = DST(0, 1) = AVG2(J, K);
  300. DST(2, 1) = DST(0, 2) = AVG2(K, L);
  301. DST(1, 0) = AVG3(I, J, K);
  302. DST(3, 0) = DST(1, 1) = AVG3(J, K, L);
  303. DST(3, 1) = DST(1, 2) = AVG3(K, L, L);
  304. DST(3, 2) = DST(2, 2) =
  305. DST(0, 3) = DST(1, 3) = DST(2, 3) = DST(3, 3) = L;
  306. }
  307. void vpx_d63_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
  308. const uint8_t *above, const uint8_t *left) {
  309. const int A = above[0];
  310. const int B = above[1];
  311. const int C = above[2];
  312. const int D = above[3];
  313. const int E = above[4];
  314. const int F = above[5];
  315. const int G = above[6];
  316. (void)left;
  317. DST(0, 0) = AVG2(A, B);
  318. DST(1, 0) = DST(0, 2) = AVG2(B, C);
  319. DST(2, 0) = DST(1, 2) = AVG2(C, D);
  320. DST(3, 0) = DST(2, 2) = AVG2(D, E);
  321. DST(3, 2) = AVG2(E, F); // differs from vp8
  322. DST(0, 1) = AVG3(A, B, C);
  323. DST(1, 1) = DST(0, 3) = AVG3(B, C, D);
  324. DST(2, 1) = DST(1, 3) = AVG3(C, D, E);
  325. DST(3, 1) = DST(2, 3) = AVG3(D, E, F);
  326. DST(3, 3) = AVG3(E, F, G); // differs from vp8
  327. }
  328. void vpx_d63f_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
  329. const uint8_t *above, const uint8_t *left) {
  330. const int A = above[0];
  331. const int B = above[1];
  332. const int C = above[2];
  333. const int D = above[3];
  334. const int E = above[4];
  335. const int F = above[5];
  336. const int G = above[6];
  337. const int H = above[7];
  338. (void)left;
  339. DST(0, 0) = AVG2(A, B);
  340. DST(1, 0) = DST(0, 2) = AVG2(B, C);
  341. DST(2, 0) = DST(1, 2) = AVG2(C, D);
  342. DST(3, 0) = DST(2, 2) = AVG2(D, E);
  343. DST(3, 2) = AVG3(E, F, G);
  344. DST(0, 1) = AVG3(A, B, C);
  345. DST(1, 1) = DST(0, 3) = AVG3(B, C, D);
  346. DST(2, 1) = DST(1, 3) = AVG3(C, D, E);
  347. DST(3, 1) = DST(2, 3) = AVG3(D, E, F);
  348. DST(3, 3) = AVG3(F, G, H);
  349. }
  350. void vpx_d45_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
  351. const uint8_t *above, const uint8_t *left) {
  352. const int A = above[0];
  353. const int B = above[1];
  354. const int C = above[2];
  355. const int D = above[3];
  356. const int E = above[4];
  357. const int F = above[5];
  358. const int G = above[6];
  359. const int H = above[7];
  360. (void)stride;
  361. (void)left;
  362. DST(0, 0) = AVG3(A, B, C);
  363. DST(1, 0) = DST(0, 1) = AVG3(B, C, D);
  364. DST(2, 0) = DST(1, 1) = DST(0, 2) = AVG3(C, D, E);
  365. DST(3, 0) = DST(2, 1) = DST(1, 2) = DST(0, 3) = AVG3(D, E, F);
  366. DST(3, 1) = DST(2, 2) = DST(1, 3) = AVG3(E, F, G);
  367. DST(3, 2) = DST(2, 3) = AVG3(F, G, H);
  368. DST(3, 3) = H; // differs from vp8
  369. }
  370. void vpx_d45e_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
  371. const uint8_t *above, const uint8_t *left) {
  372. const int A = above[0];
  373. const int B = above[1];
  374. const int C = above[2];
  375. const int D = above[3];
  376. const int E = above[4];
  377. const int F = above[5];
  378. const int G = above[6];
  379. const int H = above[7];
  380. (void)stride;
  381. (void)left;
  382. DST(0, 0) = AVG3(A, B, C);
  383. DST(1, 0) = DST(0, 1) = AVG3(B, C, D);
  384. DST(2, 0) = DST(1, 1) = DST(0, 2) = AVG3(C, D, E);
  385. DST(3, 0) = DST(2, 1) = DST(1, 2) = DST(0, 3) = AVG3(D, E, F);
  386. DST(3, 1) = DST(2, 2) = DST(1, 3) = AVG3(E, F, G);
  387. DST(3, 2) = DST(2, 3) = AVG3(F, G, H);
  388. DST(3, 3) = AVG3(G, H, H);
  389. }
  390. void vpx_d117_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
  391. const uint8_t *above, const uint8_t *left) {
  392. const int I = left[0];
  393. const int J = left[1];
  394. const int K = left[2];
  395. const int X = above[-1];
  396. const int A = above[0];
  397. const int B = above[1];
  398. const int C = above[2];
  399. const int D = above[3];
  400. DST(0, 0) = DST(1, 2) = AVG2(X, A);
  401. DST(1, 0) = DST(2, 2) = AVG2(A, B);
  402. DST(2, 0) = DST(3, 2) = AVG2(B, C);
  403. DST(3, 0) = AVG2(C, D);
  404. DST(0, 3) = AVG3(K, J, I);
  405. DST(0, 2) = AVG3(J, I, X);
  406. DST(0, 1) = DST(1, 3) = AVG3(I, X, A);
  407. DST(1, 1) = DST(2, 3) = AVG3(X, A, B);
  408. DST(2, 1) = DST(3, 3) = AVG3(A, B, C);
  409. DST(3, 1) = AVG3(B, C, D);
  410. }
  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];
  422. (void)stride;
  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);
  430. }
  431. void vpx_d153_predictor_4x4_c(uint8_t *dst, ptrdiff_t stride,
  432. const uint8_t *above, const uint8_t *left) {
  433. const int I = left[0];
  434. const int J = left[1];
  435. const int K = left[2];
  436. const int L = left[3];
  437. const int X = above[-1];
  438. const int A = above[0];
  439. const int B = above[1];
  440. const int C = above[2];
  441. DST(0, 0) = DST(2, 1) = AVG2(I, X);
  442. DST(0, 1) = DST(2, 2) = AVG2(J, I);
  443. DST(0, 2) = DST(2, 3) = AVG2(K, J);
  444. DST(0, 3) = AVG2(L, K);
  445. DST(3, 0) = AVG3(A, B, C);
  446. DST(2, 0) = AVG3(X, A, B);
  447. DST(1, 0) = DST(3, 1) = AVG3(I, X, A);
  448. DST(1, 1) = DST(3, 2) = AVG3(J, I, X);
  449. DST(1, 2) = DST(3, 3) = AVG3(K, J, I);
  450. DST(1, 3) = AVG3(L, K, J);
  451. }
  452. #if CONFIG_VP9_HIGHBITDEPTH
  453. static INLINE void highbd_d207_predictor(uint16_t *dst, ptrdiff_t stride,
  454. int bs, const uint16_t *above,
  455. const uint16_t *left, int bd) {
  456. int r, c;
  457. (void) above;
  458. (void) bd;
  459. // First column.
  460. for (r = 0; r < bs - 1; ++r) {
  461. dst[r * stride] = AVG2(left[r], left[r + 1]);
  462. }
  463. dst[(bs - 1) * stride] = left[bs - 1];
  464. dst++;
  465. // Second column.
  466. for (r = 0; r < bs - 2; ++r) {
  467. dst[r * stride] = AVG3(left[r], left[r + 1], left[r + 2]);
  468. }
  469. dst[(bs - 2) * stride] = AVG3(left[bs - 2], left[bs - 1], left[bs - 1]);
  470. dst[(bs - 1) * stride] = left[bs - 1];
  471. dst++;
  472. // Rest of last row.
  473. for (c = 0; c < bs - 2; ++c)
  474. dst[(bs - 1) * stride + c] = left[bs - 1];
  475. for (r = bs - 2; r >= 0; --r) {
  476. for (c = 0; c < bs - 2; ++c)
  477. dst[r * stride + c] = dst[(r + 1) * stride + c - 2];
  478. }
  479. }
  480. #if CONFIG_MISC_FIXES
  481. static INLINE void highbd_d207e_predictor(uint16_t *dst, ptrdiff_t stride,
  482. int bs, const uint16_t *above,
  483. const uint16_t *left, int bd) {
  484. int r, c;
  485. (void) above;
  486. (void) bd;
  487. for (r = 0; r < bs; ++r) {
  488. for (c = 0; c < bs; ++c) {
  489. dst[c] = c & 1 ? AVG3(left[(c >> 1) + r], left[(c >> 1) + r + 1],
  490. left[(c >> 1) + r + 2])
  491. : AVG2(left[(c >> 1) + r], left[(c >> 1) + r + 1]);
  492. }
  493. dst += stride;
  494. }
  495. }
  496. #endif // CONFIG_MISC_FIXES
  497. static INLINE void highbd_d63_predictor(uint16_t *dst, ptrdiff_t stride,
  498. int bs, const uint16_t *above,
  499. const uint16_t *left, int bd) {
  500. int r, c;
  501. (void) left;
  502. (void) bd;
  503. for (r = 0; r < bs; ++r) {
  504. for (c = 0; c < bs; ++c) {
  505. dst[c] = r & 1 ? AVG3(above[(r >> 1) + c], above[(r >> 1) + c + 1],
  506. above[(r >> 1) + c + 2])
  507. : AVG2(above[(r >> 1) + c], above[(r >> 1) + c + 1]);
  508. }
  509. dst += stride;
  510. }
  511. }
  512. #define highbd_d63e_predictor highbd_d63_predictor
  513. static INLINE void highbd_d45_predictor(uint16_t *dst, ptrdiff_t stride, int bs,
  514. const uint16_t *above,
  515. const uint16_t *left, int bd) {
  516. int r, c;
  517. (void) left;
  518. (void) bd;
  519. for (r = 0; r < bs; ++r) {
  520. for (c = 0; c < bs; ++c) {
  521. dst[c] = r + c + 2 < bs * 2 ? AVG3(above[r + c], above[r + c + 1],
  522. above[r + c + 2])
  523. : above[bs * 2 - 1];
  524. }
  525. dst += stride;
  526. }
  527. }
  528. #if CONFIG_MISC_FIXES
  529. static INLINE void highbd_d45e_predictor(uint16_t *dst, ptrdiff_t stride,
  530. int bs, const uint16_t *above,
  531. const uint16_t *left, int bd) {
  532. int r, c;
  533. (void) left;
  534. (void) bd;
  535. for (r = 0; r < bs; ++r) {
  536. for (c = 0; c < bs; ++c) {
  537. dst[c] = AVG3(above[r + c], above[r + c + 1],
  538. above[r + c + 1 + (r + c + 2 < bs * 2)]);
  539. }
  540. dst += stride;
  541. }
  542. }
  543. #endif // CONFIG_MISC_FIXES
  544. static INLINE void highbd_d117_predictor(uint16_t *dst, ptrdiff_t stride,
  545. int bs, const uint16_t *above,
  546. const uint16_t *left, int bd) {
  547. int r, c;
  548. (void) bd;
  549. // first row
  550. for (c = 0; c < bs; c++)
  551. dst[c] = AVG2(above[c - 1], above[c]);
  552. dst += stride;
  553. // second row
  554. dst[0] = AVG3(left[0], above[-1], above[0]);
  555. for (c = 1; c < bs; c++)
  556. dst[c] = AVG3(above[c - 2], above[c - 1], above[c]);
  557. dst += stride;
  558. // the rest of first col
  559. dst[0] = AVG3(above[-1], left[0], left[1]);
  560. for (r = 3; r < bs; ++r)
  561. dst[(r - 2) * stride] = AVG3(left[r - 3], left[r - 2], left[r - 1]);
  562. // the rest of the block
  563. for (r = 2; r < bs; ++r) {
  564. for (c = 1; c < bs; c++)
  565. dst[c] = dst[-2 * stride + c - 1];
  566. dst += stride;
  567. }
  568. }
  569. static INLINE void highbd_d135_predictor(uint16_t *dst, ptrdiff_t stride,
  570. int bs, const uint16_t *above,
  571. const uint16_t *left, int bd) {
  572. int r, c;
  573. (void) bd;
  574. dst[0] = AVG3(left[0], above[-1], above[0]);
  575. for (c = 1; c < bs; c++)
  576. dst[c] = AVG3(above[c - 2], above[c - 1], above[c]);
  577. dst[stride] = AVG3(above[-1], left[0], left[1]);
  578. for (r = 2; r < bs; ++r)
  579. dst[r * stride] = AVG3(left[r - 2], left[r - 1], left[r]);
  580. dst += stride;
  581. for (r = 1; r < bs; ++r) {
  582. for (c = 1; c < bs; c++)
  583. dst[c] = dst[-stride + c - 1];
  584. dst += stride;
  585. }
  586. }
  587. static INLINE void highbd_d153_predictor(uint16_t *dst, ptrdiff_t stride,
  588. int bs, const uint16_t *above,
  589. const uint16_t *left, int bd) {
  590. int r, c;
  591. (void) bd;
  592. dst[0] = AVG2(above[-1], left[0]);
  593. for (r = 1; r < bs; r++)
  594. dst[r * stride] = AVG2(left[r - 1], left[r]);
  595. dst++;
  596. dst[0] = AVG3(left[0], above[-1], above[0]);
  597. dst[stride] = AVG3(above[-1], left[0], left[1]);
  598. for (r = 2; r < bs; r++)
  599. dst[r * stride] = AVG3(left[r - 2], left[r - 1], left[r]);
  600. dst++;
  601. for (c = 0; c < bs - 2; c++)
  602. dst[c] = AVG3(above[c - 1], above[c], above[c + 1]);
  603. dst += stride;
  604. for (r = 1; r < bs; ++r) {
  605. for (c = 0; c < bs - 2; c++)
  606. dst[c] = dst[-stride + c - 2];
  607. dst += stride;
  608. }
  609. }
  610. static INLINE void highbd_v_predictor(uint16_t *dst, ptrdiff_t stride,
  611. int bs, const uint16_t *above,
  612. const uint16_t *left, int bd) {
  613. int r;
  614. (void) left;
  615. (void) bd;
  616. for (r = 0; r < bs; r++) {
  617. memcpy(dst, above, bs * sizeof(uint16_t));
  618. dst += stride;
  619. }
  620. }
  621. static INLINE void highbd_h_predictor(uint16_t *dst, ptrdiff_t stride,
  622. int bs, const uint16_t *above,
  623. const uint16_t *left, int bd) {
  624. int r;
  625. (void) above;
  626. (void) bd;
  627. for (r = 0; r < bs; r++) {
  628. vpx_memset16(dst, left[r], bs);
  629. dst += stride;
  630. }
  631. }
  632. static INLINE void highbd_tm_predictor(uint16_t *dst, ptrdiff_t stride,
  633. int bs, const uint16_t *above,
  634. const uint16_t *left, int bd) {
  635. int r, c;
  636. int ytop_left = above[-1];
  637. (void) bd;
  638. for (r = 0; r < bs; r++) {
  639. for (c = 0; c < bs; c++)
  640. dst[c] = clip_pixel_highbd(left[r] + above[c] - ytop_left, bd);
  641. dst += stride;
  642. }
  643. }
  644. static INLINE void highbd_dc_128_predictor(uint16_t *dst, ptrdiff_t stride,
  645. int bs, const uint16_t *above,
  646. const uint16_t *left, int bd) {
  647. int r;
  648. (void) above;
  649. (void) left;
  650. for (r = 0; r < bs; r++) {
  651. vpx_memset16(dst, 128 << (bd - 8), bs);
  652. dst += stride;
  653. }
  654. }
  655. static INLINE void highbd_dc_left_predictor(uint16_t *dst, ptrdiff_t stride,
  656. int bs, const uint16_t *above,
  657. const uint16_t *left, int bd) {
  658. int i, r, expected_dc, sum = 0;
  659. (void) above;
  660. (void) bd;
  661. for (i = 0; i < bs; i++)
  662. sum += left[i];
  663. expected_dc = (sum + (bs >> 1)) / bs;
  664. for (r = 0; r < bs; r++) {
  665. vpx_memset16(dst, expected_dc, bs);
  666. dst += stride;
  667. }
  668. }
  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;
  673. (void) left;
  674. (void) bd;
  675. for (i = 0; i < bs; i++)
  676. sum += above[i];
  677. expected_dc = (sum + (bs >> 1)) / bs;
  678. for (r = 0; r < bs; r++) {
  679. vpx_memset16(dst, expected_dc, bs);
  680. dst += stride;
  681. }
  682. }
  683. static INLINE void highbd_dc_predictor(uint16_t *dst, ptrdiff_t stride,
  684. int bs, const uint16_t *above,
  685. const uint16_t *left, int bd) {
  686. int i, r, expected_dc, sum = 0;
  687. const int count = 2 * bs;
  688. (void) bd;
  689. for (i = 0; i < bs; i++) {
  690. sum += above[i];
  691. sum += left[i];
  692. }
  693. expected_dc = (sum + (count >> 1)) / count;
  694. for (r = 0; r < bs; r++) {
  695. vpx_memset16(dst, expected_dc, bs);
  696. dst += stride;
  697. }
  698. }
  699. #endif // CONFIG_VP9_HIGHBITDEPTH
  700. // This serves as a wrapper function, so that all the prediction functions
  701. // can be unified and accessed as a pointer array. Note that the boundary
  702. // above and left are not necessarily used all the time.
  703. #define intra_pred_sized(type, size) \
  704. void vpx_##type##_predictor_##size##x##size##_c(uint8_t *dst, \
  705. ptrdiff_t stride, \
  706. const uint8_t *above, \
  707. const uint8_t *left) { \
  708. type##_predictor(dst, stride, size, above, left); \
  709. }
  710. #if CONFIG_VP9_HIGHBITDEPTH
  711. #define intra_pred_highbd_sized(type, size) \
  712. void vpx_highbd_##type##_predictor_##size##x##size##_c( \
  713. uint16_t *dst, ptrdiff_t stride, const uint16_t *above, \
  714. const uint16_t *left, int bd) { \
  715. highbd_##type##_predictor(dst, stride, size, above, left, bd); \
  716. }
  717. #define intra_pred_allsizes(type) \
  718. intra_pred_sized(type, 4) \
  719. intra_pred_sized(type, 8) \
  720. intra_pred_sized(type, 16) \
  721. intra_pred_sized(type, 32) \
  722. intra_pred_highbd_sized(type, 4) \
  723. intra_pred_highbd_sized(type, 8) \
  724. intra_pred_highbd_sized(type, 16) \
  725. intra_pred_highbd_sized(type, 32)
  726. #define intra_pred_no_4x4(type) \
  727. intra_pred_sized(type, 8) \
  728. intra_pred_sized(type, 16) \
  729. intra_pred_sized(type, 32) \
  730. intra_pred_highbd_sized(type, 4) \
  731. intra_pred_highbd_sized(type, 8) \
  732. intra_pred_highbd_sized(type, 16) \
  733. intra_pred_highbd_sized(type, 32)
  734. #else
  735. #define intra_pred_allsizes(type) \
  736. intra_pred_sized(type, 4) \
  737. intra_pred_sized(type, 8) \
  738. intra_pred_sized(type, 16) \
  739. intra_pred_sized(type, 32)
  740. #define intra_pred_no_4x4(type) \
  741. intra_pred_sized(type, 8) \
  742. intra_pred_sized(type, 16) \
  743. intra_pred_sized(type, 32)
  744. #endif // CONFIG_VP9_HIGHBITDEPTH
  745. intra_pred_no_4x4(d207)
  746. intra_pred_no_4x4(d63)
  747. intra_pred_no_4x4(d45)
  748. #if CONFIG_MISC_FIXES
  749. intra_pred_allsizes(d207e)
  750. intra_pred_allsizes(d63e)
  751. intra_pred_no_4x4(d45e)
  752. #endif
  753. intra_pred_no_4x4(d117)
  754. intra_pred_no_4x4(d135)
  755. intra_pred_no_4x4(d153)
  756. intra_pred_allsizes(v)
  757. intra_pred_allsizes(h)
  758. intra_pred_allsizes(tm)
  759. intra_pred_allsizes(dc_128)
  760. intra_pred_allsizes(dc_left)
  761. intra_pred_allsizes(dc_top)
  762. intra_pred_allsizes(dc)
  763. #undef intra_pred_allsizes