intrapred.c 28 KB

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