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.

976 lines
32KB

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