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.

995 lines
33KB

  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 / MPEG4 part10 prediction functions.
  24. * @author Michael Niedermayer <michaelni@gmx.at>
  25. */
  26. #include "mathops.h"
  27. #include "high_bit_depth.h"
  28. static void FUNCC(pred4x4_vertical)(uint8_t *_src, const uint8_t *topright, int _stride){
  29. pixel *src = (pixel*)_src;
  30. int stride = _stride/sizeof(pixel);
  31. const pixel4 a= AV_RN4PA(src-stride);
  32. AV_WN4PA(src+0*stride, a);
  33. AV_WN4PA(src+1*stride, a);
  34. AV_WN4PA(src+2*stride, a);
  35. AV_WN4PA(src+3*stride, a);
  36. }
  37. static void FUNCC(pred4x4_horizontal)(uint8_t *_src, const uint8_t *topright, int _stride){
  38. pixel *src = (pixel*)_src;
  39. int stride = _stride/sizeof(pixel);
  40. AV_WN4PA(src+0*stride, PIXEL_SPLAT_X4(src[-1+0*stride]));
  41. AV_WN4PA(src+1*stride, PIXEL_SPLAT_X4(src[-1+1*stride]));
  42. AV_WN4PA(src+2*stride, PIXEL_SPLAT_X4(src[-1+2*stride]));
  43. AV_WN4PA(src+3*stride, PIXEL_SPLAT_X4(src[-1+3*stride]));
  44. }
  45. static void FUNCC(pred4x4_dc)(uint8_t *_src, const uint8_t *topright, int _stride){
  46. pixel *src = (pixel*)_src;
  47. int stride = _stride/sizeof(pixel);
  48. const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride]
  49. + src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 4) >>3;
  50. const pixel4 a = PIXEL_SPLAT_X4(dc);
  51. AV_WN4PA(src+0*stride, a);
  52. AV_WN4PA(src+1*stride, a);
  53. AV_WN4PA(src+2*stride, a);
  54. AV_WN4PA(src+3*stride, a);
  55. }
  56. static void FUNCC(pred4x4_left_dc)(uint8_t *_src, const uint8_t *topright, int _stride){
  57. pixel *src = (pixel*)_src;
  58. int stride = _stride/sizeof(pixel);
  59. const int dc= ( src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 2) >>2;
  60. const pixel4 a = PIXEL_SPLAT_X4(dc);
  61. AV_WN4PA(src+0*stride, a);
  62. AV_WN4PA(src+1*stride, a);
  63. AV_WN4PA(src+2*stride, a);
  64. AV_WN4PA(src+3*stride, a);
  65. }
  66. static void FUNCC(pred4x4_top_dc)(uint8_t *_src, const uint8_t *topright, int _stride){
  67. pixel *src = (pixel*)_src;
  68. int stride = _stride/sizeof(pixel);
  69. const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] + 2) >>2;
  70. const pixel4 a = PIXEL_SPLAT_X4(dc);
  71. AV_WN4PA(src+0*stride, a);
  72. AV_WN4PA(src+1*stride, a);
  73. AV_WN4PA(src+2*stride, a);
  74. AV_WN4PA(src+3*stride, a);
  75. }
  76. static void FUNCC(pred4x4_128_dc)(uint8_t *_src, const uint8_t *topright, int _stride){
  77. pixel *src = (pixel*)_src;
  78. int stride = _stride/sizeof(pixel);
  79. const pixel4 a = PIXEL_SPLAT_X4(1<<(BIT_DEPTH-1));
  80. AV_WN4PA(src+0*stride, a);
  81. AV_WN4PA(src+1*stride, a);
  82. AV_WN4PA(src+2*stride, a);
  83. AV_WN4PA(src+3*stride, a);
  84. }
  85. static void FUNCC(pred4x4_127_dc)(uint8_t *_src, const uint8_t *topright, int _stride){
  86. pixel *src = (pixel*)_src;
  87. int stride = _stride/sizeof(pixel);
  88. const pixel4 a = PIXEL_SPLAT_X4((1<<(BIT_DEPTH-1))-1);
  89. AV_WN4PA(src+0*stride, a);
  90. AV_WN4PA(src+1*stride, a);
  91. AV_WN4PA(src+2*stride, a);
  92. AV_WN4PA(src+3*stride, a);
  93. }
  94. static void FUNCC(pred4x4_129_dc)(uint8_t *_src, const uint8_t *topright, int _stride){
  95. pixel *src = (pixel*)_src;
  96. int stride = _stride/sizeof(pixel);
  97. const pixel4 a = PIXEL_SPLAT_X4((1<<(BIT_DEPTH-1))+1);
  98. AV_WN4PA(src+0*stride, a);
  99. AV_WN4PA(src+1*stride, a);
  100. AV_WN4PA(src+2*stride, a);
  101. AV_WN4PA(src+3*stride, a);
  102. }
  103. #define LOAD_TOP_RIGHT_EDGE\
  104. const int av_unused t4= topright[0];\
  105. const int av_unused t5= topright[1];\
  106. const int av_unused t6= topright[2];\
  107. const int av_unused t7= topright[3];\
  108. #define LOAD_DOWN_LEFT_EDGE\
  109. const int av_unused l4= src[-1+4*stride];\
  110. const int av_unused l5= src[-1+5*stride];\
  111. const int av_unused l6= src[-1+6*stride];\
  112. const int av_unused l7= src[-1+7*stride];\
  113. #define LOAD_LEFT_EDGE\
  114. const int av_unused l0= src[-1+0*stride];\
  115. const int av_unused l1= src[-1+1*stride];\
  116. const int av_unused l2= src[-1+2*stride];\
  117. const int av_unused l3= src[-1+3*stride];\
  118. #define LOAD_TOP_EDGE\
  119. const int av_unused t0= src[ 0-1*stride];\
  120. const int av_unused t1= src[ 1-1*stride];\
  121. const int av_unused t2= src[ 2-1*stride];\
  122. const int av_unused t3= src[ 3-1*stride];\
  123. static void FUNCC(pred4x4_down_right)(uint8_t *_src, const uint8_t *topright, int _stride){
  124. pixel *src = (pixel*)_src;
  125. int stride = _stride/sizeof(pixel);
  126. const int lt= src[-1-1*stride];
  127. LOAD_TOP_EDGE
  128. LOAD_LEFT_EDGE
  129. src[0+3*stride]=(l3 + 2*l2 + l1 + 2)>>2;
  130. src[0+2*stride]=
  131. src[1+3*stride]=(l2 + 2*l1 + l0 + 2)>>2;
  132. src[0+1*stride]=
  133. src[1+2*stride]=
  134. src[2+3*stride]=(l1 + 2*l0 + lt + 2)>>2;
  135. src[0+0*stride]=
  136. src[1+1*stride]=
  137. src[2+2*stride]=
  138. src[3+3*stride]=(l0 + 2*lt + t0 + 2)>>2;
  139. src[1+0*stride]=
  140. src[2+1*stride]=
  141. src[3+2*stride]=(lt + 2*t0 + t1 + 2)>>2;
  142. src[2+0*stride]=
  143. src[3+1*stride]=(t0 + 2*t1 + t2 + 2)>>2;
  144. src[3+0*stride]=(t1 + 2*t2 + t3 + 2)>>2;
  145. }
  146. static void FUNCC(pred4x4_down_left)(uint8_t *_src, const uint8_t *_topright, int _stride){
  147. pixel *src = (pixel*)_src;
  148. const pixel *topright = (const pixel*)_topright;
  149. int stride = _stride/sizeof(pixel);
  150. LOAD_TOP_EDGE
  151. LOAD_TOP_RIGHT_EDGE
  152. // LOAD_LEFT_EDGE
  153. src[0+0*stride]=(t0 + t2 + 2*t1 + 2)>>2;
  154. src[1+0*stride]=
  155. src[0+1*stride]=(t1 + t3 + 2*t2 + 2)>>2;
  156. src[2+0*stride]=
  157. src[1+1*stride]=
  158. src[0+2*stride]=(t2 + t4 + 2*t3 + 2)>>2;
  159. src[3+0*stride]=
  160. src[2+1*stride]=
  161. src[1+2*stride]=
  162. src[0+3*stride]=(t3 + t5 + 2*t4 + 2)>>2;
  163. src[3+1*stride]=
  164. src[2+2*stride]=
  165. src[1+3*stride]=(t4 + t6 + 2*t5 + 2)>>2;
  166. src[3+2*stride]=
  167. src[2+3*stride]=(t5 + t7 + 2*t6 + 2)>>2;
  168. src[3+3*stride]=(t6 + 3*t7 + 2)>>2;
  169. }
  170. static void FUNCC(pred4x4_vertical_right)(uint8_t *_src, const uint8_t *topright, int _stride){
  171. pixel *src = (pixel*)_src;
  172. int stride = _stride/sizeof(pixel);
  173. const int lt= src[-1-1*stride];
  174. LOAD_TOP_EDGE
  175. LOAD_LEFT_EDGE
  176. src[0+0*stride]=
  177. src[1+2*stride]=(lt + t0 + 1)>>1;
  178. src[1+0*stride]=
  179. src[2+2*stride]=(t0 + t1 + 1)>>1;
  180. src[2+0*stride]=
  181. src[3+2*stride]=(t1 + t2 + 1)>>1;
  182. src[3+0*stride]=(t2 + t3 + 1)>>1;
  183. src[0+1*stride]=
  184. src[1+3*stride]=(l0 + 2*lt + t0 + 2)>>2;
  185. src[1+1*stride]=
  186. src[2+3*stride]=(lt + 2*t0 + t1 + 2)>>2;
  187. src[2+1*stride]=
  188. src[3+3*stride]=(t0 + 2*t1 + t2 + 2)>>2;
  189. src[3+1*stride]=(t1 + 2*t2 + t3 + 2)>>2;
  190. src[0+2*stride]=(lt + 2*l0 + l1 + 2)>>2;
  191. src[0+3*stride]=(l0 + 2*l1 + l2 + 2)>>2;
  192. }
  193. static void FUNCC(pred4x4_vertical_left)(uint8_t *_src, const uint8_t *_topright, int _stride){
  194. pixel *src = (pixel*)_src;
  195. const pixel *topright = (const pixel*)_topright;
  196. int stride = _stride/sizeof(pixel);
  197. LOAD_TOP_EDGE
  198. LOAD_TOP_RIGHT_EDGE
  199. src[0+0*stride]=(t0 + t1 + 1)>>1;
  200. src[1+0*stride]=
  201. src[0+2*stride]=(t1 + t2 + 1)>>1;
  202. src[2+0*stride]=
  203. src[1+2*stride]=(t2 + t3 + 1)>>1;
  204. src[3+0*stride]=
  205. src[2+2*stride]=(t3 + t4+ 1)>>1;
  206. src[3+2*stride]=(t4 + t5+ 1)>>1;
  207. src[0+1*stride]=(t0 + 2*t1 + t2 + 2)>>2;
  208. src[1+1*stride]=
  209. src[0+3*stride]=(t1 + 2*t2 + t3 + 2)>>2;
  210. src[2+1*stride]=
  211. src[1+3*stride]=(t2 + 2*t3 + t4 + 2)>>2;
  212. src[3+1*stride]=
  213. src[2+3*stride]=(t3 + 2*t4 + t5 + 2)>>2;
  214. src[3+3*stride]=(t4 + 2*t5 + t6 + 2)>>2;
  215. }
  216. static void FUNCC(pred4x4_horizontal_up)(uint8_t *_src, const uint8_t *topright, int _stride){
  217. pixel *src = (pixel*)_src;
  218. int stride = _stride/sizeof(pixel);
  219. LOAD_LEFT_EDGE
  220. src[0+0*stride]=(l0 + l1 + 1)>>1;
  221. src[1+0*stride]=(l0 + 2*l1 + l2 + 2)>>2;
  222. src[2+0*stride]=
  223. src[0+1*stride]=(l1 + l2 + 1)>>1;
  224. src[3+0*stride]=
  225. src[1+1*stride]=(l1 + 2*l2 + l3 + 2)>>2;
  226. src[2+1*stride]=
  227. src[0+2*stride]=(l2 + l3 + 1)>>1;
  228. src[3+1*stride]=
  229. src[1+2*stride]=(l2 + 2*l3 + l3 + 2)>>2;
  230. src[3+2*stride]=
  231. src[1+3*stride]=
  232. src[0+3*stride]=
  233. src[2+2*stride]=
  234. src[2+3*stride]=
  235. src[3+3*stride]=l3;
  236. }
  237. static void FUNCC(pred4x4_horizontal_down)(uint8_t *_src, const uint8_t *topright, int _stride){
  238. pixel *src = (pixel*)_src;
  239. int stride = _stride/sizeof(pixel);
  240. const int lt= src[-1-1*stride];
  241. LOAD_TOP_EDGE
  242. LOAD_LEFT_EDGE
  243. src[0+0*stride]=
  244. src[2+1*stride]=(lt + l0 + 1)>>1;
  245. src[1+0*stride]=
  246. src[3+1*stride]=(l0 + 2*lt + t0 + 2)>>2;
  247. src[2+0*stride]=(lt + 2*t0 + t1 + 2)>>2;
  248. src[3+0*stride]=(t0 + 2*t1 + t2 + 2)>>2;
  249. src[0+1*stride]=
  250. src[2+2*stride]=(l0 + l1 + 1)>>1;
  251. src[1+1*stride]=
  252. src[3+2*stride]=(lt + 2*l0 + l1 + 2)>>2;
  253. src[0+2*stride]=
  254. src[2+3*stride]=(l1 + l2+ 1)>>1;
  255. src[1+2*stride]=
  256. src[3+3*stride]=(l0 + 2*l1 + l2 + 2)>>2;
  257. src[0+3*stride]=(l2 + l3 + 1)>>1;
  258. src[1+3*stride]=(l1 + 2*l2 + l3 + 2)>>2;
  259. }
  260. static void FUNCC(pred16x16_vertical)(uint8_t *_src, int _stride){
  261. int i;
  262. pixel *src = (pixel*)_src;
  263. int stride = _stride/sizeof(pixel);
  264. const pixel4 a = AV_RN4PA(((pixel4*)(src-stride))+0);
  265. const pixel4 b = AV_RN4PA(((pixel4*)(src-stride))+1);
  266. const pixel4 c = AV_RN4PA(((pixel4*)(src-stride))+2);
  267. const pixel4 d = AV_RN4PA(((pixel4*)(src-stride))+3);
  268. for(i=0; i<16; i++){
  269. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
  270. AV_WN4PA(((pixel4*)(src+i*stride))+1, b);
  271. AV_WN4PA(((pixel4*)(src+i*stride))+2, c);
  272. AV_WN4PA(((pixel4*)(src+i*stride))+3, d);
  273. }
  274. }
  275. static void FUNCC(pred16x16_horizontal)(uint8_t *_src, int stride){
  276. int i;
  277. pixel *src = (pixel*)_src;
  278. stride /= sizeof(pixel);
  279. for(i=0; i<16; i++){
  280. const pixel4 a = PIXEL_SPLAT_X4(src[-1+i*stride]);
  281. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
  282. AV_WN4PA(((pixel4*)(src+i*stride))+1, a);
  283. AV_WN4PA(((pixel4*)(src+i*stride))+2, a);
  284. AV_WN4PA(((pixel4*)(src+i*stride))+3, a);
  285. }
  286. }
  287. #define PREDICT_16x16_DC(v)\
  288. for(i=0; i<16; i++){\
  289. AV_WN4PA(src+ 0, v);\
  290. AV_WN4PA(src+ 4, v);\
  291. AV_WN4PA(src+ 8, v);\
  292. AV_WN4PA(src+12, v);\
  293. src += stride;\
  294. }
  295. static void FUNCC(pred16x16_dc)(uint8_t *_src, int stride){
  296. int i, dc=0;
  297. pixel *src = (pixel*)_src;
  298. pixel4 dcsplat;
  299. stride /= sizeof(pixel);
  300. for(i=0;i<16; i++){
  301. dc+= src[-1+i*stride];
  302. }
  303. for(i=0;i<16; i++){
  304. dc+= src[i-stride];
  305. }
  306. dcsplat = PIXEL_SPLAT_X4((dc+16)>>5);
  307. PREDICT_16x16_DC(dcsplat);
  308. }
  309. static void FUNCC(pred16x16_left_dc)(uint8_t *_src, int stride){
  310. int i, dc=0;
  311. pixel *src = (pixel*)_src;
  312. pixel4 dcsplat;
  313. stride /= sizeof(pixel);
  314. for(i=0;i<16; i++){
  315. dc+= src[-1+i*stride];
  316. }
  317. dcsplat = PIXEL_SPLAT_X4((dc+8)>>4);
  318. PREDICT_16x16_DC(dcsplat);
  319. }
  320. static void FUNCC(pred16x16_top_dc)(uint8_t *_src, int stride){
  321. int i, dc=0;
  322. pixel *src = (pixel*)_src;
  323. pixel4 dcsplat;
  324. stride /= sizeof(pixel);
  325. for(i=0;i<16; i++){
  326. dc+= src[i-stride];
  327. }
  328. dcsplat = PIXEL_SPLAT_X4((dc+8)>>4);
  329. PREDICT_16x16_DC(dcsplat);
  330. }
  331. #define PRED16x16_X(n, v) \
  332. static void FUNCC(pred16x16_##n##_dc)(uint8_t *_src, int stride){\
  333. int i;\
  334. pixel *src = (pixel*)_src;\
  335. stride /= sizeof(pixel);\
  336. PREDICT_16x16_DC(PIXEL_SPLAT_X4(v));\
  337. }
  338. PRED16x16_X(127, (1<<(BIT_DEPTH-1))-1);
  339. PRED16x16_X(128, (1<<(BIT_DEPTH-1))+0);
  340. PRED16x16_X(129, (1<<(BIT_DEPTH-1))+1);
  341. static inline void FUNCC(pred16x16_plane_compat)(uint8_t *_src, int _stride, const int svq3, const int rv40){
  342. int i, j, k;
  343. int a;
  344. INIT_CLIP
  345. pixel *src = (pixel*)_src;
  346. int stride = _stride/sizeof(pixel);
  347. const pixel * const src0 = src +7-stride;
  348. const pixel * src1 = src +8*stride-1;
  349. const pixel * src2 = src1-2*stride; // == src+6*stride-1;
  350. int H = src0[1] - src0[-1];
  351. int V = src1[0] - src2[ 0];
  352. for(k=2; k<=8; ++k) {
  353. src1 += stride; src2 -= stride;
  354. H += k*(src0[k] - src0[-k]);
  355. V += k*(src1[0] - src2[ 0]);
  356. }
  357. if(svq3){
  358. H = ( 5*(H/4) ) / 16;
  359. V = ( 5*(V/4) ) / 16;
  360. /* required for 100% accuracy */
  361. i = H; H = V; V = i;
  362. }else if(rv40){
  363. H = ( H + (H>>2) ) >> 4;
  364. V = ( V + (V>>2) ) >> 4;
  365. }else{
  366. H = ( 5*H+32 ) >> 6;
  367. V = ( 5*V+32 ) >> 6;
  368. }
  369. a = 16*(src1[0] + src2[16] + 1) - 7*(V+H);
  370. for(j=16; j>0; --j) {
  371. int b = a;
  372. a += V;
  373. for(i=-16; i<0; i+=4) {
  374. src[16+i] = CLIP((b ) >> 5);
  375. src[17+i] = CLIP((b+ H) >> 5);
  376. src[18+i] = CLIP((b+2*H) >> 5);
  377. src[19+i] = CLIP((b+3*H) >> 5);
  378. b += 4*H;
  379. }
  380. src += stride;
  381. }
  382. }
  383. static void FUNCC(pred16x16_plane)(uint8_t *src, int stride){
  384. FUNCC(pred16x16_plane_compat)(src, stride, 0, 0);
  385. }
  386. static void FUNCC(pred8x8_vertical)(uint8_t *_src, int _stride){
  387. int i;
  388. pixel *src = (pixel*)_src;
  389. int stride = _stride/sizeof(pixel);
  390. const pixel4 a= AV_RN4PA(((pixel4*)(src-stride))+0);
  391. const pixel4 b= AV_RN4PA(((pixel4*)(src-stride))+1);
  392. for(i=0; i<8; i++){
  393. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
  394. AV_WN4PA(((pixel4*)(src+i*stride))+1, b);
  395. }
  396. }
  397. static void FUNCC(pred8x8_horizontal)(uint8_t *_src, int stride){
  398. int i;
  399. pixel *src = (pixel*)_src;
  400. stride /= sizeof(pixel);
  401. for(i=0; i<8; i++){
  402. const pixel4 a = PIXEL_SPLAT_X4(src[-1+i*stride]);
  403. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
  404. AV_WN4PA(((pixel4*)(src+i*stride))+1, a);
  405. }
  406. }
  407. #define PRED8x8_X(n, v)\
  408. static void FUNCC(pred8x8_##n##_dc)(uint8_t *_src, int stride){\
  409. int i;\
  410. const pixel4 a = PIXEL_SPLAT_X4(v);\
  411. pixel *src = (pixel*)_src;\
  412. stride /= sizeof(pixel);\
  413. for(i=0; i<8; i++){\
  414. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);\
  415. AV_WN4PA(((pixel4*)(src+i*stride))+1, a);\
  416. }\
  417. }
  418. PRED8x8_X(127, (1<<(BIT_DEPTH-1))-1);
  419. PRED8x8_X(128, (1<<(BIT_DEPTH-1))+0);
  420. PRED8x8_X(129, (1<<(BIT_DEPTH-1))+1);
  421. static void FUNCC(pred8x8_left_dc)(uint8_t *_src, int stride){
  422. int i;
  423. int dc0, dc2;
  424. pixel4 dc0splat, dc2splat;
  425. pixel *src = (pixel*)_src;
  426. stride /= sizeof(pixel);
  427. dc0=dc2=0;
  428. for(i=0;i<4; i++){
  429. dc0+= src[-1+i*stride];
  430. dc2+= src[-1+(i+4)*stride];
  431. }
  432. dc0splat = PIXEL_SPLAT_X4((dc0 + 2)>>2);
  433. dc2splat = PIXEL_SPLAT_X4((dc2 + 2)>>2);
  434. for(i=0; i<4; i++){
  435. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
  436. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc0splat);
  437. }
  438. for(i=4; i<8; i++){
  439. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc2splat);
  440. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc2splat);
  441. }
  442. }
  443. static void FUNCC(pred8x8_top_dc)(uint8_t *_src, int stride){
  444. int i;
  445. int dc0, dc1;
  446. pixel4 dc0splat, dc1splat;
  447. pixel *src = (pixel*)_src;
  448. stride /= sizeof(pixel);
  449. dc0=dc1=0;
  450. for(i=0;i<4; i++){
  451. dc0+= src[i-stride];
  452. dc1+= src[4+i-stride];
  453. }
  454. dc0splat = PIXEL_SPLAT_X4((dc0 + 2)>>2);
  455. dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2);
  456. for(i=0; i<4; i++){
  457. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
  458. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
  459. }
  460. for(i=4; i<8; i++){
  461. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
  462. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
  463. }
  464. }
  465. static void FUNCC(pred8x8_dc)(uint8_t *_src, int stride){
  466. int i;
  467. int dc0, dc1, dc2;
  468. pixel4 dc0splat, dc1splat, dc2splat, dc3splat;
  469. pixel *src = (pixel*)_src;
  470. stride /= sizeof(pixel);
  471. dc0=dc1=dc2=0;
  472. for(i=0;i<4; i++){
  473. dc0+= src[-1+i*stride] + src[i-stride];
  474. dc1+= src[4+i-stride];
  475. dc2+= src[-1+(i+4)*stride];
  476. }
  477. dc0splat = PIXEL_SPLAT_X4((dc0 + 4)>>3);
  478. dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2);
  479. dc2splat = PIXEL_SPLAT_X4((dc2 + 2)>>2);
  480. dc3splat = PIXEL_SPLAT_X4((dc1 + dc2 + 4)>>3);
  481. for(i=0; i<4; i++){
  482. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
  483. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
  484. }
  485. for(i=4; i<8; i++){
  486. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc2splat);
  487. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc3splat);
  488. }
  489. }
  490. //the following 4 function should not be optimized!
  491. static void FUNC(pred8x8_mad_cow_dc_l0t)(uint8_t *src, int stride){
  492. FUNCC(pred8x8_top_dc)(src, stride);
  493. FUNCC(pred4x4_dc)(src, NULL, stride);
  494. }
  495. static void FUNC(pred8x8_mad_cow_dc_0lt)(uint8_t *src, int stride){
  496. FUNCC(pred8x8_dc)(src, stride);
  497. FUNCC(pred4x4_top_dc)(src, NULL, stride);
  498. }
  499. static void FUNC(pred8x8_mad_cow_dc_l00)(uint8_t *src, int stride){
  500. FUNCC(pred8x8_left_dc)(src, stride);
  501. FUNCC(pred4x4_128_dc)(src + 4*stride , NULL, stride);
  502. FUNCC(pred4x4_128_dc)(src + 4*stride + 4*sizeof(pixel), NULL, stride);
  503. }
  504. static void FUNC(pred8x8_mad_cow_dc_0l0)(uint8_t *src, int stride){
  505. FUNCC(pred8x8_left_dc)(src, stride);
  506. FUNCC(pred4x4_128_dc)(src , NULL, stride);
  507. FUNCC(pred4x4_128_dc)(src + 4*sizeof(pixel), NULL, stride);
  508. }
  509. static void FUNCC(pred8x8_plane)(uint8_t *_src, int _stride){
  510. int j, k;
  511. int a;
  512. INIT_CLIP
  513. pixel *src = (pixel*)_src;
  514. int stride = _stride/sizeof(pixel);
  515. const pixel * const src0 = src +3-stride;
  516. const pixel * src1 = src +4*stride-1;
  517. const pixel * src2 = src1-2*stride; // == src+2*stride-1;
  518. int H = src0[1] - src0[-1];
  519. int V = src1[0] - src2[ 0];
  520. for(k=2; k<=4; ++k) {
  521. src1 += stride; src2 -= stride;
  522. H += k*(src0[k] - src0[-k]);
  523. V += k*(src1[0] - src2[ 0]);
  524. }
  525. H = ( 17*H+16 ) >> 5;
  526. V = ( 17*V+16 ) >> 5;
  527. a = 16*(src1[0] + src2[8]+1) - 3*(V+H);
  528. for(j=8; j>0; --j) {
  529. int b = a;
  530. a += V;
  531. src[0] = CLIP((b ) >> 5);
  532. src[1] = CLIP((b+ H) >> 5);
  533. src[2] = CLIP((b+2*H) >> 5);
  534. src[3] = CLIP((b+3*H) >> 5);
  535. src[4] = CLIP((b+4*H) >> 5);
  536. src[5] = CLIP((b+5*H) >> 5);
  537. src[6] = CLIP((b+6*H) >> 5);
  538. src[7] = CLIP((b+7*H) >> 5);
  539. src += stride;
  540. }
  541. }
  542. #define SRC(x,y) src[(x)+(y)*stride]
  543. #define PL(y) \
  544. const int l##y = (SRC(-1,y-1) + 2*SRC(-1,y) + SRC(-1,y+1) + 2) >> 2;
  545. #define PREDICT_8x8_LOAD_LEFT \
  546. const int l0 = ((has_topleft ? SRC(-1,-1) : SRC(-1,0)) \
  547. + 2*SRC(-1,0) + SRC(-1,1) + 2) >> 2; \
  548. PL(1) PL(2) PL(3) PL(4) PL(5) PL(6) \
  549. const int l7 av_unused = (SRC(-1,6) + 3*SRC(-1,7) + 2) >> 2
  550. #define PT(x) \
  551. const int t##x = (SRC(x-1,-1) + 2*SRC(x,-1) + SRC(x+1,-1) + 2) >> 2;
  552. #define PREDICT_8x8_LOAD_TOP \
  553. const int t0 = ((has_topleft ? SRC(-1,-1) : SRC(0,-1)) \
  554. + 2*SRC(0,-1) + SRC(1,-1) + 2) >> 2; \
  555. PT(1) PT(2) PT(3) PT(4) PT(5) PT(6) \
  556. const int t7 av_unused = ((has_topright ? SRC(8,-1) : SRC(7,-1)) \
  557. + 2*SRC(7,-1) + SRC(6,-1) + 2) >> 2
  558. #define PTR(x) \
  559. t##x = (SRC(x-1,-1) + 2*SRC(x,-1) + SRC(x+1,-1) + 2) >> 2;
  560. #define PREDICT_8x8_LOAD_TOPRIGHT \
  561. int t8, t9, t10, t11, t12, t13, t14, t15; \
  562. if(has_topright) { \
  563. PTR(8) PTR(9) PTR(10) PTR(11) PTR(12) PTR(13) PTR(14) \
  564. t15 = (SRC(14,-1) + 3*SRC(15,-1) + 2) >> 2; \
  565. } else t8=t9=t10=t11=t12=t13=t14=t15= SRC(7,-1);
  566. #define PREDICT_8x8_LOAD_TOPLEFT \
  567. const int lt = (SRC(-1,0) + 2*SRC(-1,-1) + SRC(0,-1) + 2) >> 2
  568. #define PREDICT_8x8_DC(v) \
  569. int y; \
  570. for( y = 0; y < 8; y++ ) { \
  571. AV_WN4PA(((pixel4*)src)+0, v); \
  572. AV_WN4PA(((pixel4*)src)+1, v); \
  573. src += stride; \
  574. }
  575. static void FUNCC(pred8x8l_128_dc)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
  576. {
  577. pixel *src = (pixel*)_src;
  578. int stride = _stride/sizeof(pixel);
  579. PREDICT_8x8_DC(PIXEL_SPLAT_X4(1<<(BIT_DEPTH-1)));
  580. }
  581. static void FUNCC(pred8x8l_left_dc)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
  582. {
  583. pixel *src = (pixel*)_src;
  584. int stride = _stride/sizeof(pixel);
  585. PREDICT_8x8_LOAD_LEFT;
  586. const pixel4 dc = PIXEL_SPLAT_X4((l0+l1+l2+l3+l4+l5+l6+l7+4) >> 3);
  587. PREDICT_8x8_DC(dc);
  588. }
  589. static void FUNCC(pred8x8l_top_dc)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
  590. {
  591. pixel *src = (pixel*)_src;
  592. int stride = _stride/sizeof(pixel);
  593. PREDICT_8x8_LOAD_TOP;
  594. const pixel4 dc = PIXEL_SPLAT_X4((t0+t1+t2+t3+t4+t5+t6+t7+4) >> 3);
  595. PREDICT_8x8_DC(dc);
  596. }
  597. static void FUNCC(pred8x8l_dc)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
  598. {
  599. pixel *src = (pixel*)_src;
  600. int stride = _stride/sizeof(pixel);
  601. PREDICT_8x8_LOAD_LEFT;
  602. PREDICT_8x8_LOAD_TOP;
  603. const pixel4 dc = PIXEL_SPLAT_X4((l0+l1+l2+l3+l4+l5+l6+l7
  604. +t0+t1+t2+t3+t4+t5+t6+t7+8) >> 4);
  605. PREDICT_8x8_DC(dc);
  606. }
  607. static void FUNCC(pred8x8l_horizontal)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
  608. {
  609. pixel *src = (pixel*)_src;
  610. int stride = _stride/sizeof(pixel);
  611. pixel4 a;
  612. PREDICT_8x8_LOAD_LEFT;
  613. #define ROW(y) a = PIXEL_SPLAT_X4(l##y); \
  614. AV_WN4PA(src+y*stride, a); \
  615. AV_WN4PA(src+y*stride+4, a);
  616. ROW(0); ROW(1); ROW(2); ROW(3); ROW(4); ROW(5); ROW(6); ROW(7);
  617. #undef ROW
  618. }
  619. static void FUNCC(pred8x8l_vertical)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
  620. {
  621. int y;
  622. pixel *src = (pixel*)_src;
  623. int stride = _stride/sizeof(pixel);
  624. pixel4 a, b;
  625. PREDICT_8x8_LOAD_TOP;
  626. src[0] = t0;
  627. src[1] = t1;
  628. src[2] = t2;
  629. src[3] = t3;
  630. src[4] = t4;
  631. src[5] = t5;
  632. src[6] = t6;
  633. src[7] = t7;
  634. a = AV_RN4PA(((pixel4*)src)+0);
  635. b = AV_RN4PA(((pixel4*)src)+1);
  636. for( y = 1; y < 8; y++ ) {
  637. AV_WN4PA(((pixel4*)(src+y*stride))+0, a);
  638. AV_WN4PA(((pixel4*)(src+y*stride))+1, b);
  639. }
  640. }
  641. static void FUNCC(pred8x8l_down_left)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
  642. {
  643. pixel *src = (pixel*)_src;
  644. int stride = _stride/sizeof(pixel);
  645. PREDICT_8x8_LOAD_TOP;
  646. PREDICT_8x8_LOAD_TOPRIGHT;
  647. SRC(0,0)= (t0 + 2*t1 + t2 + 2) >> 2;
  648. SRC(0,1)=SRC(1,0)= (t1 + 2*t2 + t3 + 2) >> 2;
  649. SRC(0,2)=SRC(1,1)=SRC(2,0)= (t2 + 2*t3 + t4 + 2) >> 2;
  650. SRC(0,3)=SRC(1,2)=SRC(2,1)=SRC(3,0)= (t3 + 2*t4 + t5 + 2) >> 2;
  651. SRC(0,4)=SRC(1,3)=SRC(2,2)=SRC(3,1)=SRC(4,0)= (t4 + 2*t5 + t6 + 2) >> 2;
  652. SRC(0,5)=SRC(1,4)=SRC(2,3)=SRC(3,2)=SRC(4,1)=SRC(5,0)= (t5 + 2*t6 + t7 + 2) >> 2;
  653. 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;
  654. 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;
  655. 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;
  656. SRC(2,7)=SRC(3,6)=SRC(4,5)=SRC(5,4)=SRC(6,3)=SRC(7,2)= (t9 + 2*t10 + t11 + 2) >> 2;
  657. SRC(3,7)=SRC(4,6)=SRC(5,5)=SRC(6,4)=SRC(7,3)= (t10 + 2*t11 + t12 + 2) >> 2;
  658. SRC(4,7)=SRC(5,6)=SRC(6,5)=SRC(7,4)= (t11 + 2*t12 + t13 + 2) >> 2;
  659. SRC(5,7)=SRC(6,6)=SRC(7,5)= (t12 + 2*t13 + t14 + 2) >> 2;
  660. SRC(6,7)=SRC(7,6)= (t13 + 2*t14 + t15 + 2) >> 2;
  661. SRC(7,7)= (t14 + 3*t15 + 2) >> 2;
  662. }
  663. static void FUNCC(pred8x8l_down_right)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
  664. {
  665. pixel *src = (pixel*)_src;
  666. int stride = _stride/sizeof(pixel);
  667. PREDICT_8x8_LOAD_TOP;
  668. PREDICT_8x8_LOAD_LEFT;
  669. PREDICT_8x8_LOAD_TOPLEFT;
  670. SRC(0,7)= (l7 + 2*l6 + l5 + 2) >> 2;
  671. SRC(0,6)=SRC(1,7)= (l6 + 2*l5 + l4 + 2) >> 2;
  672. SRC(0,5)=SRC(1,6)=SRC(2,7)= (l5 + 2*l4 + l3 + 2) >> 2;
  673. SRC(0,4)=SRC(1,5)=SRC(2,6)=SRC(3,7)= (l4 + 2*l3 + l2 + 2) >> 2;
  674. SRC(0,3)=SRC(1,4)=SRC(2,5)=SRC(3,6)=SRC(4,7)= (l3 + 2*l2 + l1 + 2) >> 2;
  675. SRC(0,2)=SRC(1,3)=SRC(2,4)=SRC(3,5)=SRC(4,6)=SRC(5,7)= (l2 + 2*l1 + l0 + 2) >> 2;
  676. 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;
  677. 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;
  678. 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;
  679. SRC(2,0)=SRC(3,1)=SRC(4,2)=SRC(5,3)=SRC(6,4)=SRC(7,5)= (t0 + 2*t1 + t2 + 2) >> 2;
  680. SRC(3,0)=SRC(4,1)=SRC(5,2)=SRC(6,3)=SRC(7,4)= (t1 + 2*t2 + t3 + 2) >> 2;
  681. SRC(4,0)=SRC(5,1)=SRC(6,2)=SRC(7,3)= (t2 + 2*t3 + t4 + 2) >> 2;
  682. SRC(5,0)=SRC(6,1)=SRC(7,2)= (t3 + 2*t4 + t5 + 2) >> 2;
  683. SRC(6,0)=SRC(7,1)= (t4 + 2*t5 + t6 + 2) >> 2;
  684. SRC(7,0)= (t5 + 2*t6 + t7 + 2) >> 2;
  685. }
  686. static void FUNCC(pred8x8l_vertical_right)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
  687. {
  688. pixel *src = (pixel*)_src;
  689. int stride = _stride/sizeof(pixel);
  690. PREDICT_8x8_LOAD_TOP;
  691. PREDICT_8x8_LOAD_LEFT;
  692. PREDICT_8x8_LOAD_TOPLEFT;
  693. SRC(0,6)= (l5 + 2*l4 + l3 + 2) >> 2;
  694. SRC(0,7)= (l6 + 2*l5 + l4 + 2) >> 2;
  695. SRC(0,4)=SRC(1,6)= (l3 + 2*l2 + l1 + 2) >> 2;
  696. SRC(0,5)=SRC(1,7)= (l4 + 2*l3 + l2 + 2) >> 2;
  697. SRC(0,2)=SRC(1,4)=SRC(2,6)= (l1 + 2*l0 + lt + 2) >> 2;
  698. SRC(0,3)=SRC(1,5)=SRC(2,7)= (l2 + 2*l1 + l0 + 2) >> 2;
  699. SRC(0,1)=SRC(1,3)=SRC(2,5)=SRC(3,7)= (l0 + 2*lt + t0 + 2) >> 2;
  700. SRC(0,0)=SRC(1,2)=SRC(2,4)=SRC(3,6)= (lt + t0 + 1) >> 1;
  701. SRC(1,1)=SRC(2,3)=SRC(3,5)=SRC(4,7)= (lt + 2*t0 + t1 + 2) >> 2;
  702. SRC(1,0)=SRC(2,2)=SRC(3,4)=SRC(4,6)= (t0 + t1 + 1) >> 1;
  703. SRC(2,1)=SRC(3,3)=SRC(4,5)=SRC(5,7)= (t0 + 2*t1 + t2 + 2) >> 2;
  704. SRC(2,0)=SRC(3,2)=SRC(4,4)=SRC(5,6)= (t1 + t2 + 1) >> 1;
  705. SRC(3,1)=SRC(4,3)=SRC(5,5)=SRC(6,7)= (t1 + 2*t2 + t3 + 2) >> 2;
  706. SRC(3,0)=SRC(4,2)=SRC(5,4)=SRC(6,6)= (t2 + t3 + 1) >> 1;
  707. SRC(4,1)=SRC(5,3)=SRC(6,5)=SRC(7,7)= (t2 + 2*t3 + t4 + 2) >> 2;
  708. SRC(4,0)=SRC(5,2)=SRC(6,4)=SRC(7,6)= (t3 + t4 + 1) >> 1;
  709. SRC(5,1)=SRC(6,3)=SRC(7,5)= (t3 + 2*t4 + t5 + 2) >> 2;
  710. SRC(5,0)=SRC(6,2)=SRC(7,4)= (t4 + t5 + 1) >> 1;
  711. SRC(6,1)=SRC(7,3)= (t4 + 2*t5 + t6 + 2) >> 2;
  712. SRC(6,0)=SRC(7,2)= (t5 + t6 + 1) >> 1;
  713. SRC(7,1)= (t5 + 2*t6 + t7 + 2) >> 2;
  714. SRC(7,0)= (t6 + t7 + 1) >> 1;
  715. }
  716. static void FUNCC(pred8x8l_horizontal_down)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
  717. {
  718. pixel *src = (pixel*)_src;
  719. int stride = _stride/sizeof(pixel);
  720. PREDICT_8x8_LOAD_TOP;
  721. PREDICT_8x8_LOAD_LEFT;
  722. PREDICT_8x8_LOAD_TOPLEFT;
  723. SRC(0,7)= (l6 + l7 + 1) >> 1;
  724. SRC(1,7)= (l5 + 2*l6 + l7 + 2) >> 2;
  725. SRC(0,6)=SRC(2,7)= (l5 + l6 + 1) >> 1;
  726. SRC(1,6)=SRC(3,7)= (l4 + 2*l5 + l6 + 2) >> 2;
  727. SRC(0,5)=SRC(2,6)=SRC(4,7)= (l4 + l5 + 1) >> 1;
  728. SRC(1,5)=SRC(3,6)=SRC(5,7)= (l3 + 2*l4 + l5 + 2) >> 2;
  729. SRC(0,4)=SRC(2,5)=SRC(4,6)=SRC(6,7)= (l3 + l4 + 1) >> 1;
  730. SRC(1,4)=SRC(3,5)=SRC(5,6)=SRC(7,7)= (l2 + 2*l3 + l4 + 2) >> 2;
  731. SRC(0,3)=SRC(2,4)=SRC(4,5)=SRC(6,6)= (l2 + l3 + 1) >> 1;
  732. SRC(1,3)=SRC(3,4)=SRC(5,5)=SRC(7,6)= (l1 + 2*l2 + l3 + 2) >> 2;
  733. SRC(0,2)=SRC(2,3)=SRC(4,4)=SRC(6,5)= (l1 + l2 + 1) >> 1;
  734. SRC(1,2)=SRC(3,3)=SRC(5,4)=SRC(7,5)= (l0 + 2*l1 + l2 + 2) >> 2;
  735. SRC(0,1)=SRC(2,2)=SRC(4,3)=SRC(6,4)= (l0 + l1 + 1) >> 1;
  736. SRC(1,1)=SRC(3,2)=SRC(5,3)=SRC(7,4)= (lt + 2*l0 + l1 + 2) >> 2;
  737. SRC(0,0)=SRC(2,1)=SRC(4,2)=SRC(6,3)= (lt + l0 + 1) >> 1;
  738. SRC(1,0)=SRC(3,1)=SRC(5,2)=SRC(7,3)= (l0 + 2*lt + t0 + 2) >> 2;
  739. SRC(2,0)=SRC(4,1)=SRC(6,2)= (t1 + 2*t0 + lt + 2) >> 2;
  740. SRC(3,0)=SRC(5,1)=SRC(7,2)= (t2 + 2*t1 + t0 + 2) >> 2;
  741. SRC(4,0)=SRC(6,1)= (t3 + 2*t2 + t1 + 2) >> 2;
  742. SRC(5,0)=SRC(7,1)= (t4 + 2*t3 + t2 + 2) >> 2;
  743. SRC(6,0)= (t5 + 2*t4 + t3 + 2) >> 2;
  744. SRC(7,0)= (t6 + 2*t5 + t4 + 2) >> 2;
  745. }
  746. static void FUNCC(pred8x8l_vertical_left)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
  747. {
  748. pixel *src = (pixel*)_src;
  749. int stride = _stride/sizeof(pixel);
  750. PREDICT_8x8_LOAD_TOP;
  751. PREDICT_8x8_LOAD_TOPRIGHT;
  752. SRC(0,0)= (t0 + t1 + 1) >> 1;
  753. SRC(0,1)= (t0 + 2*t1 + t2 + 2) >> 2;
  754. SRC(0,2)=SRC(1,0)= (t1 + t2 + 1) >> 1;
  755. SRC(0,3)=SRC(1,1)= (t1 + 2*t2 + t3 + 2) >> 2;
  756. SRC(0,4)=SRC(1,2)=SRC(2,0)= (t2 + t3 + 1) >> 1;
  757. SRC(0,5)=SRC(1,3)=SRC(2,1)= (t2 + 2*t3 + t4 + 2) >> 2;
  758. SRC(0,6)=SRC(1,4)=SRC(2,2)=SRC(3,0)= (t3 + t4 + 1) >> 1;
  759. SRC(0,7)=SRC(1,5)=SRC(2,3)=SRC(3,1)= (t3 + 2*t4 + t5 + 2) >> 2;
  760. SRC(1,6)=SRC(2,4)=SRC(3,2)=SRC(4,0)= (t4 + t5 + 1) >> 1;
  761. SRC(1,7)=SRC(2,5)=SRC(3,3)=SRC(4,1)= (t4 + 2*t5 + t6 + 2) >> 2;
  762. SRC(2,6)=SRC(3,4)=SRC(4,2)=SRC(5,0)= (t5 + t6 + 1) >> 1;
  763. SRC(2,7)=SRC(3,5)=SRC(4,3)=SRC(5,1)= (t5 + 2*t6 + t7 + 2) >> 2;
  764. SRC(3,6)=SRC(4,4)=SRC(5,2)=SRC(6,0)= (t6 + t7 + 1) >> 1;
  765. SRC(3,7)=SRC(4,5)=SRC(5,3)=SRC(6,1)= (t6 + 2*t7 + t8 + 2) >> 2;
  766. SRC(4,6)=SRC(5,4)=SRC(6,2)=SRC(7,0)= (t7 + t8 + 1) >> 1;
  767. SRC(4,7)=SRC(5,5)=SRC(6,3)=SRC(7,1)= (t7 + 2*t8 + t9 + 2) >> 2;
  768. SRC(5,6)=SRC(6,4)=SRC(7,2)= (t8 + t9 + 1) >> 1;
  769. SRC(5,7)=SRC(6,5)=SRC(7,3)= (t8 + 2*t9 + t10 + 2) >> 2;
  770. SRC(6,6)=SRC(7,4)= (t9 + t10 + 1) >> 1;
  771. SRC(6,7)=SRC(7,5)= (t9 + 2*t10 + t11 + 2) >> 2;
  772. SRC(7,6)= (t10 + t11 + 1) >> 1;
  773. SRC(7,7)= (t10 + 2*t11 + t12 + 2) >> 2;
  774. }
  775. static void FUNCC(pred8x8l_horizontal_up)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
  776. {
  777. pixel *src = (pixel*)_src;
  778. int stride = _stride/sizeof(pixel);
  779. PREDICT_8x8_LOAD_LEFT;
  780. SRC(0,0)= (l0 + l1 + 1) >> 1;
  781. SRC(1,0)= (l0 + 2*l1 + l2 + 2) >> 2;
  782. SRC(0,1)=SRC(2,0)= (l1 + l2 + 1) >> 1;
  783. SRC(1,1)=SRC(3,0)= (l1 + 2*l2 + l3 + 2) >> 2;
  784. SRC(0,2)=SRC(2,1)=SRC(4,0)= (l2 + l3 + 1) >> 1;
  785. SRC(1,2)=SRC(3,1)=SRC(5,0)= (l2 + 2*l3 + l4 + 2) >> 2;
  786. SRC(0,3)=SRC(2,2)=SRC(4,1)=SRC(6,0)= (l3 + l4 + 1) >> 1;
  787. SRC(1,3)=SRC(3,2)=SRC(5,1)=SRC(7,0)= (l3 + 2*l4 + l5 + 2) >> 2;
  788. SRC(0,4)=SRC(2,3)=SRC(4,2)=SRC(6,1)= (l4 + l5 + 1) >> 1;
  789. SRC(1,4)=SRC(3,3)=SRC(5,2)=SRC(7,1)= (l4 + 2*l5 + l6 + 2) >> 2;
  790. SRC(0,5)=SRC(2,4)=SRC(4,3)=SRC(6,2)= (l5 + l6 + 1) >> 1;
  791. SRC(1,5)=SRC(3,4)=SRC(5,3)=SRC(7,2)= (l5 + 2*l6 + l7 + 2) >> 2;
  792. SRC(0,6)=SRC(2,5)=SRC(4,4)=SRC(6,3)= (l6 + l7 + 1) >> 1;
  793. SRC(1,6)=SRC(3,5)=SRC(5,4)=SRC(7,3)= (l6 + 3*l7 + 2) >> 2;
  794. SRC(0,7)=SRC(1,7)=SRC(2,6)=SRC(2,7)=SRC(3,6)=
  795. SRC(3,7)=SRC(4,5)=SRC(4,6)=SRC(4,7)=SRC(5,5)=
  796. SRC(5,6)=SRC(5,7)=SRC(6,4)=SRC(6,5)=SRC(6,6)=
  797. SRC(6,7)=SRC(7,4)=SRC(7,5)=SRC(7,6)=SRC(7,7)= l7;
  798. }
  799. #undef PREDICT_8x8_LOAD_LEFT
  800. #undef PREDICT_8x8_LOAD_TOP
  801. #undef PREDICT_8x8_LOAD_TOPLEFT
  802. #undef PREDICT_8x8_LOAD_TOPRIGHT
  803. #undef PREDICT_8x8_DC
  804. #undef PTR
  805. #undef PT
  806. #undef PL
  807. #undef SRC
  808. static void FUNCC(pred4x4_vertical_add)(uint8_t *_pix, const DCTELEM *_block, int stride){
  809. int i;
  810. pixel *pix = (pixel*)_pix;
  811. const dctcoef *block = (const dctcoef*)_block;
  812. stride /= sizeof(pixel);
  813. pix -= stride;
  814. for(i=0; i<4; i++){
  815. pixel v = pix[0];
  816. pix[1*stride]= v += block[0];
  817. pix[2*stride]= v += block[4];
  818. pix[3*stride]= v += block[8];
  819. pix[4*stride]= v + block[12];
  820. pix++;
  821. block++;
  822. }
  823. }
  824. static void FUNCC(pred4x4_horizontal_add)(uint8_t *_pix, const DCTELEM *_block, int stride){
  825. int i;
  826. pixel *pix = (pixel*)_pix;
  827. const dctcoef *block = (const dctcoef*)_block;
  828. stride /= sizeof(pixel);
  829. for(i=0; i<4; i++){
  830. pixel v = pix[-1];
  831. pix[0]= v += block[0];
  832. pix[1]= v += block[1];
  833. pix[2]= v += block[2];
  834. pix[3]= v + block[3];
  835. pix+= stride;
  836. block+= 4;
  837. }
  838. }
  839. static void FUNCC(pred8x8l_vertical_add)(uint8_t *_pix, const DCTELEM *_block, int stride){
  840. int i;
  841. pixel *pix = (pixel*)_pix;
  842. const dctcoef *block = (const dctcoef*)_block;
  843. stride /= sizeof(pixel);
  844. pix -= stride;
  845. for(i=0; i<8; i++){
  846. pixel v = pix[0];
  847. pix[1*stride]= v += block[0];
  848. pix[2*stride]= v += block[8];
  849. pix[3*stride]= v += block[16];
  850. pix[4*stride]= v += block[24];
  851. pix[5*stride]= v += block[32];
  852. pix[6*stride]= v += block[40];
  853. pix[7*stride]= v += block[48];
  854. pix[8*stride]= v + block[56];
  855. pix++;
  856. block++;
  857. }
  858. }
  859. static void FUNCC(pred8x8l_horizontal_add)(uint8_t *_pix, const DCTELEM *_block, int stride){
  860. int i;
  861. pixel *pix = (pixel*)_pix;
  862. const dctcoef *block = (const dctcoef*)_block;
  863. stride /= sizeof(pixel);
  864. for(i=0; i<8; i++){
  865. pixel v = pix[-1];
  866. pix[0]= v += block[0];
  867. pix[1]= v += block[1];
  868. pix[2]= v += block[2];
  869. pix[3]= v += block[3];
  870. pix[4]= v += block[4];
  871. pix[5]= v += block[5];
  872. pix[6]= v += block[6];
  873. pix[7]= v + block[7];
  874. pix+= stride;
  875. block+= 8;
  876. }
  877. }
  878. static void FUNCC(pred16x16_vertical_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){
  879. int i;
  880. for(i=0; i<16; i++)
  881. FUNCC(pred4x4_vertical_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
  882. }
  883. static void FUNCC(pred16x16_horizontal_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){
  884. int i;
  885. for(i=0; i<16; i++)
  886. FUNCC(pred4x4_horizontal_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
  887. }
  888. static void FUNCC(pred8x8_vertical_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){
  889. int i;
  890. for(i=0; i<4; i++)
  891. FUNCC(pred4x4_vertical_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
  892. }
  893. static void FUNCC(pred8x8_horizontal_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){
  894. int i;
  895. for(i=0; i<4; i++)
  896. FUNCC(pred4x4_horizontal_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
  897. }