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.

1273 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 FFmpeg.
  6. *
  7. * FFmpeg 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. * FFmpeg 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 FFmpeg; 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 / MPEG4 part10 prediction functions.
  24. * @author Michael Niedermayer <michaelni@gmx.at>
  25. */
  26. #include "mathops.h"
  27. #include "bit_depth_template.c"
  28. static void FUNCC(pred4x4_vertical)(uint8_t *_src, const uint8_t *topright,
  29. ptrdiff_t _stride)
  30. {
  31. pixel *src = (pixel*)_src;
  32. int stride = _stride>>(sizeof(pixel)-1);
  33. const pixel4 a= AV_RN4PA(src-stride);
  34. AV_WN4PA(src+0*stride, a);
  35. AV_WN4PA(src+1*stride, a);
  36. AV_WN4PA(src+2*stride, a);
  37. AV_WN4PA(src+3*stride, a);
  38. }
  39. static void FUNCC(pred4x4_horizontal)(uint8_t *_src, const uint8_t *topright,
  40. ptrdiff_t _stride)
  41. {
  42. pixel *src = (pixel*)_src;
  43. int stride = _stride>>(sizeof(pixel)-1);
  44. AV_WN4PA(src+0*stride, PIXEL_SPLAT_X4(src[-1+0*stride]));
  45. AV_WN4PA(src+1*stride, PIXEL_SPLAT_X4(src[-1+1*stride]));
  46. AV_WN4PA(src+2*stride, PIXEL_SPLAT_X4(src[-1+2*stride]));
  47. AV_WN4PA(src+3*stride, PIXEL_SPLAT_X4(src[-1+3*stride]));
  48. }
  49. static void FUNCC(pred4x4_dc)(uint8_t *_src, const uint8_t *topright,
  50. ptrdiff_t _stride)
  51. {
  52. pixel *src = (pixel*)_src;
  53. int stride = _stride>>(sizeof(pixel)-1);
  54. const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride]
  55. + src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 4) >>3;
  56. const pixel4 a = PIXEL_SPLAT_X4(dc);
  57. AV_WN4PA(src+0*stride, a);
  58. AV_WN4PA(src+1*stride, a);
  59. AV_WN4PA(src+2*stride, a);
  60. AV_WN4PA(src+3*stride, a);
  61. }
  62. static void FUNCC(pred4x4_left_dc)(uint8_t *_src, const uint8_t *topright,
  63. ptrdiff_t _stride)
  64. {
  65. pixel *src = (pixel*)_src;
  66. int stride = _stride>>(sizeof(pixel)-1);
  67. const int dc= ( src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 2) >>2;
  68. const pixel4 a = PIXEL_SPLAT_X4(dc);
  69. AV_WN4PA(src+0*stride, a);
  70. AV_WN4PA(src+1*stride, a);
  71. AV_WN4PA(src+2*stride, a);
  72. AV_WN4PA(src+3*stride, a);
  73. }
  74. static void FUNCC(pred4x4_top_dc)(uint8_t *_src, const uint8_t *topright,
  75. ptrdiff_t _stride)
  76. {
  77. pixel *src = (pixel*)_src;
  78. int stride = _stride>>(sizeof(pixel)-1);
  79. const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] + 2) >>2;
  80. const pixel4 a = PIXEL_SPLAT_X4(dc);
  81. AV_WN4PA(src+0*stride, a);
  82. AV_WN4PA(src+1*stride, a);
  83. AV_WN4PA(src+2*stride, a);
  84. AV_WN4PA(src+3*stride, a);
  85. }
  86. static void FUNCC(pred4x4_128_dc)(uint8_t *_src, const uint8_t *topright,
  87. ptrdiff_t _stride)
  88. {
  89. pixel *src = (pixel*)_src;
  90. int stride = _stride>>(sizeof(pixel)-1);
  91. const pixel4 a = PIXEL_SPLAT_X4(1<<(BIT_DEPTH-1));
  92. AV_WN4PA(src+0*stride, a);
  93. AV_WN4PA(src+1*stride, a);
  94. AV_WN4PA(src+2*stride, a);
  95. AV_WN4PA(src+3*stride, a);
  96. }
  97. static void FUNCC(pred4x4_127_dc)(uint8_t *_src, const uint8_t *topright,
  98. ptrdiff_t _stride)
  99. {
  100. pixel *src = (pixel*)_src;
  101. int stride = _stride>>(sizeof(pixel)-1);
  102. const pixel4 a = PIXEL_SPLAT_X4((1<<(BIT_DEPTH-1))-1);
  103. AV_WN4PA(src+0*stride, a);
  104. AV_WN4PA(src+1*stride, a);
  105. AV_WN4PA(src+2*stride, a);
  106. AV_WN4PA(src+3*stride, a);
  107. }
  108. static void FUNCC(pred4x4_129_dc)(uint8_t *_src, const uint8_t *topright,
  109. ptrdiff_t _stride)
  110. {
  111. pixel *src = (pixel*)_src;
  112. int stride = _stride>>(sizeof(pixel)-1);
  113. const pixel4 a = PIXEL_SPLAT_X4((1<<(BIT_DEPTH-1))+1);
  114. AV_WN4PA(src+0*stride, a);
  115. AV_WN4PA(src+1*stride, a);
  116. AV_WN4PA(src+2*stride, a);
  117. AV_WN4PA(src+3*stride, a);
  118. }
  119. #define LOAD_TOP_RIGHT_EDGE\
  120. const unsigned av_unused t4 = topright[0];\
  121. const unsigned av_unused t5 = topright[1];\
  122. const unsigned av_unused t6 = topright[2];\
  123. const unsigned av_unused t7 = topright[3];\
  124. #define LOAD_DOWN_LEFT_EDGE\
  125. const unsigned av_unused l4 = src[-1+4*stride];\
  126. const unsigned av_unused l5 = src[-1+5*stride];\
  127. const unsigned av_unused l6 = src[-1+6*stride];\
  128. const unsigned av_unused l7 = src[-1+7*stride];\
  129. #define LOAD_LEFT_EDGE\
  130. const unsigned av_unused l0 = src[-1+0*stride];\
  131. const unsigned av_unused l1 = src[-1+1*stride];\
  132. const unsigned av_unused l2 = src[-1+2*stride];\
  133. const unsigned av_unused l3 = src[-1+3*stride];\
  134. #define LOAD_TOP_EDGE\
  135. const unsigned av_unused t0 = src[ 0-1*stride];\
  136. const unsigned av_unused t1 = src[ 1-1*stride];\
  137. const unsigned av_unused t2 = src[ 2-1*stride];\
  138. const unsigned av_unused t3 = src[ 3-1*stride];\
  139. static void FUNCC(pred4x4_down_right)(uint8_t *_src, const uint8_t *topright,
  140. ptrdiff_t _stride)
  141. {
  142. pixel *src = (pixel*)_src;
  143. int stride = _stride>>(sizeof(pixel)-1);
  144. const int lt= src[-1-1*stride];
  145. LOAD_TOP_EDGE
  146. LOAD_LEFT_EDGE
  147. src[0+3*stride]=(l3 + 2*l2 + l1 + 2)>>2;
  148. src[0+2*stride]=
  149. src[1+3*stride]=(l2 + 2*l1 + l0 + 2)>>2;
  150. src[0+1*stride]=
  151. src[1+2*stride]=
  152. src[2+3*stride]=(l1 + 2*l0 + lt + 2)>>2;
  153. src[0+0*stride]=
  154. src[1+1*stride]=
  155. src[2+2*stride]=
  156. src[3+3*stride]=(l0 + 2*lt + t0 + 2)>>2;
  157. src[1+0*stride]=
  158. src[2+1*stride]=
  159. src[3+2*stride]=(lt + 2*t0 + t1 + 2)>>2;
  160. src[2+0*stride]=
  161. src[3+1*stride]=(t0 + 2*t1 + t2 + 2)>>2;
  162. src[3+0*stride]=(t1 + 2*t2 + t3 + 2)>>2;
  163. }
  164. static void FUNCC(pred4x4_down_left)(uint8_t *_src, const uint8_t *_topright,
  165. ptrdiff_t _stride)
  166. {
  167. pixel *src = (pixel*)_src;
  168. const pixel *topright = (const pixel*)_topright;
  169. int stride = _stride>>(sizeof(pixel)-1);
  170. LOAD_TOP_EDGE
  171. LOAD_TOP_RIGHT_EDGE
  172. // LOAD_LEFT_EDGE
  173. src[0+0*stride]=(t0 + t2 + 2*t1 + 2)>>2;
  174. src[1+0*stride]=
  175. src[0+1*stride]=(t1 + t3 + 2*t2 + 2)>>2;
  176. src[2+0*stride]=
  177. src[1+1*stride]=
  178. src[0+2*stride]=(t2 + t4 + 2*t3 + 2)>>2;
  179. src[3+0*stride]=
  180. src[2+1*stride]=
  181. src[1+2*stride]=
  182. src[0+3*stride]=(t3 + t5 + 2*t4 + 2)>>2;
  183. src[3+1*stride]=
  184. src[2+2*stride]=
  185. src[1+3*stride]=(t4 + t6 + 2*t5 + 2)>>2;
  186. src[3+2*stride]=
  187. src[2+3*stride]=(t5 + t7 + 2*t6 + 2)>>2;
  188. src[3+3*stride]=(t6 + 3*t7 + 2)>>2;
  189. }
  190. static void FUNCC(pred4x4_vertical_right)(uint8_t *_src,
  191. const uint8_t *topright,
  192. ptrdiff_t _stride)
  193. {
  194. pixel *src = (pixel*)_src;
  195. int stride = _stride>>(sizeof(pixel)-1);
  196. const int lt= src[-1-1*stride];
  197. LOAD_TOP_EDGE
  198. LOAD_LEFT_EDGE
  199. src[0+0*stride]=
  200. src[1+2*stride]=(lt + t0 + 1)>>1;
  201. src[1+0*stride]=
  202. src[2+2*stride]=(t0 + t1 + 1)>>1;
  203. src[2+0*stride]=
  204. src[3+2*stride]=(t1 + t2 + 1)>>1;
  205. src[3+0*stride]=(t2 + t3 + 1)>>1;
  206. src[0+1*stride]=
  207. src[1+3*stride]=(l0 + 2*lt + t0 + 2)>>2;
  208. src[1+1*stride]=
  209. src[2+3*stride]=(lt + 2*t0 + t1 + 2)>>2;
  210. src[2+1*stride]=
  211. src[3+3*stride]=(t0 + 2*t1 + t2 + 2)>>2;
  212. src[3+1*stride]=(t1 + 2*t2 + t3 + 2)>>2;
  213. src[0+2*stride]=(lt + 2*l0 + l1 + 2)>>2;
  214. src[0+3*stride]=(l0 + 2*l1 + l2 + 2)>>2;
  215. }
  216. static void FUNCC(pred4x4_vertical_left)(uint8_t *_src,
  217. const uint8_t *_topright,
  218. ptrdiff_t _stride)
  219. {
  220. pixel *src = (pixel*)_src;
  221. const pixel *topright = (const pixel*)_topright;
  222. int stride = _stride>>(sizeof(pixel)-1);
  223. LOAD_TOP_EDGE
  224. LOAD_TOP_RIGHT_EDGE
  225. src[0+0*stride]=(t0 + t1 + 1)>>1;
  226. src[1+0*stride]=
  227. src[0+2*stride]=(t1 + t2 + 1)>>1;
  228. src[2+0*stride]=
  229. src[1+2*stride]=(t2 + t3 + 1)>>1;
  230. src[3+0*stride]=
  231. src[2+2*stride]=(t3 + t4+ 1)>>1;
  232. src[3+2*stride]=(t4 + t5+ 1)>>1;
  233. src[0+1*stride]=(t0 + 2*t1 + t2 + 2)>>2;
  234. src[1+1*stride]=
  235. src[0+3*stride]=(t1 + 2*t2 + t3 + 2)>>2;
  236. src[2+1*stride]=
  237. src[1+3*stride]=(t2 + 2*t3 + t4 + 2)>>2;
  238. src[3+1*stride]=
  239. src[2+3*stride]=(t3 + 2*t4 + t5 + 2)>>2;
  240. src[3+3*stride]=(t4 + 2*t5 + t6 + 2)>>2;
  241. }
  242. static void FUNCC(pred4x4_horizontal_up)(uint8_t *_src, const uint8_t *topright,
  243. ptrdiff_t _stride)
  244. {
  245. pixel *src = (pixel*)_src;
  246. int stride = _stride>>(sizeof(pixel)-1);
  247. LOAD_LEFT_EDGE
  248. src[0+0*stride]=(l0 + l1 + 1)>>1;
  249. src[1+0*stride]=(l0 + 2*l1 + l2 + 2)>>2;
  250. src[2+0*stride]=
  251. src[0+1*stride]=(l1 + l2 + 1)>>1;
  252. src[3+0*stride]=
  253. src[1+1*stride]=(l1 + 2*l2 + l3 + 2)>>2;
  254. src[2+1*stride]=
  255. src[0+2*stride]=(l2 + l3 + 1)>>1;
  256. src[3+1*stride]=
  257. src[1+2*stride]=(l2 + 2*l3 + l3 + 2)>>2;
  258. src[3+2*stride]=
  259. src[1+3*stride]=
  260. src[0+3*stride]=
  261. src[2+2*stride]=
  262. src[2+3*stride]=
  263. src[3+3*stride]=l3;
  264. }
  265. static void FUNCC(pred4x4_horizontal_down)(uint8_t *_src,
  266. const uint8_t *topright,
  267. ptrdiff_t _stride)
  268. {
  269. pixel *src = (pixel*)_src;
  270. int stride = _stride>>(sizeof(pixel)-1);
  271. const int lt= src[-1-1*stride];
  272. LOAD_TOP_EDGE
  273. LOAD_LEFT_EDGE
  274. src[0+0*stride]=
  275. src[2+1*stride]=(lt + l0 + 1)>>1;
  276. src[1+0*stride]=
  277. src[3+1*stride]=(l0 + 2*lt + t0 + 2)>>2;
  278. src[2+0*stride]=(lt + 2*t0 + t1 + 2)>>2;
  279. src[3+0*stride]=(t0 + 2*t1 + t2 + 2)>>2;
  280. src[0+1*stride]=
  281. src[2+2*stride]=(l0 + l1 + 1)>>1;
  282. src[1+1*stride]=
  283. src[3+2*stride]=(lt + 2*l0 + l1 + 2)>>2;
  284. src[0+2*stride]=
  285. src[2+3*stride]=(l1 + l2+ 1)>>1;
  286. src[1+2*stride]=
  287. src[3+3*stride]=(l0 + 2*l1 + l2 + 2)>>2;
  288. src[0+3*stride]=(l2 + l3 + 1)>>1;
  289. src[1+3*stride]=(l1 + 2*l2 + l3 + 2)>>2;
  290. }
  291. static void FUNCC(pred16x16_vertical)(uint8_t *_src, ptrdiff_t _stride)
  292. {
  293. int i;
  294. pixel *src = (pixel*)_src;
  295. int stride = _stride>>(sizeof(pixel)-1);
  296. const pixel4 a = AV_RN4PA(((pixel4*)(src-stride))+0);
  297. const pixel4 b = AV_RN4PA(((pixel4*)(src-stride))+1);
  298. const pixel4 c = AV_RN4PA(((pixel4*)(src-stride))+2);
  299. const pixel4 d = AV_RN4PA(((pixel4*)(src-stride))+3);
  300. for(i=0; i<16; i++){
  301. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
  302. AV_WN4PA(((pixel4*)(src+i*stride))+1, b);
  303. AV_WN4PA(((pixel4*)(src+i*stride))+2, c);
  304. AV_WN4PA(((pixel4*)(src+i*stride))+3, d);
  305. }
  306. }
  307. static void FUNCC(pred16x16_horizontal)(uint8_t *_src, ptrdiff_t stride)
  308. {
  309. int i;
  310. pixel *src = (pixel*)_src;
  311. stride >>= sizeof(pixel)-1;
  312. for(i=0; i<16; i++){
  313. const pixel4 a = PIXEL_SPLAT_X4(src[-1+i*stride]);
  314. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
  315. AV_WN4PA(((pixel4*)(src+i*stride))+1, a);
  316. AV_WN4PA(((pixel4*)(src+i*stride))+2, a);
  317. AV_WN4PA(((pixel4*)(src+i*stride))+3, a);
  318. }
  319. }
  320. #define PREDICT_16x16_DC(v)\
  321. for(i=0; i<16; i++){\
  322. AV_WN4PA(src+ 0, v);\
  323. AV_WN4PA(src+ 4, v);\
  324. AV_WN4PA(src+ 8, v);\
  325. AV_WN4PA(src+12, v);\
  326. src += stride;\
  327. }
  328. static void FUNCC(pred16x16_dc)(uint8_t *_src, ptrdiff_t stride)
  329. {
  330. int i, dc=0;
  331. pixel *src = (pixel*)_src;
  332. pixel4 dcsplat;
  333. stride >>= sizeof(pixel)-1;
  334. for(i=0;i<16; i++){
  335. dc+= src[-1+i*stride];
  336. }
  337. for(i=0;i<16; i++){
  338. dc+= src[i-stride];
  339. }
  340. dcsplat = PIXEL_SPLAT_X4((dc+16)>>5);
  341. PREDICT_16x16_DC(dcsplat);
  342. }
  343. static void FUNCC(pred16x16_left_dc)(uint8_t *_src, ptrdiff_t stride)
  344. {
  345. int i, dc=0;
  346. pixel *src = (pixel*)_src;
  347. pixel4 dcsplat;
  348. stride >>= sizeof(pixel)-1;
  349. for(i=0;i<16; i++){
  350. dc+= src[-1+i*stride];
  351. }
  352. dcsplat = PIXEL_SPLAT_X4((dc+8)>>4);
  353. PREDICT_16x16_DC(dcsplat);
  354. }
  355. static void FUNCC(pred16x16_top_dc)(uint8_t *_src, ptrdiff_t stride)
  356. {
  357. int i, dc=0;
  358. pixel *src = (pixel*)_src;
  359. pixel4 dcsplat;
  360. stride >>= sizeof(pixel)-1;
  361. for(i=0;i<16; i++){
  362. dc+= src[i-stride];
  363. }
  364. dcsplat = PIXEL_SPLAT_X4((dc+8)>>4);
  365. PREDICT_16x16_DC(dcsplat);
  366. }
  367. #define PRED16x16_X(n, v) \
  368. static void FUNCC(pred16x16_##n##_dc)(uint8_t *_src, ptrdiff_t stride)\
  369. {\
  370. int i;\
  371. pixel *src = (pixel*)_src;\
  372. stride >>= sizeof(pixel)-1;\
  373. PREDICT_16x16_DC(PIXEL_SPLAT_X4(v));\
  374. }
  375. PRED16x16_X(127, (1<<(BIT_DEPTH-1))-1)
  376. PRED16x16_X(128, (1<<(BIT_DEPTH-1))+0)
  377. PRED16x16_X(129, (1<<(BIT_DEPTH-1))+1)
  378. static inline void FUNCC(pred16x16_plane_compat)(uint8_t *_src,
  379. ptrdiff_t _stride,
  380. const int svq3,
  381. const int rv40)
  382. {
  383. int i, j, k;
  384. int a;
  385. INIT_CLIP
  386. pixel *src = (pixel*)_src;
  387. int stride = _stride>>(sizeof(pixel)-1);
  388. const pixel * const src0 = src +7-stride;
  389. const pixel * src1 = src +8*stride-1;
  390. const pixel * src2 = src1-2*stride; // == src+6*stride-1;
  391. int H = src0[1] - src0[-1];
  392. int V = src1[0] - src2[ 0];
  393. for(k=2; k<=8; ++k) {
  394. src1 += stride; src2 -= stride;
  395. H += k*(src0[k] - src0[-k]);
  396. V += k*(src1[0] - src2[ 0]);
  397. }
  398. if(svq3){
  399. H = ( 5*(H/4) ) / 16;
  400. V = ( 5*(V/4) ) / 16;
  401. /* required for 100% accuracy */
  402. i = H; H = V; V = i;
  403. }else if(rv40){
  404. H = ( H + (H>>2) ) >> 4;
  405. V = ( V + (V>>2) ) >> 4;
  406. }else{
  407. H = ( 5*H+32 ) >> 6;
  408. V = ( 5*V+32 ) >> 6;
  409. }
  410. a = 16*(src1[0] + src2[16] + 1) - 7*(V+H);
  411. for(j=16; j>0; --j) {
  412. int b = a;
  413. a += V;
  414. for(i=-16; i<0; i+=4) {
  415. src[16+i] = CLIP((b ) >> 5);
  416. src[17+i] = CLIP((b+ H) >> 5);
  417. src[18+i] = CLIP((b+2*H) >> 5);
  418. src[19+i] = CLIP((b+3*H) >> 5);
  419. b += 4*H;
  420. }
  421. src += stride;
  422. }
  423. }
  424. static void FUNCC(pred16x16_plane)(uint8_t *src, ptrdiff_t stride)
  425. {
  426. FUNCC(pred16x16_plane_compat)(src, stride, 0, 0);
  427. }
  428. static void FUNCC(pred8x8_vertical)(uint8_t *_src, ptrdiff_t _stride)
  429. {
  430. int i;
  431. pixel *src = (pixel*)_src;
  432. int stride = _stride>>(sizeof(pixel)-1);
  433. const pixel4 a= AV_RN4PA(((pixel4*)(src-stride))+0);
  434. const pixel4 b= AV_RN4PA(((pixel4*)(src-stride))+1);
  435. for(i=0; i<8; i++){
  436. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
  437. AV_WN4PA(((pixel4*)(src+i*stride))+1, b);
  438. }
  439. }
  440. static void FUNCC(pred8x16_vertical)(uint8_t *_src, ptrdiff_t _stride)
  441. {
  442. int i;
  443. pixel *src = (pixel*)_src;
  444. int stride = _stride>>(sizeof(pixel)-1);
  445. const pixel4 a= AV_RN4PA(((pixel4*)(src-stride))+0);
  446. const pixel4 b= AV_RN4PA(((pixel4*)(src-stride))+1);
  447. for(i=0; i<16; i++){
  448. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
  449. AV_WN4PA(((pixel4*)(src+i*stride))+1, b);
  450. }
  451. }
  452. static void FUNCC(pred8x8_horizontal)(uint8_t *_src, ptrdiff_t stride)
  453. {
  454. int i;
  455. pixel *src = (pixel*)_src;
  456. stride >>= sizeof(pixel)-1;
  457. for(i=0; i<8; i++){
  458. const pixel4 a = PIXEL_SPLAT_X4(src[-1+i*stride]);
  459. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
  460. AV_WN4PA(((pixel4*)(src+i*stride))+1, a);
  461. }
  462. }
  463. static void FUNCC(pred8x16_horizontal)(uint8_t *_src, ptrdiff_t stride)
  464. {
  465. int i;
  466. pixel *src = (pixel*)_src;
  467. stride >>= sizeof(pixel)-1;
  468. for(i=0; i<16; i++){
  469. const pixel4 a = PIXEL_SPLAT_X4(src[-1+i*stride]);
  470. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
  471. AV_WN4PA(((pixel4*)(src+i*stride))+1, a);
  472. }
  473. }
  474. #define PRED8x8_X(n, v)\
  475. static void FUNCC(pred8x8_##n##_dc)(uint8_t *_src, ptrdiff_t stride)\
  476. {\
  477. int i;\
  478. const pixel4 a = PIXEL_SPLAT_X4(v);\
  479. pixel *src = (pixel*)_src;\
  480. stride >>= sizeof(pixel)-1;\
  481. for(i=0; i<8; i++){\
  482. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);\
  483. AV_WN4PA(((pixel4*)(src+i*stride))+1, a);\
  484. }\
  485. }
  486. PRED8x8_X(127, (1<<(BIT_DEPTH-1))-1)
  487. PRED8x8_X(128, (1<<(BIT_DEPTH-1))+0)
  488. PRED8x8_X(129, (1<<(BIT_DEPTH-1))+1)
  489. static void FUNCC(pred8x16_128_dc)(uint8_t *_src, ptrdiff_t stride)
  490. {
  491. FUNCC(pred8x8_128_dc)(_src, stride);
  492. FUNCC(pred8x8_128_dc)(_src+8*stride, stride);
  493. }
  494. static void FUNCC(pred8x8_left_dc)(uint8_t *_src, ptrdiff_t stride)
  495. {
  496. int i;
  497. int dc0, dc2;
  498. pixel4 dc0splat, dc2splat;
  499. pixel *src = (pixel*)_src;
  500. stride >>= sizeof(pixel)-1;
  501. dc0=dc2=0;
  502. for(i=0;i<4; i++){
  503. dc0+= src[-1+i*stride];
  504. dc2+= src[-1+(i+4)*stride];
  505. }
  506. dc0splat = PIXEL_SPLAT_X4((dc0 + 2)>>2);
  507. dc2splat = PIXEL_SPLAT_X4((dc2 + 2)>>2);
  508. for(i=0; i<4; i++){
  509. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
  510. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc0splat);
  511. }
  512. for(i=4; i<8; i++){
  513. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc2splat);
  514. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc2splat);
  515. }
  516. }
  517. static void FUNCC(pred8x16_left_dc)(uint8_t *_src, ptrdiff_t stride)
  518. {
  519. FUNCC(pred8x8_left_dc)(_src, stride);
  520. FUNCC(pred8x8_left_dc)(_src+8*stride, stride);
  521. }
  522. static void FUNCC(pred8x8_top_dc)(uint8_t *_src, ptrdiff_t stride)
  523. {
  524. int i;
  525. int dc0, dc1;
  526. pixel4 dc0splat, dc1splat;
  527. pixel *src = (pixel*)_src;
  528. stride >>= sizeof(pixel)-1;
  529. dc0=dc1=0;
  530. for(i=0;i<4; i++){
  531. dc0+= src[i-stride];
  532. dc1+= src[4+i-stride];
  533. }
  534. dc0splat = PIXEL_SPLAT_X4((dc0 + 2)>>2);
  535. dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2);
  536. for(i=0; i<4; i++){
  537. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
  538. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
  539. }
  540. for(i=4; i<8; i++){
  541. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
  542. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
  543. }
  544. }
  545. static void FUNCC(pred8x16_top_dc)(uint8_t *_src, ptrdiff_t stride)
  546. {
  547. int i;
  548. int dc0, dc1;
  549. pixel4 dc0splat, dc1splat;
  550. pixel *src = (pixel*)_src;
  551. stride >>= sizeof(pixel)-1;
  552. dc0=dc1=0;
  553. for(i=0;i<4; i++){
  554. dc0+= src[i-stride];
  555. dc1+= src[4+i-stride];
  556. }
  557. dc0splat = PIXEL_SPLAT_X4((dc0 + 2)>>2);
  558. dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2);
  559. for(i=0; i<16; i++){
  560. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
  561. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
  562. }
  563. }
  564. static void FUNCC(pred8x8_dc)(uint8_t *_src, ptrdiff_t stride)
  565. {
  566. int i;
  567. int dc0, dc1, dc2;
  568. pixel4 dc0splat, dc1splat, dc2splat, dc3splat;
  569. pixel *src = (pixel*)_src;
  570. stride >>= sizeof(pixel)-1;
  571. dc0=dc1=dc2=0;
  572. for(i=0;i<4; i++){
  573. dc0+= src[-1+i*stride] + src[i-stride];
  574. dc1+= src[4+i-stride];
  575. dc2+= src[-1+(i+4)*stride];
  576. }
  577. dc0splat = PIXEL_SPLAT_X4((dc0 + 4)>>3);
  578. dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2);
  579. dc2splat = PIXEL_SPLAT_X4((dc2 + 2)>>2);
  580. dc3splat = PIXEL_SPLAT_X4((dc1 + dc2 + 4)>>3);
  581. for(i=0; i<4; i++){
  582. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
  583. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
  584. }
  585. for(i=4; i<8; i++){
  586. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc2splat);
  587. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc3splat);
  588. }
  589. }
  590. static void FUNCC(pred8x16_dc)(uint8_t *_src, ptrdiff_t stride)
  591. {
  592. int i;
  593. int dc0, dc1, dc2, dc3, dc4;
  594. pixel4 dc0splat, dc1splat, dc2splat, dc3splat, dc4splat, dc5splat, dc6splat, dc7splat;
  595. pixel *src = (pixel*)_src;
  596. stride >>= sizeof(pixel)-1;
  597. dc0=dc1=dc2=dc3=dc4=0;
  598. for(i=0;i<4; i++){
  599. dc0+= src[-1+i*stride] + src[i-stride];
  600. dc1+= src[4+i-stride];
  601. dc2+= src[-1+(i+4)*stride];
  602. dc3+= src[-1+(i+8)*stride];
  603. dc4+= src[-1+(i+12)*stride];
  604. }
  605. dc0splat = PIXEL_SPLAT_X4((dc0 + 4)>>3);
  606. dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2);
  607. dc2splat = PIXEL_SPLAT_X4((dc2 + 2)>>2);
  608. dc3splat = PIXEL_SPLAT_X4((dc1 + dc2 + 4)>>3);
  609. dc4splat = PIXEL_SPLAT_X4((dc3 + 2)>>2);
  610. dc5splat = PIXEL_SPLAT_X4((dc1 + dc3 + 4)>>3);
  611. dc6splat = PIXEL_SPLAT_X4((dc4 + 2)>>2);
  612. dc7splat = PIXEL_SPLAT_X4((dc1 + dc4 + 4)>>3);
  613. for(i=0; i<4; i++){
  614. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
  615. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
  616. }
  617. for(i=4; i<8; i++){
  618. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc2splat);
  619. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc3splat);
  620. }
  621. for(i=8; i<12; i++){
  622. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc4splat);
  623. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc5splat);
  624. }
  625. for(i=12; i<16; i++){
  626. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc6splat);
  627. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc7splat);
  628. }
  629. }
  630. //the following 4 function should not be optimized!
  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)-1);
  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)-1);
  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)-1);
  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)-1);
  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)-1);
  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)-1);
  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)-1);
  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)-1);
  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)-1);
  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)-1);
  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)-1);
  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)-1);
  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)-1);
  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, const 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)-1;
  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. }
  1043. static void FUNCC(pred4x4_horizontal_add)(uint8_t *_pix, const int16_t *_block,
  1044. ptrdiff_t stride)
  1045. {
  1046. int i;
  1047. pixel *pix = (pixel*)_pix;
  1048. const dctcoef *block = (const dctcoef*)_block;
  1049. stride >>= sizeof(pixel)-1;
  1050. for(i=0; i<4; i++){
  1051. pixel v = pix[-1];
  1052. pix[0]= v += block[0];
  1053. pix[1]= v += block[1];
  1054. pix[2]= v += block[2];
  1055. pix[3]= v + block[3];
  1056. pix+= stride;
  1057. block+= 4;
  1058. }
  1059. }
  1060. static void FUNCC(pred8x8l_vertical_add)(uint8_t *_pix, const int16_t *_block,
  1061. ptrdiff_t stride)
  1062. {
  1063. int i;
  1064. pixel *pix = (pixel*)_pix;
  1065. const dctcoef *block = (const dctcoef*)_block;
  1066. stride >>= sizeof(pixel)-1;
  1067. pix -= stride;
  1068. for(i=0; i<8; i++){
  1069. pixel v = pix[0];
  1070. pix[1*stride]= v += block[0];
  1071. pix[2*stride]= v += block[8];
  1072. pix[3*stride]= v += block[16];
  1073. pix[4*stride]= v += block[24];
  1074. pix[5*stride]= v += block[32];
  1075. pix[6*stride]= v += block[40];
  1076. pix[7*stride]= v += block[48];
  1077. pix[8*stride]= v + block[56];
  1078. pix++;
  1079. block++;
  1080. }
  1081. }
  1082. static void FUNCC(pred8x8l_horizontal_add)(uint8_t *_pix, const int16_t *_block,
  1083. ptrdiff_t stride)
  1084. {
  1085. int i;
  1086. pixel *pix = (pixel*)_pix;
  1087. const dctcoef *block = (const dctcoef*)_block;
  1088. stride >>= sizeof(pixel)-1;
  1089. for(i=0; i<8; i++){
  1090. pixel v = pix[-1];
  1091. pix[0]= v += block[0];
  1092. pix[1]= v += block[1];
  1093. pix[2]= v += block[2];
  1094. pix[3]= v += block[3];
  1095. pix[4]= v += block[4];
  1096. pix[5]= v += block[5];
  1097. pix[6]= v += block[6];
  1098. pix[7]= v + block[7];
  1099. pix+= stride;
  1100. block+= 8;
  1101. }
  1102. }
  1103. static void FUNCC(pred16x16_vertical_add)(uint8_t *pix, const int *block_offset,
  1104. const int16_t *block,
  1105. ptrdiff_t stride)
  1106. {
  1107. int i;
  1108. for(i=0; i<16; i++)
  1109. FUNCC(pred4x4_vertical_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
  1110. }
  1111. static void FUNCC(pred16x16_horizontal_add)(uint8_t *pix,
  1112. const int *block_offset,
  1113. const int16_t *block,
  1114. ptrdiff_t stride)
  1115. {
  1116. int i;
  1117. for(i=0; i<16; i++)
  1118. FUNCC(pred4x4_horizontal_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
  1119. }
  1120. static void FUNCC(pred8x8_vertical_add)(uint8_t *pix, const int *block_offset,
  1121. const int16_t *block, ptrdiff_t stride)
  1122. {
  1123. int i;
  1124. for(i=0; i<4; i++)
  1125. FUNCC(pred4x4_vertical_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
  1126. }
  1127. static void FUNCC(pred8x16_vertical_add)(uint8_t *pix, const int *block_offset,
  1128. const int16_t *block, ptrdiff_t stride)
  1129. {
  1130. int i;
  1131. for(i=0; i<4; i++)
  1132. FUNCC(pred4x4_vertical_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
  1133. for(i=4; i<8; i++)
  1134. FUNCC(pred4x4_vertical_add)(pix + block_offset[i+4], block + i*16*sizeof(pixel), stride);
  1135. }
  1136. static void FUNCC(pred8x8_horizontal_add)(uint8_t *pix, const int *block_offset,
  1137. const int16_t *block,
  1138. ptrdiff_t stride)
  1139. {
  1140. int i;
  1141. for(i=0; i<4; i++)
  1142. FUNCC(pred4x4_horizontal_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
  1143. }
  1144. static void FUNCC(pred8x16_horizontal_add)(uint8_t *pix,
  1145. const int *block_offset,
  1146. const int16_t *block, ptrdiff_t stride)
  1147. {
  1148. int i;
  1149. for(i=0; i<4; i++)
  1150. FUNCC(pred4x4_horizontal_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
  1151. for(i=4; i<8; i++)
  1152. FUNCC(pred4x4_horizontal_add)(pix + block_offset[i+4], block + i*16*sizeof(pixel), stride);
  1153. }