You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1282 lines
41KB

  1. /*
  2. * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
  3. * Copyright (c) 2003-2011 Michael Niedermayer <michaelni@gmx.at>
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * Libav is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * H.264 / AVC / MPEG-4 part10 prediction functions.
  24. * @author Michael Niedermayer <michaelni@gmx.at>
  25. */
  26. #include "libavutil/intreadwrite.h"
  27. #include "mathops.h"
  28. #include "bit_depth_template.c"
  29. static void FUNCC(pred4x4_vertical)(uint8_t *_src, const uint8_t *topright,
  30. ptrdiff_t _stride)
  31. {
  32. pixel *src = (pixel*)_src;
  33. int stride = _stride/sizeof(pixel);
  34. const pixel4 a= AV_RN4PA(src-stride);
  35. AV_WN4PA(src+0*stride, a);
  36. AV_WN4PA(src+1*stride, a);
  37. AV_WN4PA(src+2*stride, a);
  38. AV_WN4PA(src+3*stride, a);
  39. }
  40. static void FUNCC(pred4x4_horizontal)(uint8_t *_src, const uint8_t *topright,
  41. ptrdiff_t _stride)
  42. {
  43. pixel *src = (pixel*)_src;
  44. int stride = _stride/sizeof(pixel);
  45. AV_WN4PA(src+0*stride, PIXEL_SPLAT_X4(src[-1+0*stride]));
  46. AV_WN4PA(src+1*stride, PIXEL_SPLAT_X4(src[-1+1*stride]));
  47. AV_WN4PA(src+2*stride, PIXEL_SPLAT_X4(src[-1+2*stride]));
  48. AV_WN4PA(src+3*stride, PIXEL_SPLAT_X4(src[-1+3*stride]));
  49. }
  50. static void FUNCC(pred4x4_dc)(uint8_t *_src, const uint8_t *topright,
  51. ptrdiff_t _stride)
  52. {
  53. pixel *src = (pixel*)_src;
  54. int stride = _stride/sizeof(pixel);
  55. const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride]
  56. + src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 4) >>3;
  57. const pixel4 a = PIXEL_SPLAT_X4(dc);
  58. AV_WN4PA(src+0*stride, a);
  59. AV_WN4PA(src+1*stride, a);
  60. AV_WN4PA(src+2*stride, a);
  61. AV_WN4PA(src+3*stride, a);
  62. }
  63. static void FUNCC(pred4x4_left_dc)(uint8_t *_src, const uint8_t *topright,
  64. ptrdiff_t _stride)
  65. {
  66. pixel *src = (pixel*)_src;
  67. int stride = _stride/sizeof(pixel);
  68. const int dc= ( src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 2) >>2;
  69. const pixel4 a = PIXEL_SPLAT_X4(dc);
  70. AV_WN4PA(src+0*stride, a);
  71. AV_WN4PA(src+1*stride, a);
  72. AV_WN4PA(src+2*stride, a);
  73. AV_WN4PA(src+3*stride, a);
  74. }
  75. static void FUNCC(pred4x4_top_dc)(uint8_t *_src, const uint8_t *topright,
  76. ptrdiff_t _stride)
  77. {
  78. pixel *src = (pixel*)_src;
  79. int stride = _stride/sizeof(pixel);
  80. const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] + 2) >>2;
  81. const pixel4 a = PIXEL_SPLAT_X4(dc);
  82. AV_WN4PA(src+0*stride, a);
  83. AV_WN4PA(src+1*stride, a);
  84. AV_WN4PA(src+2*stride, a);
  85. AV_WN4PA(src+3*stride, a);
  86. }
  87. static void FUNCC(pred4x4_128_dc)(uint8_t *_src, const uint8_t *topright,
  88. ptrdiff_t _stride)
  89. {
  90. pixel *src = (pixel*)_src;
  91. int stride = _stride/sizeof(pixel);
  92. const pixel4 a = PIXEL_SPLAT_X4(1<<(BIT_DEPTH-1));
  93. AV_WN4PA(src+0*stride, a);
  94. AV_WN4PA(src+1*stride, a);
  95. AV_WN4PA(src+2*stride, a);
  96. AV_WN4PA(src+3*stride, a);
  97. }
  98. static void FUNCC(pred4x4_127_dc)(uint8_t *_src, const uint8_t *topright,
  99. ptrdiff_t _stride)
  100. {
  101. pixel *src = (pixel*)_src;
  102. int stride = _stride/sizeof(pixel);
  103. const pixel4 a = PIXEL_SPLAT_X4((1<<(BIT_DEPTH-1))-1);
  104. AV_WN4PA(src+0*stride, a);
  105. AV_WN4PA(src+1*stride, a);
  106. AV_WN4PA(src+2*stride, a);
  107. AV_WN4PA(src+3*stride, a);
  108. }
  109. static void FUNCC(pred4x4_129_dc)(uint8_t *_src, const uint8_t *topright,
  110. ptrdiff_t _stride)
  111. {
  112. pixel *src = (pixel*)_src;
  113. int stride = _stride/sizeof(pixel);
  114. const pixel4 a = PIXEL_SPLAT_X4((1<<(BIT_DEPTH-1))+1);
  115. AV_WN4PA(src+0*stride, a);
  116. AV_WN4PA(src+1*stride, a);
  117. AV_WN4PA(src+2*stride, a);
  118. AV_WN4PA(src+3*stride, a);
  119. }
  120. #define LOAD_TOP_RIGHT_EDGE\
  121. const unsigned av_unused t4 = topright[0];\
  122. const unsigned av_unused t5 = topright[1];\
  123. const unsigned av_unused t6 = topright[2];\
  124. const unsigned av_unused t7 = topright[3];\
  125. #define LOAD_DOWN_LEFT_EDGE\
  126. const unsigned av_unused l4 = src[-1+4*stride];\
  127. const unsigned av_unused l5 = src[-1+5*stride];\
  128. const unsigned av_unused l6 = src[-1+6*stride];\
  129. const unsigned av_unused l7 = src[-1+7*stride];\
  130. #define LOAD_LEFT_EDGE\
  131. const unsigned av_unused l0 = src[-1+0*stride];\
  132. const unsigned av_unused l1 = src[-1+1*stride];\
  133. const unsigned av_unused l2 = src[-1+2*stride];\
  134. const unsigned av_unused l3 = src[-1+3*stride];\
  135. #define LOAD_TOP_EDGE\
  136. const unsigned av_unused t0 = src[ 0-1*stride];\
  137. const unsigned av_unused t1 = src[ 1-1*stride];\
  138. const unsigned av_unused t2 = src[ 2-1*stride];\
  139. const unsigned av_unused t3 = src[ 3-1*stride];\
  140. static void FUNCC(pred4x4_down_right)(uint8_t *_src, const uint8_t *topright,
  141. ptrdiff_t _stride)
  142. {
  143. pixel *src = (pixel*)_src;
  144. int stride = _stride/sizeof(pixel);
  145. const int lt= src[-1-1*stride];
  146. LOAD_TOP_EDGE
  147. LOAD_LEFT_EDGE
  148. src[0+3*stride]=(l3 + 2*l2 + l1 + 2)>>2;
  149. src[0+2*stride]=
  150. src[1+3*stride]=(l2 + 2*l1 + l0 + 2)>>2;
  151. src[0+1*stride]=
  152. src[1+2*stride]=
  153. src[2+3*stride]=(l1 + 2*l0 + lt + 2)>>2;
  154. src[0+0*stride]=
  155. src[1+1*stride]=
  156. src[2+2*stride]=
  157. src[3+3*stride]=(l0 + 2*lt + t0 + 2)>>2;
  158. src[1+0*stride]=
  159. src[2+1*stride]=
  160. src[3+2*stride]=(lt + 2*t0 + t1 + 2)>>2;
  161. src[2+0*stride]=
  162. src[3+1*stride]=(t0 + 2*t1 + t2 + 2)>>2;
  163. src[3+0*stride]=(t1 + 2*t2 + t3 + 2)>>2;
  164. }
  165. static void FUNCC(pred4x4_down_left)(uint8_t *_src, const uint8_t *_topright,
  166. ptrdiff_t _stride)
  167. {
  168. pixel *src = (pixel*)_src;
  169. const pixel *topright = (const pixel*)_topright;
  170. int stride = _stride/sizeof(pixel);
  171. LOAD_TOP_EDGE
  172. LOAD_TOP_RIGHT_EDGE
  173. // LOAD_LEFT_EDGE
  174. src[0+0*stride]=(t0 + t2 + 2*t1 + 2)>>2;
  175. src[1+0*stride]=
  176. src[0+1*stride]=(t1 + t3 + 2*t2 + 2)>>2;
  177. src[2+0*stride]=
  178. src[1+1*stride]=
  179. src[0+2*stride]=(t2 + t4 + 2*t3 + 2)>>2;
  180. src[3+0*stride]=
  181. src[2+1*stride]=
  182. src[1+2*stride]=
  183. src[0+3*stride]=(t3 + t5 + 2*t4 + 2)>>2;
  184. src[3+1*stride]=
  185. src[2+2*stride]=
  186. src[1+3*stride]=(t4 + t6 + 2*t5 + 2)>>2;
  187. src[3+2*stride]=
  188. src[2+3*stride]=(t5 + t7 + 2*t6 + 2)>>2;
  189. src[3+3*stride]=(t6 + 3*t7 + 2)>>2;
  190. }
  191. static void FUNCC(pred4x4_vertical_right)(uint8_t *_src,
  192. const uint8_t *topright,
  193. ptrdiff_t _stride)
  194. {
  195. pixel *src = (pixel*)_src;
  196. int stride = _stride/sizeof(pixel);
  197. const int lt= src[-1-1*stride];
  198. LOAD_TOP_EDGE
  199. LOAD_LEFT_EDGE
  200. src[0+0*stride]=
  201. src[1+2*stride]=(lt + t0 + 1)>>1;
  202. src[1+0*stride]=
  203. src[2+2*stride]=(t0 + t1 + 1)>>1;
  204. src[2+0*stride]=
  205. src[3+2*stride]=(t1 + t2 + 1)>>1;
  206. src[3+0*stride]=(t2 + t3 + 1)>>1;
  207. src[0+1*stride]=
  208. src[1+3*stride]=(l0 + 2*lt + t0 + 2)>>2;
  209. src[1+1*stride]=
  210. src[2+3*stride]=(lt + 2*t0 + t1 + 2)>>2;
  211. src[2+1*stride]=
  212. src[3+3*stride]=(t0 + 2*t1 + t2 + 2)>>2;
  213. src[3+1*stride]=(t1 + 2*t2 + t3 + 2)>>2;
  214. src[0+2*stride]=(lt + 2*l0 + l1 + 2)>>2;
  215. src[0+3*stride]=(l0 + 2*l1 + l2 + 2)>>2;
  216. }
  217. static void FUNCC(pred4x4_vertical_left)(uint8_t *_src,
  218. const uint8_t *_topright,
  219. ptrdiff_t _stride)
  220. {
  221. pixel *src = (pixel*)_src;
  222. const pixel *topright = (const pixel*)_topright;
  223. int stride = _stride/sizeof(pixel);
  224. LOAD_TOP_EDGE
  225. LOAD_TOP_RIGHT_EDGE
  226. src[0+0*stride]=(t0 + t1 + 1)>>1;
  227. src[1+0*stride]=
  228. src[0+2*stride]=(t1 + t2 + 1)>>1;
  229. src[2+0*stride]=
  230. src[1+2*stride]=(t2 + t3 + 1)>>1;
  231. src[3+0*stride]=
  232. src[2+2*stride]=(t3 + t4+ 1)>>1;
  233. src[3+2*stride]=(t4 + t5+ 1)>>1;
  234. src[0+1*stride]=(t0 + 2*t1 + t2 + 2)>>2;
  235. src[1+1*stride]=
  236. src[0+3*stride]=(t1 + 2*t2 + t3 + 2)>>2;
  237. src[2+1*stride]=
  238. src[1+3*stride]=(t2 + 2*t3 + t4 + 2)>>2;
  239. src[3+1*stride]=
  240. src[2+3*stride]=(t3 + 2*t4 + t5 + 2)>>2;
  241. src[3+3*stride]=(t4 + 2*t5 + t6 + 2)>>2;
  242. }
  243. static void FUNCC(pred4x4_horizontal_up)(uint8_t *_src, const uint8_t *topright,
  244. ptrdiff_t _stride)
  245. {
  246. pixel *src = (pixel*)_src;
  247. int stride = _stride/sizeof(pixel);
  248. LOAD_LEFT_EDGE
  249. src[0+0*stride]=(l0 + l1 + 1)>>1;
  250. src[1+0*stride]=(l0 + 2*l1 + l2 + 2)>>2;
  251. src[2+0*stride]=
  252. src[0+1*stride]=(l1 + l2 + 1)>>1;
  253. src[3+0*stride]=
  254. src[1+1*stride]=(l1 + 2*l2 + l3 + 2)>>2;
  255. src[2+1*stride]=
  256. src[0+2*stride]=(l2 + l3 + 1)>>1;
  257. src[3+1*stride]=
  258. src[1+2*stride]=(l2 + 2*l3 + l3 + 2)>>2;
  259. src[3+2*stride]=
  260. src[1+3*stride]=
  261. src[0+3*stride]=
  262. src[2+2*stride]=
  263. src[2+3*stride]=
  264. src[3+3*stride]=l3;
  265. }
  266. static void FUNCC(pred4x4_horizontal_down)(uint8_t *_src,
  267. const uint8_t *topright,
  268. ptrdiff_t _stride)
  269. {
  270. pixel *src = (pixel*)_src;
  271. int stride = _stride/sizeof(pixel);
  272. const int lt= src[-1-1*stride];
  273. LOAD_TOP_EDGE
  274. LOAD_LEFT_EDGE
  275. src[0+0*stride]=
  276. src[2+1*stride]=(lt + l0 + 1)>>1;
  277. src[1+0*stride]=
  278. src[3+1*stride]=(l0 + 2*lt + t0 + 2)>>2;
  279. src[2+0*stride]=(lt + 2*t0 + t1 + 2)>>2;
  280. src[3+0*stride]=(t0 + 2*t1 + t2 + 2)>>2;
  281. src[0+1*stride]=
  282. src[2+2*stride]=(l0 + l1 + 1)>>1;
  283. src[1+1*stride]=
  284. src[3+2*stride]=(lt + 2*l0 + l1 + 2)>>2;
  285. src[0+2*stride]=
  286. src[2+3*stride]=(l1 + l2+ 1)>>1;
  287. src[1+2*stride]=
  288. src[3+3*stride]=(l0 + 2*l1 + l2 + 2)>>2;
  289. src[0+3*stride]=(l2 + l3 + 1)>>1;
  290. src[1+3*stride]=(l1 + 2*l2 + l3 + 2)>>2;
  291. }
  292. static void FUNCC(pred16x16_vertical)(uint8_t *_src, ptrdiff_t _stride)
  293. {
  294. int i;
  295. pixel *src = (pixel*)_src;
  296. int stride = _stride/sizeof(pixel);
  297. const pixel4 a = AV_RN4PA(((pixel4*)(src-stride))+0);
  298. const pixel4 b = AV_RN4PA(((pixel4*)(src-stride))+1);
  299. const pixel4 c = AV_RN4PA(((pixel4*)(src-stride))+2);
  300. const pixel4 d = AV_RN4PA(((pixel4*)(src-stride))+3);
  301. for(i=0; i<16; i++){
  302. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
  303. AV_WN4PA(((pixel4*)(src+i*stride))+1, b);
  304. AV_WN4PA(((pixel4*)(src+i*stride))+2, c);
  305. AV_WN4PA(((pixel4*)(src+i*stride))+3, d);
  306. }
  307. }
  308. static void FUNCC(pred16x16_horizontal)(uint8_t *_src, ptrdiff_t stride)
  309. {
  310. int i;
  311. pixel *src = (pixel*)_src;
  312. stride /= sizeof(pixel);
  313. for(i=0; i<16; i++){
  314. const pixel4 a = PIXEL_SPLAT_X4(src[-1+i*stride]);
  315. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
  316. AV_WN4PA(((pixel4*)(src+i*stride))+1, a);
  317. AV_WN4PA(((pixel4*)(src+i*stride))+2, a);
  318. AV_WN4PA(((pixel4*)(src+i*stride))+3, a);
  319. }
  320. }
  321. #define PREDICT_16x16_DC(v)\
  322. for(i=0; i<16; i++){\
  323. AV_WN4PA(src+ 0, v);\
  324. AV_WN4PA(src+ 4, v);\
  325. AV_WN4PA(src+ 8, v);\
  326. AV_WN4PA(src+12, v);\
  327. src += stride;\
  328. }
  329. static void FUNCC(pred16x16_dc)(uint8_t *_src, ptrdiff_t stride)
  330. {
  331. int i, dc=0;
  332. pixel *src = (pixel*)_src;
  333. pixel4 dcsplat;
  334. stride /= sizeof(pixel);
  335. for(i=0;i<16; i++){
  336. dc+= src[-1+i*stride];
  337. }
  338. for(i=0;i<16; i++){
  339. dc+= src[i-stride];
  340. }
  341. dcsplat = PIXEL_SPLAT_X4((dc+16)>>5);
  342. PREDICT_16x16_DC(dcsplat);
  343. }
  344. static void FUNCC(pred16x16_left_dc)(uint8_t *_src, ptrdiff_t stride)
  345. {
  346. int i, dc=0;
  347. pixel *src = (pixel*)_src;
  348. pixel4 dcsplat;
  349. stride /= sizeof(pixel);
  350. for(i=0;i<16; i++){
  351. dc+= src[-1+i*stride];
  352. }
  353. dcsplat = PIXEL_SPLAT_X4((dc+8)>>4);
  354. PREDICT_16x16_DC(dcsplat);
  355. }
  356. static void FUNCC(pred16x16_top_dc)(uint8_t *_src, ptrdiff_t stride)
  357. {
  358. int i, dc=0;
  359. pixel *src = (pixel*)_src;
  360. pixel4 dcsplat;
  361. stride /= sizeof(pixel);
  362. for(i=0;i<16; i++){
  363. dc+= src[i-stride];
  364. }
  365. dcsplat = PIXEL_SPLAT_X4((dc+8)>>4);
  366. PREDICT_16x16_DC(dcsplat);
  367. }
  368. #define PRED16x16_X(n, v) \
  369. static void FUNCC(pred16x16_##n##_dc)(uint8_t *_src, ptrdiff_t stride)\
  370. {\
  371. int i;\
  372. pixel *src = (pixel*)_src;\
  373. stride /= sizeof(pixel);\
  374. PREDICT_16x16_DC(PIXEL_SPLAT_X4(v));\
  375. }
  376. PRED16x16_X(127, (1<<(BIT_DEPTH-1))-1)
  377. PRED16x16_X(128, (1<<(BIT_DEPTH-1))+0)
  378. PRED16x16_X(129, (1<<(BIT_DEPTH-1))+1)
  379. static inline void FUNCC(pred16x16_plane_compat)(uint8_t *_src,
  380. ptrdiff_t _stride,
  381. const int svq3,
  382. const int rv40)
  383. {
  384. int i, j, k;
  385. int a;
  386. INIT_CLIP
  387. pixel *src = (pixel*)_src;
  388. int stride = _stride/sizeof(pixel);
  389. const pixel * const src0 = src +7-stride;
  390. const pixel * src1 = src +8*stride-1;
  391. const pixel * src2 = src1-2*stride; // == src+6*stride-1;
  392. int H = src0[1] - src0[-1];
  393. int V = src1[0] - src2[ 0];
  394. for(k=2; k<=8; ++k) {
  395. src1 += stride; src2 -= stride;
  396. H += k*(src0[k] - src0[-k]);
  397. V += k*(src1[0] - src2[ 0]);
  398. }
  399. if(svq3){
  400. H = ( 5*(H/4) ) / 16;
  401. V = ( 5*(V/4) ) / 16;
  402. /* required for 100% accuracy */
  403. i = H; H = V; V = i;
  404. }else if(rv40){
  405. H = ( H + (H>>2) ) >> 4;
  406. V = ( V + (V>>2) ) >> 4;
  407. }else{
  408. H = ( 5*H+32 ) >> 6;
  409. V = ( 5*V+32 ) >> 6;
  410. }
  411. a = 16*(src1[0] + src2[16] + 1) - 7*(V+H);
  412. for(j=16; j>0; --j) {
  413. int b = a;
  414. a += V;
  415. for(i=-16; i<0; i+=4) {
  416. src[16+i] = CLIP((b ) >> 5);
  417. src[17+i] = CLIP((b+ H) >> 5);
  418. src[18+i] = CLIP((b+2*H) >> 5);
  419. src[19+i] = CLIP((b+3*H) >> 5);
  420. b += 4*H;
  421. }
  422. src += stride;
  423. }
  424. }
  425. static void FUNCC(pred16x16_plane)(uint8_t *src, ptrdiff_t stride)
  426. {
  427. FUNCC(pred16x16_plane_compat)(src, stride, 0, 0);
  428. }
  429. static void FUNCC(pred8x8_vertical)(uint8_t *_src, ptrdiff_t _stride)
  430. {
  431. int i;
  432. pixel *src = (pixel*)_src;
  433. int stride = _stride/sizeof(pixel);
  434. const pixel4 a= AV_RN4PA(((pixel4*)(src-stride))+0);
  435. const pixel4 b= AV_RN4PA(((pixel4*)(src-stride))+1);
  436. for(i=0; i<8; i++){
  437. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
  438. AV_WN4PA(((pixel4*)(src+i*stride))+1, b);
  439. }
  440. }
  441. static void FUNCC(pred8x16_vertical)(uint8_t *_src, ptrdiff_t _stride)
  442. {
  443. int i;
  444. pixel *src = (pixel*)_src;
  445. int stride = _stride>>(sizeof(pixel)-1);
  446. const pixel4 a= AV_RN4PA(((pixel4*)(src-stride))+0);
  447. const pixel4 b= AV_RN4PA(((pixel4*)(src-stride))+1);
  448. for(i=0; i<16; i++){
  449. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
  450. AV_WN4PA(((pixel4*)(src+i*stride))+1, b);
  451. }
  452. }
  453. static void FUNCC(pred8x8_horizontal)(uint8_t *_src, ptrdiff_t stride)
  454. {
  455. int i;
  456. pixel *src = (pixel*)_src;
  457. stride /= sizeof(pixel);
  458. for(i=0; i<8; i++){
  459. const pixel4 a = PIXEL_SPLAT_X4(src[-1+i*stride]);
  460. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
  461. AV_WN4PA(((pixel4*)(src+i*stride))+1, a);
  462. }
  463. }
  464. static void FUNCC(pred8x16_horizontal)(uint8_t *_src, ptrdiff_t stride)
  465. {
  466. int i;
  467. pixel *src = (pixel*)_src;
  468. stride >>= sizeof(pixel)-1;
  469. for(i=0; i<16; i++){
  470. const pixel4 a = PIXEL_SPLAT_X4(src[-1+i*stride]);
  471. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
  472. AV_WN4PA(((pixel4*)(src+i*stride))+1, a);
  473. }
  474. }
  475. #define PRED8x8_X(n, v)\
  476. static void FUNCC(pred8x8_##n##_dc)(uint8_t *_src, ptrdiff_t stride)\
  477. {\
  478. int i;\
  479. const pixel4 a = PIXEL_SPLAT_X4(v);\
  480. pixel *src = (pixel*)_src;\
  481. stride /= sizeof(pixel);\
  482. for(i=0; i<8; i++){\
  483. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);\
  484. AV_WN4PA(((pixel4*)(src+i*stride))+1, a);\
  485. }\
  486. }
  487. PRED8x8_X(127, (1<<(BIT_DEPTH-1))-1)
  488. PRED8x8_X(128, (1<<(BIT_DEPTH-1))+0)
  489. PRED8x8_X(129, (1<<(BIT_DEPTH-1))+1)
  490. static void FUNCC(pred8x16_128_dc)(uint8_t *_src, ptrdiff_t stride)
  491. {
  492. FUNCC(pred8x8_128_dc)(_src, stride);
  493. FUNCC(pred8x8_128_dc)(_src+8*stride, stride);
  494. }
  495. static void FUNCC(pred8x8_left_dc)(uint8_t *_src, ptrdiff_t stride)
  496. {
  497. int i;
  498. int dc0, dc2;
  499. pixel4 dc0splat, dc2splat;
  500. pixel *src = (pixel*)_src;
  501. stride /= sizeof(pixel);
  502. dc0=dc2=0;
  503. for(i=0;i<4; i++){
  504. dc0+= src[-1+i*stride];
  505. dc2+= src[-1+(i+4)*stride];
  506. }
  507. dc0splat = PIXEL_SPLAT_X4((dc0 + 2)>>2);
  508. dc2splat = PIXEL_SPLAT_X4((dc2 + 2)>>2);
  509. for(i=0; i<4; i++){
  510. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
  511. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc0splat);
  512. }
  513. for(i=4; i<8; i++){
  514. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc2splat);
  515. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc2splat);
  516. }
  517. }
  518. static void FUNCC(pred8x16_left_dc)(uint8_t *_src, ptrdiff_t stride)
  519. {
  520. FUNCC(pred8x8_left_dc)(_src, stride);
  521. FUNCC(pred8x8_left_dc)(_src+8*stride, stride);
  522. }
  523. static void FUNCC(pred8x8_top_dc)(uint8_t *_src, ptrdiff_t stride)
  524. {
  525. int i;
  526. int dc0, dc1;
  527. pixel4 dc0splat, dc1splat;
  528. pixel *src = (pixel*)_src;
  529. stride /= sizeof(pixel);
  530. dc0=dc1=0;
  531. for(i=0;i<4; i++){
  532. dc0+= src[i-stride];
  533. dc1+= src[4+i-stride];
  534. }
  535. dc0splat = PIXEL_SPLAT_X4((dc0 + 2)>>2);
  536. dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2);
  537. for(i=0; i<4; i++){
  538. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
  539. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
  540. }
  541. for(i=4; i<8; i++){
  542. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
  543. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
  544. }
  545. }
  546. static void FUNCC(pred8x16_top_dc)(uint8_t *_src, ptrdiff_t stride)
  547. {
  548. int i;
  549. int dc0, dc1;
  550. pixel4 dc0splat, dc1splat;
  551. pixel *src = (pixel*)_src;
  552. stride >>= sizeof(pixel)-1;
  553. dc0=dc1=0;
  554. for(i=0;i<4; i++){
  555. dc0+= src[i-stride];
  556. dc1+= src[4+i-stride];
  557. }
  558. dc0splat = PIXEL_SPLAT_X4((dc0 + 2)>>2);
  559. dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2);
  560. for(i=0; i<16; i++){
  561. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
  562. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
  563. }
  564. }
  565. static void FUNCC(pred8x8_dc)(uint8_t *_src, ptrdiff_t stride)
  566. {
  567. int i;
  568. int dc0, dc1, dc2;
  569. pixel4 dc0splat, dc1splat, dc2splat, dc3splat;
  570. pixel *src = (pixel*)_src;
  571. stride /= sizeof(pixel);
  572. dc0=dc1=dc2=0;
  573. for(i=0;i<4; i++){
  574. dc0+= src[-1+i*stride] + src[i-stride];
  575. dc1+= src[4+i-stride];
  576. dc2+= src[-1+(i+4)*stride];
  577. }
  578. dc0splat = PIXEL_SPLAT_X4((dc0 + 4)>>3);
  579. dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2);
  580. dc2splat = PIXEL_SPLAT_X4((dc2 + 2)>>2);
  581. dc3splat = PIXEL_SPLAT_X4((dc1 + dc2 + 4)>>3);
  582. for(i=0; i<4; i++){
  583. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
  584. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
  585. }
  586. for(i=4; i<8; i++){
  587. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc2splat);
  588. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc3splat);
  589. }
  590. }
  591. static void FUNCC(pred8x16_dc)(uint8_t *_src, ptrdiff_t stride)
  592. {
  593. int i;
  594. int dc0, dc1, dc2, dc3, dc4;
  595. pixel4 dc0splat, dc1splat, dc2splat, dc3splat, dc4splat, dc5splat, dc6splat, dc7splat;
  596. pixel *src = (pixel*)_src;
  597. stride >>= sizeof(pixel)-1;
  598. dc0=dc1=dc2=dc3=dc4=0;
  599. for(i=0;i<4; i++){
  600. dc0+= src[-1+i*stride] + src[i-stride];
  601. dc1+= src[4+i-stride];
  602. dc2+= src[-1+(i+4)*stride];
  603. dc3+= src[-1+(i+8)*stride];
  604. dc4+= src[-1+(i+12)*stride];
  605. }
  606. dc0splat = PIXEL_SPLAT_X4((dc0 + 4)>>3);
  607. dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2);
  608. dc2splat = PIXEL_SPLAT_X4((dc2 + 2)>>2);
  609. dc3splat = PIXEL_SPLAT_X4((dc1 + dc2 + 4)>>3);
  610. dc4splat = PIXEL_SPLAT_X4((dc3 + 2)>>2);
  611. dc5splat = PIXEL_SPLAT_X4((dc1 + dc3 + 4)>>3);
  612. dc6splat = PIXEL_SPLAT_X4((dc4 + 2)>>2);
  613. dc7splat = PIXEL_SPLAT_X4((dc1 + dc4 + 4)>>3);
  614. for(i=0; i<4; i++){
  615. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
  616. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
  617. }
  618. for(i=4; i<8; i++){
  619. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc2splat);
  620. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc3splat);
  621. }
  622. for(i=8; i<12; i++){
  623. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc4splat);
  624. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc5splat);
  625. }
  626. for(i=12; i<16; i++){
  627. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc6splat);
  628. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc7splat);
  629. }
  630. }
  631. static void FUNC(pred8x8_mad_cow_dc_l0t)(uint8_t *src, ptrdiff_t stride)
  632. {
  633. FUNCC(pred8x8_top_dc)(src, stride);
  634. FUNCC(pred4x4_dc)(src, NULL, stride);
  635. }
  636. static void FUNC(pred8x16_mad_cow_dc_l0t)(uint8_t *src, ptrdiff_t stride)
  637. {
  638. FUNCC(pred8x16_top_dc)(src, stride);
  639. FUNCC(pred4x4_dc)(src, NULL, stride);
  640. }
  641. static void FUNC(pred8x8_mad_cow_dc_0lt)(uint8_t *src, ptrdiff_t stride)
  642. {
  643. FUNCC(pred8x8_dc)(src, stride);
  644. FUNCC(pred4x4_top_dc)(src, NULL, stride);
  645. }
  646. static void FUNC(pred8x16_mad_cow_dc_0lt)(uint8_t *src, ptrdiff_t stride)
  647. {
  648. FUNCC(pred8x16_dc)(src, stride);
  649. FUNCC(pred4x4_top_dc)(src, NULL, stride);
  650. }
  651. static void FUNC(pred8x8_mad_cow_dc_l00)(uint8_t *src, ptrdiff_t stride)
  652. {
  653. FUNCC(pred8x8_left_dc)(src, stride);
  654. FUNCC(pred4x4_128_dc)(src + 4*stride , NULL, stride);
  655. FUNCC(pred4x4_128_dc)(src + 4*stride + 4*sizeof(pixel), NULL, stride);
  656. }
  657. static void FUNC(pred8x16_mad_cow_dc_l00)(uint8_t *src, ptrdiff_t stride)
  658. {
  659. FUNCC(pred8x16_left_dc)(src, stride);
  660. FUNCC(pred4x4_128_dc)(src + 4*stride , NULL, stride);
  661. FUNCC(pred4x4_128_dc)(src + 4*stride + 4*sizeof(pixel), NULL, stride);
  662. }
  663. static void FUNC(pred8x8_mad_cow_dc_0l0)(uint8_t *src, ptrdiff_t stride)
  664. {
  665. FUNCC(pred8x8_left_dc)(src, stride);
  666. FUNCC(pred4x4_128_dc)(src , NULL, stride);
  667. FUNCC(pred4x4_128_dc)(src + 4*sizeof(pixel), NULL, stride);
  668. }
  669. static void FUNC(pred8x16_mad_cow_dc_0l0)(uint8_t *src, ptrdiff_t stride)
  670. {
  671. FUNCC(pred8x16_left_dc)(src, stride);
  672. FUNCC(pred4x4_128_dc)(src , NULL, stride);
  673. FUNCC(pred4x4_128_dc)(src + 4*sizeof(pixel), NULL, stride);
  674. }
  675. static void FUNCC(pred8x8_plane)(uint8_t *_src, ptrdiff_t _stride)
  676. {
  677. int j, k;
  678. int a;
  679. INIT_CLIP
  680. pixel *src = (pixel*)_src;
  681. int stride = _stride/sizeof(pixel);
  682. const pixel * const src0 = src +3-stride;
  683. const pixel * src1 = src +4*stride-1;
  684. const pixel * src2 = src1-2*stride; // == src+2*stride-1;
  685. int H = src0[1] - src0[-1];
  686. int V = src1[0] - src2[ 0];
  687. for(k=2; k<=4; ++k) {
  688. src1 += stride; src2 -= stride;
  689. H += k*(src0[k] - src0[-k]);
  690. V += k*(src1[0] - src2[ 0]);
  691. }
  692. H = ( 17*H+16 ) >> 5;
  693. V = ( 17*V+16 ) >> 5;
  694. a = 16*(src1[0] + src2[8]+1) - 3*(V+H);
  695. for(j=8; j>0; --j) {
  696. int b = a;
  697. a += V;
  698. src[0] = CLIP((b ) >> 5);
  699. src[1] = CLIP((b+ H) >> 5);
  700. src[2] = CLIP((b+2*H) >> 5);
  701. src[3] = CLIP((b+3*H) >> 5);
  702. src[4] = CLIP((b+4*H) >> 5);
  703. src[5] = CLIP((b+5*H) >> 5);
  704. src[6] = CLIP((b+6*H) >> 5);
  705. src[7] = CLIP((b+7*H) >> 5);
  706. src += stride;
  707. }
  708. }
  709. static void FUNCC(pred8x16_plane)(uint8_t *_src, ptrdiff_t _stride)
  710. {
  711. int j, k;
  712. int a;
  713. INIT_CLIP
  714. pixel *src = (pixel*)_src;
  715. int stride = _stride>>(sizeof(pixel)-1);
  716. const pixel * const src0 = src +3-stride;
  717. const pixel * src1 = src +8*stride-1;
  718. const pixel * src2 = src1-2*stride; // == src+6*stride-1;
  719. int H = src0[1] - src0[-1];
  720. int V = src1[0] - src2[ 0];
  721. for (k = 2; k <= 4; ++k) {
  722. src1 += stride; src2 -= stride;
  723. H += k*(src0[k] - src0[-k]);
  724. V += k*(src1[0] - src2[ 0]);
  725. }
  726. for (; k <= 8; ++k) {
  727. src1 += stride; src2 -= stride;
  728. V += k*(src1[0] - src2[0]);
  729. }
  730. H = (17*H+16) >> 5;
  731. V = (5*V+32) >> 6;
  732. a = 16*(src1[0] + src2[8] + 1) - 7*V - 3*H;
  733. for(j=16; j>0; --j) {
  734. int b = a;
  735. a += V;
  736. src[0] = CLIP((b ) >> 5);
  737. src[1] = CLIP((b+ H) >> 5);
  738. src[2] = CLIP((b+2*H) >> 5);
  739. src[3] = CLIP((b+3*H) >> 5);
  740. src[4] = CLIP((b+4*H) >> 5);
  741. src[5] = CLIP((b+5*H) >> 5);
  742. src[6] = CLIP((b+6*H) >> 5);
  743. src[7] = CLIP((b+7*H) >> 5);
  744. src += stride;
  745. }
  746. }
  747. #define SRC(x,y) src[(x)+(y)*stride]
  748. #define PL(y) \
  749. const int l##y = (SRC(-1,y-1) + 2*SRC(-1,y) + SRC(-1,y+1) + 2) >> 2;
  750. #define PREDICT_8x8_LOAD_LEFT \
  751. const int l0 = ((has_topleft ? SRC(-1,-1) : SRC(-1,0)) \
  752. + 2*SRC(-1,0) + SRC(-1,1) + 2) >> 2; \
  753. PL(1) PL(2) PL(3) PL(4) PL(5) PL(6) \
  754. const int l7 av_unused = (SRC(-1,6) + 3*SRC(-1,7) + 2) >> 2
  755. #define PT(x) \
  756. const int t##x = (SRC(x-1,-1) + 2*SRC(x,-1) + SRC(x+1,-1) + 2) >> 2;
  757. #define PREDICT_8x8_LOAD_TOP \
  758. const int t0 = ((has_topleft ? SRC(-1,-1) : SRC(0,-1)) \
  759. + 2*SRC(0,-1) + SRC(1,-1) + 2) >> 2; \
  760. PT(1) PT(2) PT(3) PT(4) PT(5) PT(6) \
  761. const int t7 av_unused = ((has_topright ? SRC(8,-1) : SRC(7,-1)) \
  762. + 2*SRC(7,-1) + SRC(6,-1) + 2) >> 2
  763. #define PTR(x) \
  764. t##x = (SRC(x-1,-1) + 2*SRC(x,-1) + SRC(x+1,-1) + 2) >> 2;
  765. #define PREDICT_8x8_LOAD_TOPRIGHT \
  766. int t8, t9, t10, t11, t12, t13, t14, t15; \
  767. if(has_topright) { \
  768. PTR(8) PTR(9) PTR(10) PTR(11) PTR(12) PTR(13) PTR(14) \
  769. t15 = (SRC(14,-1) + 3*SRC(15,-1) + 2) >> 2; \
  770. } else t8=t9=t10=t11=t12=t13=t14=t15= SRC(7,-1);
  771. #define PREDICT_8x8_LOAD_TOPLEFT \
  772. const int lt = (SRC(-1,0) + 2*SRC(-1,-1) + SRC(0,-1) + 2) >> 2
  773. #define PREDICT_8x8_DC(v) \
  774. int y; \
  775. for( y = 0; y < 8; y++ ) { \
  776. AV_WN4PA(((pixel4*)src)+0, v); \
  777. AV_WN4PA(((pixel4*)src)+1, v); \
  778. src += stride; \
  779. }
  780. static void FUNCC(pred8x8l_128_dc)(uint8_t *_src, int has_topleft,
  781. int has_topright, ptrdiff_t _stride)
  782. {
  783. pixel *src = (pixel*)_src;
  784. int stride = _stride/sizeof(pixel);
  785. PREDICT_8x8_DC(PIXEL_SPLAT_X4(1<<(BIT_DEPTH-1)));
  786. }
  787. static void FUNCC(pred8x8l_left_dc)(uint8_t *_src, int has_topleft,
  788. int has_topright, ptrdiff_t _stride)
  789. {
  790. pixel *src = (pixel*)_src;
  791. int stride = _stride/sizeof(pixel);
  792. PREDICT_8x8_LOAD_LEFT;
  793. const pixel4 dc = PIXEL_SPLAT_X4((l0+l1+l2+l3+l4+l5+l6+l7+4) >> 3);
  794. PREDICT_8x8_DC(dc);
  795. }
  796. static void FUNCC(pred8x8l_top_dc)(uint8_t *_src, int has_topleft,
  797. int has_topright, ptrdiff_t _stride)
  798. {
  799. pixel *src = (pixel*)_src;
  800. int stride = _stride/sizeof(pixel);
  801. PREDICT_8x8_LOAD_TOP;
  802. const pixel4 dc = PIXEL_SPLAT_X4((t0+t1+t2+t3+t4+t5+t6+t7+4) >> 3);
  803. PREDICT_8x8_DC(dc);
  804. }
  805. static void FUNCC(pred8x8l_dc)(uint8_t *_src, int has_topleft,
  806. int has_topright, ptrdiff_t _stride)
  807. {
  808. pixel *src = (pixel*)_src;
  809. int stride = _stride/sizeof(pixel);
  810. PREDICT_8x8_LOAD_LEFT;
  811. PREDICT_8x8_LOAD_TOP;
  812. const pixel4 dc = PIXEL_SPLAT_X4((l0+l1+l2+l3+l4+l5+l6+l7
  813. +t0+t1+t2+t3+t4+t5+t6+t7+8) >> 4);
  814. PREDICT_8x8_DC(dc);
  815. }
  816. static void FUNCC(pred8x8l_horizontal)(uint8_t *_src, int has_topleft,
  817. int has_topright, ptrdiff_t _stride)
  818. {
  819. pixel *src = (pixel*)_src;
  820. int stride = _stride/sizeof(pixel);
  821. pixel4 a;
  822. PREDICT_8x8_LOAD_LEFT;
  823. #define ROW(y) a = PIXEL_SPLAT_X4(l##y); \
  824. AV_WN4PA(src+y*stride, a); \
  825. AV_WN4PA(src+y*stride+4, a);
  826. ROW(0); ROW(1); ROW(2); ROW(3); ROW(4); ROW(5); ROW(6); ROW(7);
  827. #undef ROW
  828. }
  829. static void FUNCC(pred8x8l_vertical)(uint8_t *_src, int has_topleft,
  830. int has_topright, ptrdiff_t _stride)
  831. {
  832. int y;
  833. pixel *src = (pixel*)_src;
  834. int stride = _stride/sizeof(pixel);
  835. pixel4 a, b;
  836. PREDICT_8x8_LOAD_TOP;
  837. src[0] = t0;
  838. src[1] = t1;
  839. src[2] = t2;
  840. src[3] = t3;
  841. src[4] = t4;
  842. src[5] = t5;
  843. src[6] = t6;
  844. src[7] = t7;
  845. a = AV_RN4PA(((pixel4*)src)+0);
  846. b = AV_RN4PA(((pixel4*)src)+1);
  847. for( y = 1; y < 8; y++ ) {
  848. AV_WN4PA(((pixel4*)(src+y*stride))+0, a);
  849. AV_WN4PA(((pixel4*)(src+y*stride))+1, b);
  850. }
  851. }
  852. static void FUNCC(pred8x8l_down_left)(uint8_t *_src, int has_topleft,
  853. int has_topright, ptrdiff_t _stride)
  854. {
  855. pixel *src = (pixel*)_src;
  856. int stride = _stride/sizeof(pixel);
  857. PREDICT_8x8_LOAD_TOP;
  858. PREDICT_8x8_LOAD_TOPRIGHT;
  859. SRC(0,0)= (t0 + 2*t1 + t2 + 2) >> 2;
  860. SRC(0,1)=SRC(1,0)= (t1 + 2*t2 + t3 + 2) >> 2;
  861. SRC(0,2)=SRC(1,1)=SRC(2,0)= (t2 + 2*t3 + t4 + 2) >> 2;
  862. SRC(0,3)=SRC(1,2)=SRC(2,1)=SRC(3,0)= (t3 + 2*t4 + t5 + 2) >> 2;
  863. SRC(0,4)=SRC(1,3)=SRC(2,2)=SRC(3,1)=SRC(4,0)= (t4 + 2*t5 + t6 + 2) >> 2;
  864. SRC(0,5)=SRC(1,4)=SRC(2,3)=SRC(3,2)=SRC(4,1)=SRC(5,0)= (t5 + 2*t6 + t7 + 2) >> 2;
  865. SRC(0,6)=SRC(1,5)=SRC(2,4)=SRC(3,3)=SRC(4,2)=SRC(5,1)=SRC(6,0)= (t6 + 2*t7 + t8 + 2) >> 2;
  866. SRC(0,7)=SRC(1,6)=SRC(2,5)=SRC(3,4)=SRC(4,3)=SRC(5,2)=SRC(6,1)=SRC(7,0)= (t7 + 2*t8 + t9 + 2) >> 2;
  867. SRC(1,7)=SRC(2,6)=SRC(3,5)=SRC(4,4)=SRC(5,3)=SRC(6,2)=SRC(7,1)= (t8 + 2*t9 + t10 + 2) >> 2;
  868. SRC(2,7)=SRC(3,6)=SRC(4,5)=SRC(5,4)=SRC(6,3)=SRC(7,2)= (t9 + 2*t10 + t11 + 2) >> 2;
  869. SRC(3,7)=SRC(4,6)=SRC(5,5)=SRC(6,4)=SRC(7,3)= (t10 + 2*t11 + t12 + 2) >> 2;
  870. SRC(4,7)=SRC(5,6)=SRC(6,5)=SRC(7,4)= (t11 + 2*t12 + t13 + 2) >> 2;
  871. SRC(5,7)=SRC(6,6)=SRC(7,5)= (t12 + 2*t13 + t14 + 2) >> 2;
  872. SRC(6,7)=SRC(7,6)= (t13 + 2*t14 + t15 + 2) >> 2;
  873. SRC(7,7)= (t14 + 3*t15 + 2) >> 2;
  874. }
  875. static void FUNCC(pred8x8l_down_right)(uint8_t *_src, int has_topleft,
  876. int has_topright, ptrdiff_t _stride)
  877. {
  878. pixel *src = (pixel*)_src;
  879. int stride = _stride/sizeof(pixel);
  880. PREDICT_8x8_LOAD_TOP;
  881. PREDICT_8x8_LOAD_LEFT;
  882. PREDICT_8x8_LOAD_TOPLEFT;
  883. SRC(0,7)= (l7 + 2*l6 + l5 + 2) >> 2;
  884. SRC(0,6)=SRC(1,7)= (l6 + 2*l5 + l4 + 2) >> 2;
  885. SRC(0,5)=SRC(1,6)=SRC(2,7)= (l5 + 2*l4 + l3 + 2) >> 2;
  886. SRC(0,4)=SRC(1,5)=SRC(2,6)=SRC(3,7)= (l4 + 2*l3 + l2 + 2) >> 2;
  887. SRC(0,3)=SRC(1,4)=SRC(2,5)=SRC(3,6)=SRC(4,7)= (l3 + 2*l2 + l1 + 2) >> 2;
  888. SRC(0,2)=SRC(1,3)=SRC(2,4)=SRC(3,5)=SRC(4,6)=SRC(5,7)= (l2 + 2*l1 + l0 + 2) >> 2;
  889. SRC(0,1)=SRC(1,2)=SRC(2,3)=SRC(3,4)=SRC(4,5)=SRC(5,6)=SRC(6,7)= (l1 + 2*l0 + lt + 2) >> 2;
  890. SRC(0,0)=SRC(1,1)=SRC(2,2)=SRC(3,3)=SRC(4,4)=SRC(5,5)=SRC(6,6)=SRC(7,7)= (l0 + 2*lt + t0 + 2) >> 2;
  891. SRC(1,0)=SRC(2,1)=SRC(3,2)=SRC(4,3)=SRC(5,4)=SRC(6,5)=SRC(7,6)= (lt + 2*t0 + t1 + 2) >> 2;
  892. SRC(2,0)=SRC(3,1)=SRC(4,2)=SRC(5,3)=SRC(6,4)=SRC(7,5)= (t0 + 2*t1 + t2 + 2) >> 2;
  893. SRC(3,0)=SRC(4,1)=SRC(5,2)=SRC(6,3)=SRC(7,4)= (t1 + 2*t2 + t3 + 2) >> 2;
  894. SRC(4,0)=SRC(5,1)=SRC(6,2)=SRC(7,3)= (t2 + 2*t3 + t4 + 2) >> 2;
  895. SRC(5,0)=SRC(6,1)=SRC(7,2)= (t3 + 2*t4 + t5 + 2) >> 2;
  896. SRC(6,0)=SRC(7,1)= (t4 + 2*t5 + t6 + 2) >> 2;
  897. SRC(7,0)= (t5 + 2*t6 + t7 + 2) >> 2;
  898. }
  899. static void FUNCC(pred8x8l_vertical_right)(uint8_t *_src, int has_topleft,
  900. int has_topright, ptrdiff_t _stride)
  901. {
  902. pixel *src = (pixel*)_src;
  903. int stride = _stride/sizeof(pixel);
  904. PREDICT_8x8_LOAD_TOP;
  905. PREDICT_8x8_LOAD_LEFT;
  906. PREDICT_8x8_LOAD_TOPLEFT;
  907. SRC(0,6)= (l5 + 2*l4 + l3 + 2) >> 2;
  908. SRC(0,7)= (l6 + 2*l5 + l4 + 2) >> 2;
  909. SRC(0,4)=SRC(1,6)= (l3 + 2*l2 + l1 + 2) >> 2;
  910. SRC(0,5)=SRC(1,7)= (l4 + 2*l3 + l2 + 2) >> 2;
  911. SRC(0,2)=SRC(1,4)=SRC(2,6)= (l1 + 2*l0 + lt + 2) >> 2;
  912. SRC(0,3)=SRC(1,5)=SRC(2,7)= (l2 + 2*l1 + l0 + 2) >> 2;
  913. SRC(0,1)=SRC(1,3)=SRC(2,5)=SRC(3,7)= (l0 + 2*lt + t0 + 2) >> 2;
  914. SRC(0,0)=SRC(1,2)=SRC(2,4)=SRC(3,6)= (lt + t0 + 1) >> 1;
  915. SRC(1,1)=SRC(2,3)=SRC(3,5)=SRC(4,7)= (lt + 2*t0 + t1 + 2) >> 2;
  916. SRC(1,0)=SRC(2,2)=SRC(3,4)=SRC(4,6)= (t0 + t1 + 1) >> 1;
  917. SRC(2,1)=SRC(3,3)=SRC(4,5)=SRC(5,7)= (t0 + 2*t1 + t2 + 2) >> 2;
  918. SRC(2,0)=SRC(3,2)=SRC(4,4)=SRC(5,6)= (t1 + t2 + 1) >> 1;
  919. SRC(3,1)=SRC(4,3)=SRC(5,5)=SRC(6,7)= (t1 + 2*t2 + t3 + 2) >> 2;
  920. SRC(3,0)=SRC(4,2)=SRC(5,4)=SRC(6,6)= (t2 + t3 + 1) >> 1;
  921. SRC(4,1)=SRC(5,3)=SRC(6,5)=SRC(7,7)= (t2 + 2*t3 + t4 + 2) >> 2;
  922. SRC(4,0)=SRC(5,2)=SRC(6,4)=SRC(7,6)= (t3 + t4 + 1) >> 1;
  923. SRC(5,1)=SRC(6,3)=SRC(7,5)= (t3 + 2*t4 + t5 + 2) >> 2;
  924. SRC(5,0)=SRC(6,2)=SRC(7,4)= (t4 + t5 + 1) >> 1;
  925. SRC(6,1)=SRC(7,3)= (t4 + 2*t5 + t6 + 2) >> 2;
  926. SRC(6,0)=SRC(7,2)= (t5 + t6 + 1) >> 1;
  927. SRC(7,1)= (t5 + 2*t6 + t7 + 2) >> 2;
  928. SRC(7,0)= (t6 + t7 + 1) >> 1;
  929. }
  930. static void FUNCC(pred8x8l_horizontal_down)(uint8_t *_src, int has_topleft,
  931. int has_topright, ptrdiff_t _stride)
  932. {
  933. pixel *src = (pixel*)_src;
  934. int stride = _stride/sizeof(pixel);
  935. PREDICT_8x8_LOAD_TOP;
  936. PREDICT_8x8_LOAD_LEFT;
  937. PREDICT_8x8_LOAD_TOPLEFT;
  938. SRC(0,7)= (l6 + l7 + 1) >> 1;
  939. SRC(1,7)= (l5 + 2*l6 + l7 + 2) >> 2;
  940. SRC(0,6)=SRC(2,7)= (l5 + l6 + 1) >> 1;
  941. SRC(1,6)=SRC(3,7)= (l4 + 2*l5 + l6 + 2) >> 2;
  942. SRC(0,5)=SRC(2,6)=SRC(4,7)= (l4 + l5 + 1) >> 1;
  943. SRC(1,5)=SRC(3,6)=SRC(5,7)= (l3 + 2*l4 + l5 + 2) >> 2;
  944. SRC(0,4)=SRC(2,5)=SRC(4,6)=SRC(6,7)= (l3 + l4 + 1) >> 1;
  945. SRC(1,4)=SRC(3,5)=SRC(5,6)=SRC(7,7)= (l2 + 2*l3 + l4 + 2) >> 2;
  946. SRC(0,3)=SRC(2,4)=SRC(4,5)=SRC(6,6)= (l2 + l3 + 1) >> 1;
  947. SRC(1,3)=SRC(3,4)=SRC(5,5)=SRC(7,6)= (l1 + 2*l2 + l3 + 2) >> 2;
  948. SRC(0,2)=SRC(2,3)=SRC(4,4)=SRC(6,5)= (l1 + l2 + 1) >> 1;
  949. SRC(1,2)=SRC(3,3)=SRC(5,4)=SRC(7,5)= (l0 + 2*l1 + l2 + 2) >> 2;
  950. SRC(0,1)=SRC(2,2)=SRC(4,3)=SRC(6,4)= (l0 + l1 + 1) >> 1;
  951. SRC(1,1)=SRC(3,2)=SRC(5,3)=SRC(7,4)= (lt + 2*l0 + l1 + 2) >> 2;
  952. SRC(0,0)=SRC(2,1)=SRC(4,2)=SRC(6,3)= (lt + l0 + 1) >> 1;
  953. SRC(1,0)=SRC(3,1)=SRC(5,2)=SRC(7,3)= (l0 + 2*lt + t0 + 2) >> 2;
  954. SRC(2,0)=SRC(4,1)=SRC(6,2)= (t1 + 2*t0 + lt + 2) >> 2;
  955. SRC(3,0)=SRC(5,1)=SRC(7,2)= (t2 + 2*t1 + t0 + 2) >> 2;
  956. SRC(4,0)=SRC(6,1)= (t3 + 2*t2 + t1 + 2) >> 2;
  957. SRC(5,0)=SRC(7,1)= (t4 + 2*t3 + t2 + 2) >> 2;
  958. SRC(6,0)= (t5 + 2*t4 + t3 + 2) >> 2;
  959. SRC(7,0)= (t6 + 2*t5 + t4 + 2) >> 2;
  960. }
  961. static void FUNCC(pred8x8l_vertical_left)(uint8_t *_src, int has_topleft,
  962. int has_topright, ptrdiff_t _stride)
  963. {
  964. pixel *src = (pixel*)_src;
  965. int stride = _stride/sizeof(pixel);
  966. PREDICT_8x8_LOAD_TOP;
  967. PREDICT_8x8_LOAD_TOPRIGHT;
  968. SRC(0,0)= (t0 + t1 + 1) >> 1;
  969. SRC(0,1)= (t0 + 2*t1 + t2 + 2) >> 2;
  970. SRC(0,2)=SRC(1,0)= (t1 + t2 + 1) >> 1;
  971. SRC(0,3)=SRC(1,1)= (t1 + 2*t2 + t3 + 2) >> 2;
  972. SRC(0,4)=SRC(1,2)=SRC(2,0)= (t2 + t3 + 1) >> 1;
  973. SRC(0,5)=SRC(1,3)=SRC(2,1)= (t2 + 2*t3 + t4 + 2) >> 2;
  974. SRC(0,6)=SRC(1,4)=SRC(2,2)=SRC(3,0)= (t3 + t4 + 1) >> 1;
  975. SRC(0,7)=SRC(1,5)=SRC(2,3)=SRC(3,1)= (t3 + 2*t4 + t5 + 2) >> 2;
  976. SRC(1,6)=SRC(2,4)=SRC(3,2)=SRC(4,0)= (t4 + t5 + 1) >> 1;
  977. SRC(1,7)=SRC(2,5)=SRC(3,3)=SRC(4,1)= (t4 + 2*t5 + t6 + 2) >> 2;
  978. SRC(2,6)=SRC(3,4)=SRC(4,2)=SRC(5,0)= (t5 + t6 + 1) >> 1;
  979. SRC(2,7)=SRC(3,5)=SRC(4,3)=SRC(5,1)= (t5 + 2*t6 + t7 + 2) >> 2;
  980. SRC(3,6)=SRC(4,4)=SRC(5,2)=SRC(6,0)= (t6 + t7 + 1) >> 1;
  981. SRC(3,7)=SRC(4,5)=SRC(5,3)=SRC(6,1)= (t6 + 2*t7 + t8 + 2) >> 2;
  982. SRC(4,6)=SRC(5,4)=SRC(6,2)=SRC(7,0)= (t7 + t8 + 1) >> 1;
  983. SRC(4,7)=SRC(5,5)=SRC(6,3)=SRC(7,1)= (t7 + 2*t8 + t9 + 2) >> 2;
  984. SRC(5,6)=SRC(6,4)=SRC(7,2)= (t8 + t9 + 1) >> 1;
  985. SRC(5,7)=SRC(6,5)=SRC(7,3)= (t8 + 2*t9 + t10 + 2) >> 2;
  986. SRC(6,6)=SRC(7,4)= (t9 + t10 + 1) >> 1;
  987. SRC(6,7)=SRC(7,5)= (t9 + 2*t10 + t11 + 2) >> 2;
  988. SRC(7,6)= (t10 + t11 + 1) >> 1;
  989. SRC(7,7)= (t10 + 2*t11 + t12 + 2) >> 2;
  990. }
  991. static void FUNCC(pred8x8l_horizontal_up)(uint8_t *_src, int has_topleft,
  992. int has_topright, ptrdiff_t _stride)
  993. {
  994. pixel *src = (pixel*)_src;
  995. int stride = _stride/sizeof(pixel);
  996. PREDICT_8x8_LOAD_LEFT;
  997. SRC(0,0)= (l0 + l1 + 1) >> 1;
  998. SRC(1,0)= (l0 + 2*l1 + l2 + 2) >> 2;
  999. SRC(0,1)=SRC(2,0)= (l1 + l2 + 1) >> 1;
  1000. SRC(1,1)=SRC(3,0)= (l1 + 2*l2 + l3 + 2) >> 2;
  1001. SRC(0,2)=SRC(2,1)=SRC(4,0)= (l2 + l3 + 1) >> 1;
  1002. SRC(1,2)=SRC(3,1)=SRC(5,0)= (l2 + 2*l3 + l4 + 2) >> 2;
  1003. SRC(0,3)=SRC(2,2)=SRC(4,1)=SRC(6,0)= (l3 + l4 + 1) >> 1;
  1004. SRC(1,3)=SRC(3,2)=SRC(5,1)=SRC(7,0)= (l3 + 2*l4 + l5 + 2) >> 2;
  1005. SRC(0,4)=SRC(2,3)=SRC(4,2)=SRC(6,1)= (l4 + l5 + 1) >> 1;
  1006. SRC(1,4)=SRC(3,3)=SRC(5,2)=SRC(7,1)= (l4 + 2*l5 + l6 + 2) >> 2;
  1007. SRC(0,5)=SRC(2,4)=SRC(4,3)=SRC(6,2)= (l5 + l6 + 1) >> 1;
  1008. SRC(1,5)=SRC(3,4)=SRC(5,3)=SRC(7,2)= (l5 + 2*l6 + l7 + 2) >> 2;
  1009. SRC(0,6)=SRC(2,5)=SRC(4,4)=SRC(6,3)= (l6 + l7 + 1) >> 1;
  1010. SRC(1,6)=SRC(3,5)=SRC(5,4)=SRC(7,3)= (l6 + 3*l7 + 2) >> 2;
  1011. SRC(0,7)=SRC(1,7)=SRC(2,6)=SRC(2,7)=SRC(3,6)=
  1012. SRC(3,7)=SRC(4,5)=SRC(4,6)=SRC(4,7)=SRC(5,5)=
  1013. SRC(5,6)=SRC(5,7)=SRC(6,4)=SRC(6,5)=SRC(6,6)=
  1014. SRC(6,7)=SRC(7,4)=SRC(7,5)=SRC(7,6)=SRC(7,7)= l7;
  1015. }
  1016. #undef PREDICT_8x8_LOAD_LEFT
  1017. #undef PREDICT_8x8_LOAD_TOP
  1018. #undef PREDICT_8x8_LOAD_TOPLEFT
  1019. #undef PREDICT_8x8_LOAD_TOPRIGHT
  1020. #undef PREDICT_8x8_DC
  1021. #undef PTR
  1022. #undef PT
  1023. #undef PL
  1024. #undef SRC
  1025. static void FUNCC(pred4x4_vertical_add)(uint8_t *_pix, int16_t *_block,
  1026. ptrdiff_t stride)
  1027. {
  1028. int i;
  1029. pixel *pix = (pixel*)_pix;
  1030. const dctcoef *block = (const dctcoef*)_block;
  1031. stride /= sizeof(pixel);
  1032. pix -= stride;
  1033. for(i=0; i<4; i++){
  1034. pixel v = pix[0];
  1035. pix[1*stride]= v += block[0];
  1036. pix[2*stride]= v += block[4];
  1037. pix[3*stride]= v += block[8];
  1038. pix[4*stride]= v + block[12];
  1039. pix++;
  1040. block++;
  1041. }
  1042. memset(_block, 0, sizeof(dctcoef) * 16);
  1043. }
  1044. static void FUNCC(pred4x4_horizontal_add)(uint8_t *_pix, int16_t *_block,
  1045. ptrdiff_t stride)
  1046. {
  1047. int i;
  1048. pixel *pix = (pixel*)_pix;
  1049. const dctcoef *block = (const dctcoef*)_block;
  1050. stride /= sizeof(pixel);
  1051. for(i=0; i<4; i++){
  1052. pixel v = pix[-1];
  1053. pix[0]= v += block[0];
  1054. pix[1]= v += block[1];
  1055. pix[2]= v += block[2];
  1056. pix[3]= v + block[3];
  1057. pix+= stride;
  1058. block+= 4;
  1059. }
  1060. memset(_block, 0, sizeof(dctcoef) * 16);
  1061. }
  1062. static void FUNCC(pred8x8l_vertical_add)(uint8_t *_pix, int16_t *_block,
  1063. ptrdiff_t stride)
  1064. {
  1065. int i;
  1066. pixel *pix = (pixel*)_pix;
  1067. const dctcoef *block = (const dctcoef*)_block;
  1068. stride /= sizeof(pixel);
  1069. pix -= stride;
  1070. for(i=0; i<8; i++){
  1071. pixel v = pix[0];
  1072. pix[1*stride]= v += block[0];
  1073. pix[2*stride]= v += block[8];
  1074. pix[3*stride]= v += block[16];
  1075. pix[4*stride]= v += block[24];
  1076. pix[5*stride]= v += block[32];
  1077. pix[6*stride]= v += block[40];
  1078. pix[7*stride]= v += block[48];
  1079. pix[8*stride]= v + block[56];
  1080. pix++;
  1081. block++;
  1082. }
  1083. memset(_block, 0, sizeof(dctcoef) * 64);
  1084. }
  1085. static void FUNCC(pred8x8l_horizontal_add)(uint8_t *_pix, int16_t *_block,
  1086. ptrdiff_t stride)
  1087. {
  1088. int i;
  1089. pixel *pix = (pixel*)_pix;
  1090. const dctcoef *block = (const dctcoef*)_block;
  1091. stride /= sizeof(pixel);
  1092. for(i=0; i<8; i++){
  1093. pixel v = pix[-1];
  1094. pix[0]= v += block[0];
  1095. pix[1]= v += block[1];
  1096. pix[2]= v += block[2];
  1097. pix[3]= v += block[3];
  1098. pix[4]= v += block[4];
  1099. pix[5]= v += block[5];
  1100. pix[6]= v += block[6];
  1101. pix[7]= v + block[7];
  1102. pix+= stride;
  1103. block+= 8;
  1104. }
  1105. memset(_block, 0, sizeof(dctcoef) * 64);
  1106. }
  1107. static void FUNCC(pred16x16_vertical_add)(uint8_t *pix, const int *block_offset,
  1108. int16_t *block,
  1109. ptrdiff_t stride)
  1110. {
  1111. int i;
  1112. for(i=0; i<16; i++)
  1113. FUNCC(pred4x4_vertical_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
  1114. }
  1115. static void FUNCC(pred16x16_horizontal_add)(uint8_t *pix,
  1116. const int *block_offset,
  1117. int16_t *block,
  1118. ptrdiff_t stride)
  1119. {
  1120. int i;
  1121. for(i=0; i<16; i++)
  1122. FUNCC(pred4x4_horizontal_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
  1123. }
  1124. static void FUNCC(pred8x8_vertical_add)(uint8_t *pix, const int *block_offset,
  1125. int16_t *block, ptrdiff_t stride)
  1126. {
  1127. int i;
  1128. for(i=0; i<4; i++)
  1129. FUNCC(pred4x4_vertical_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
  1130. }
  1131. static void FUNCC(pred8x16_vertical_add)(uint8_t *pix, const int *block_offset,
  1132. int16_t *block, ptrdiff_t stride)
  1133. {
  1134. int i;
  1135. for(i=0; i<4; i++)
  1136. FUNCC(pred4x4_vertical_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
  1137. for(i=4; i<8; i++)
  1138. FUNCC(pred4x4_vertical_add)(pix + block_offset[i+4], block + i*16*sizeof(pixel), stride);
  1139. }
  1140. static void FUNCC(pred8x8_horizontal_add)(uint8_t *pix, const int *block_offset,
  1141. int16_t *block,
  1142. ptrdiff_t stride)
  1143. {
  1144. int i;
  1145. for(i=0; i<4; i++)
  1146. FUNCC(pred4x4_horizontal_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
  1147. }
  1148. static void FUNCC(pred8x16_horizontal_add)(uint8_t *pix,
  1149. const int *block_offset,
  1150. int16_t *block, ptrdiff_t stride)
  1151. {
  1152. int i;
  1153. for(i=0; i<4; i++)
  1154. FUNCC(pred4x4_horizontal_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
  1155. for(i=4; i<8; i++)
  1156. FUNCC(pred4x4_horizontal_add)(pix + block_offset[i+4], block + i*16*sizeof(pixel), stride);
  1157. }