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.

1172 lines
39KB

  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, int _stride){
  29. pixel *src = (pixel*)_src;
  30. int stride = _stride>>(sizeof(pixel)-1);
  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)-1);
  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)-1);
  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)-1);
  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)-1);
  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)-1);
  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)-1);
  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)-1);
  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 unsigned av_unused t4 = topright[0];\
  105. const unsigned av_unused t5 = topright[1];\
  106. const unsigned av_unused t6 = topright[2];\
  107. const unsigned av_unused t7 = topright[3];\
  108. #define LOAD_DOWN_LEFT_EDGE\
  109. const unsigned av_unused l4 = src[-1+4*stride];\
  110. const unsigned av_unused l5 = src[-1+5*stride];\
  111. const unsigned av_unused l6 = src[-1+6*stride];\
  112. const unsigned av_unused l7 = src[-1+7*stride];\
  113. #define LOAD_LEFT_EDGE\
  114. const unsigned av_unused l0 = src[-1+0*stride];\
  115. const unsigned av_unused l1 = src[-1+1*stride];\
  116. const unsigned av_unused l2 = src[-1+2*stride];\
  117. const unsigned av_unused l3 = src[-1+3*stride];\
  118. #define LOAD_TOP_EDGE\
  119. const unsigned av_unused t0 = src[ 0-1*stride];\
  120. const unsigned av_unused t1 = src[ 1-1*stride];\
  121. const unsigned av_unused t2 = src[ 2-1*stride];\
  122. const unsigned 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)-1);
  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)-1);
  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)-1);
  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)-1);
  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)-1);
  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)-1);
  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)-1);
  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)-1;
  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)-1;
  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)-1;
  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)-1;
  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)-1;\
  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 *p_src, int p_stride, const int svq3, const int rv40){
  342. int i, j, k;
  343. int a;
  344. INIT_CLIP
  345. pixel *src = (pixel*)p_src;
  346. int stride = p_stride>>(sizeof(pixel)-1);
  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)-1);
  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(pred8x16_vertical)(uint8_t *_src, int _stride){
  398. int i;
  399. pixel *src = (pixel*)_src;
  400. int stride = _stride>>(sizeof(pixel)-1);
  401. const pixel4 a= AV_RN4PA(((pixel4*)(src-stride))+0);
  402. const pixel4 b= AV_RN4PA(((pixel4*)(src-stride))+1);
  403. for(i=0; i<16; i++){
  404. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
  405. AV_WN4PA(((pixel4*)(src+i*stride))+1, b);
  406. }
  407. }
  408. static void FUNCC(pred8x8_horizontal)(uint8_t *_src, int stride){
  409. int i;
  410. pixel *src = (pixel*)_src;
  411. stride >>= sizeof(pixel)-1;
  412. for(i=0; i<8; i++){
  413. const pixel4 a = PIXEL_SPLAT_X4(src[-1+i*stride]);
  414. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
  415. AV_WN4PA(((pixel4*)(src+i*stride))+1, a);
  416. }
  417. }
  418. static void FUNCC(pred8x16_horizontal)(uint8_t *_src, int stride){
  419. int i;
  420. pixel *src = (pixel*)_src;
  421. stride >>= sizeof(pixel)-1;
  422. for(i=0; i<16; i++){
  423. const pixel4 a = PIXEL_SPLAT_X4(src[-1+i*stride]);
  424. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);
  425. AV_WN4PA(((pixel4*)(src+i*stride))+1, a);
  426. }
  427. }
  428. #define PRED8x8_X(n, v)\
  429. static void FUNCC(pred8x8_##n##_dc)(uint8_t *_src, int stride){\
  430. int i;\
  431. const pixel4 a = PIXEL_SPLAT_X4(v);\
  432. pixel *src = (pixel*)_src;\
  433. stride >>= sizeof(pixel)-1;\
  434. for(i=0; i<8; i++){\
  435. AV_WN4PA(((pixel4*)(src+i*stride))+0, a);\
  436. AV_WN4PA(((pixel4*)(src+i*stride))+1, a);\
  437. }\
  438. }
  439. PRED8x8_X(127, (1<<(BIT_DEPTH-1))-1)
  440. PRED8x8_X(128, (1<<(BIT_DEPTH-1))+0)
  441. PRED8x8_X(129, (1<<(BIT_DEPTH-1))+1)
  442. static void FUNCC(pred8x16_128_dc)(uint8_t *_src, int stride){
  443. FUNCC(pred8x8_128_dc)(_src, stride);
  444. FUNCC(pred8x8_128_dc)(_src+8*stride, stride);
  445. }
  446. static void FUNCC(pred8x8_left_dc)(uint8_t *_src, int stride){
  447. int i;
  448. int dc0, dc2;
  449. pixel4 dc0splat, dc2splat;
  450. pixel *src = (pixel*)_src;
  451. stride >>= sizeof(pixel)-1;
  452. dc0=dc2=0;
  453. for(i=0;i<4; i++){
  454. dc0+= src[-1+i*stride];
  455. dc2+= src[-1+(i+4)*stride];
  456. }
  457. dc0splat = PIXEL_SPLAT_X4((dc0 + 2)>>2);
  458. dc2splat = PIXEL_SPLAT_X4((dc2 + 2)>>2);
  459. for(i=0; i<4; i++){
  460. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
  461. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc0splat);
  462. }
  463. for(i=4; i<8; i++){
  464. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc2splat);
  465. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc2splat);
  466. }
  467. }
  468. static void FUNCC(pred8x16_left_dc)(uint8_t *_src, int stride){
  469. FUNCC(pred8x8_left_dc)(_src, stride);
  470. FUNCC(pred8x8_left_dc)(_src+8*stride, stride);
  471. }
  472. static void FUNCC(pred8x8_top_dc)(uint8_t *_src, int stride){
  473. int i;
  474. int dc0, dc1;
  475. pixel4 dc0splat, dc1splat;
  476. pixel *src = (pixel*)_src;
  477. stride >>= sizeof(pixel)-1;
  478. dc0=dc1=0;
  479. for(i=0;i<4; i++){
  480. dc0+= src[i-stride];
  481. dc1+= src[4+i-stride];
  482. }
  483. dc0splat = PIXEL_SPLAT_X4((dc0 + 2)>>2);
  484. dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2);
  485. for(i=0; i<4; i++){
  486. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
  487. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
  488. }
  489. for(i=4; i<8; i++){
  490. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
  491. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
  492. }
  493. }
  494. static void FUNCC(pred8x16_top_dc)(uint8_t *_src, int stride){
  495. int i;
  496. int dc0, dc1;
  497. pixel4 dc0splat, dc1splat;
  498. pixel *src = (pixel*)_src;
  499. stride >>= sizeof(pixel)-1;
  500. dc0=dc1=0;
  501. for(i=0;i<4; i++){
  502. dc0+= src[i-stride];
  503. dc1+= src[4+i-stride];
  504. }
  505. dc0splat = PIXEL_SPLAT_X4((dc0 + 2)>>2);
  506. dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2);
  507. for(i=0; i<16; i++){
  508. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
  509. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
  510. }
  511. }
  512. static void FUNCC(pred8x8_dc)(uint8_t *_src, int stride){
  513. int i;
  514. int dc0, dc1, dc2;
  515. pixel4 dc0splat, dc1splat, dc2splat, dc3splat;
  516. pixel *src = (pixel*)_src;
  517. stride >>= sizeof(pixel)-1;
  518. dc0=dc1=dc2=0;
  519. for(i=0;i<4; i++){
  520. dc0+= src[-1+i*stride] + src[i-stride];
  521. dc1+= src[4+i-stride];
  522. dc2+= src[-1+(i+4)*stride];
  523. }
  524. dc0splat = PIXEL_SPLAT_X4((dc0 + 4)>>3);
  525. dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2);
  526. dc2splat = PIXEL_SPLAT_X4((dc2 + 2)>>2);
  527. dc3splat = PIXEL_SPLAT_X4((dc1 + dc2 + 4)>>3);
  528. for(i=0; i<4; i++){
  529. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
  530. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
  531. }
  532. for(i=4; i<8; i++){
  533. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc2splat);
  534. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc3splat);
  535. }
  536. }
  537. static void FUNCC(pred8x16_dc)(uint8_t *_src, int stride){
  538. int i;
  539. int dc0, dc1, dc2, dc3, dc4;
  540. pixel4 dc0splat, dc1splat, dc2splat, dc3splat, dc4splat, dc5splat, dc6splat, dc7splat;
  541. pixel *src = (pixel*)_src;
  542. stride >>= sizeof(pixel)-1;
  543. dc0=dc1=dc2=dc3=dc4=0;
  544. for(i=0;i<4; i++){
  545. dc0+= src[-1+i*stride] + src[i-stride];
  546. dc1+= src[4+i-stride];
  547. dc2+= src[-1+(i+4)*stride];
  548. dc3+= src[-1+(i+8)*stride];
  549. dc4+= src[-1+(i+12)*stride];
  550. }
  551. dc0splat = PIXEL_SPLAT_X4((dc0 + 4)>>3);
  552. dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2);
  553. dc2splat = PIXEL_SPLAT_X4((dc2 + 2)>>2);
  554. dc3splat = PIXEL_SPLAT_X4((dc1 + dc2 + 4)>>3);
  555. dc4splat = PIXEL_SPLAT_X4((dc3 + 2)>>2);
  556. dc5splat = PIXEL_SPLAT_X4((dc1 + dc3 + 4)>>3);
  557. dc6splat = PIXEL_SPLAT_X4((dc4 + 2)>>2);
  558. dc7splat = PIXEL_SPLAT_X4((dc1 + dc4 + 4)>>3);
  559. for(i=0; i<4; i++){
  560. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat);
  561. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat);
  562. }
  563. for(i=4; i<8; i++){
  564. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc2splat);
  565. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc3splat);
  566. }
  567. for(i=8; i<12; i++){
  568. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc4splat);
  569. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc5splat);
  570. }
  571. for(i=12; i<16; i++){
  572. AV_WN4PA(((pixel4*)(src+i*stride))+0, dc6splat);
  573. AV_WN4PA(((pixel4*)(src+i*stride))+1, dc7splat);
  574. }
  575. }
  576. //the following 4 function should not be optimized!
  577. static void FUNC(pred8x8_mad_cow_dc_l0t)(uint8_t *src, int stride){
  578. FUNCC(pred8x8_top_dc)(src, stride);
  579. FUNCC(pred4x4_dc)(src, NULL, stride);
  580. }
  581. static void FUNC(pred8x16_mad_cow_dc_l0t)(uint8_t *src, int stride){
  582. FUNCC(pred8x16_top_dc)(src, stride);
  583. FUNCC(pred4x4_dc)(src, NULL, stride);
  584. }
  585. static void FUNC(pred8x8_mad_cow_dc_0lt)(uint8_t *src, int stride){
  586. FUNCC(pred8x8_dc)(src, stride);
  587. FUNCC(pred4x4_top_dc)(src, NULL, stride);
  588. }
  589. static void FUNC(pred8x16_mad_cow_dc_0lt)(uint8_t *src, int stride){
  590. FUNCC(pred8x16_dc)(src, stride);
  591. FUNCC(pred4x4_top_dc)(src, NULL, stride);
  592. }
  593. static void FUNC(pred8x8_mad_cow_dc_l00)(uint8_t *src, int stride){
  594. FUNCC(pred8x8_left_dc)(src, stride);
  595. FUNCC(pred4x4_128_dc)(src + 4*stride , NULL, stride);
  596. FUNCC(pred4x4_128_dc)(src + 4*stride + 4*sizeof(pixel), NULL, stride);
  597. }
  598. static void FUNC(pred8x16_mad_cow_dc_l00)(uint8_t *src, int stride){
  599. FUNCC(pred8x16_left_dc)(src, stride);
  600. FUNCC(pred4x4_128_dc)(src + 4*stride , NULL, stride);
  601. FUNCC(pred4x4_128_dc)(src + 4*stride + 4*sizeof(pixel), NULL, stride);
  602. }
  603. static void FUNC(pred8x8_mad_cow_dc_0l0)(uint8_t *src, int stride){
  604. FUNCC(pred8x8_left_dc)(src, stride);
  605. FUNCC(pred4x4_128_dc)(src , NULL, stride);
  606. FUNCC(pred4x4_128_dc)(src + 4*sizeof(pixel), NULL, stride);
  607. }
  608. static void FUNC(pred8x16_mad_cow_dc_0l0)(uint8_t *src, int stride){
  609. FUNCC(pred8x16_left_dc)(src, stride);
  610. FUNCC(pred4x4_128_dc)(src , NULL, stride);
  611. FUNCC(pred4x4_128_dc)(src + 4*sizeof(pixel), NULL, stride);
  612. }
  613. static void FUNCC(pred8x8_plane)(uint8_t *_src, int _stride){
  614. int j, k;
  615. int a;
  616. INIT_CLIP
  617. pixel *src = (pixel*)_src;
  618. int stride = _stride>>(sizeof(pixel)-1);
  619. const pixel * const src0 = src +3-stride;
  620. const pixel * src1 = src +4*stride-1;
  621. const pixel * src2 = src1-2*stride; // == src+2*stride-1;
  622. int H = src0[1] - src0[-1];
  623. int V = src1[0] - src2[ 0];
  624. for(k=2; k<=4; ++k) {
  625. src1 += stride; src2 -= stride;
  626. H += k*(src0[k] - src0[-k]);
  627. V += k*(src1[0] - src2[ 0]);
  628. }
  629. H = ( 17*H+16 ) >> 5;
  630. V = ( 17*V+16 ) >> 5;
  631. a = 16*(src1[0] + src2[8]+1) - 3*(V+H);
  632. for(j=8; j>0; --j) {
  633. int b = a;
  634. a += V;
  635. src[0] = CLIP((b ) >> 5);
  636. src[1] = CLIP((b+ H) >> 5);
  637. src[2] = CLIP((b+2*H) >> 5);
  638. src[3] = CLIP((b+3*H) >> 5);
  639. src[4] = CLIP((b+4*H) >> 5);
  640. src[5] = CLIP((b+5*H) >> 5);
  641. src[6] = CLIP((b+6*H) >> 5);
  642. src[7] = CLIP((b+7*H) >> 5);
  643. src += stride;
  644. }
  645. }
  646. static void FUNCC(pred8x16_plane)(uint8_t *_src, int _stride){
  647. int j, k;
  648. int a;
  649. INIT_CLIP
  650. pixel *src = (pixel*)_src;
  651. int stride = _stride>>(sizeof(pixel)-1);
  652. const pixel * const src0 = src +3-stride;
  653. const pixel * src1 = src +8*stride-1;
  654. const pixel * src2 = src1-2*stride; // == src+6*stride-1;
  655. int H = src0[1] - src0[-1];
  656. int V = src1[0] - src2[ 0];
  657. for (k = 2; k <= 4; ++k) {
  658. src1 += stride; src2 -= stride;
  659. H += k*(src0[k] - src0[-k]);
  660. V += k*(src1[0] - src2[ 0]);
  661. }
  662. for (; k <= 8; ++k) {
  663. src1 += stride; src2 -= stride;
  664. V += k*(src1[0] - src2[0]);
  665. }
  666. H = (17*H+16) >> 5;
  667. V = (5*V+32) >> 6;
  668. a = 16*(src1[0] + src2[8] + 1) - 7*V - 3*H;
  669. for(j=16; j>0; --j) {
  670. int b = a;
  671. a += V;
  672. src[0] = CLIP((b ) >> 5);
  673. src[1] = CLIP((b+ H) >> 5);
  674. src[2] = CLIP((b+2*H) >> 5);
  675. src[3] = CLIP((b+3*H) >> 5);
  676. src[4] = CLIP((b+4*H) >> 5);
  677. src[5] = CLIP((b+5*H) >> 5);
  678. src[6] = CLIP((b+6*H) >> 5);
  679. src[7] = CLIP((b+7*H) >> 5);
  680. src += stride;
  681. }
  682. }
  683. #define SRC(x,y) src[(x)+(y)*stride]
  684. #define PL(y) \
  685. const int l##y = (SRC(-1,y-1) + 2*SRC(-1,y) + SRC(-1,y+1) + 2) >> 2;
  686. #define PREDICT_8x8_LOAD_LEFT \
  687. const int l0 = ((has_topleft ? SRC(-1,-1) : SRC(-1,0)) \
  688. + 2*SRC(-1,0) + SRC(-1,1) + 2) >> 2; \
  689. PL(1) PL(2) PL(3) PL(4) PL(5) PL(6) \
  690. const int l7 av_unused = (SRC(-1,6) + 3*SRC(-1,7) + 2) >> 2
  691. #define PT(x) \
  692. const int t##x = (SRC(x-1,-1) + 2*SRC(x,-1) + SRC(x+1,-1) + 2) >> 2;
  693. #define PREDICT_8x8_LOAD_TOP \
  694. const int t0 = ((has_topleft ? SRC(-1,-1) : SRC(0,-1)) \
  695. + 2*SRC(0,-1) + SRC(1,-1) + 2) >> 2; \
  696. PT(1) PT(2) PT(3) PT(4) PT(5) PT(6) \
  697. const int t7 av_unused = ((has_topright ? SRC(8,-1) : SRC(7,-1)) \
  698. + 2*SRC(7,-1) + SRC(6,-1) + 2) >> 2
  699. #define PTR(x) \
  700. t##x = (SRC(x-1,-1) + 2*SRC(x,-1) + SRC(x+1,-1) + 2) >> 2;
  701. #define PREDICT_8x8_LOAD_TOPRIGHT \
  702. int t8, t9, t10, t11, t12, t13, t14, t15; \
  703. if(has_topright) { \
  704. PTR(8) PTR(9) PTR(10) PTR(11) PTR(12) PTR(13) PTR(14) \
  705. t15 = (SRC(14,-1) + 3*SRC(15,-1) + 2) >> 2; \
  706. } else t8=t9=t10=t11=t12=t13=t14=t15= SRC(7,-1);
  707. #define PREDICT_8x8_LOAD_TOPLEFT \
  708. const int lt = (SRC(-1,0) + 2*SRC(-1,-1) + SRC(0,-1) + 2) >> 2
  709. #define PREDICT_8x8_DC(v) \
  710. int y; \
  711. for( y = 0; y < 8; y++ ) { \
  712. AV_WN4PA(((pixel4*)src)+0, v); \
  713. AV_WN4PA(((pixel4*)src)+1, v); \
  714. src += stride; \
  715. }
  716. static void FUNCC(pred8x8l_128_dc)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
  717. {
  718. pixel *src = (pixel*)_src;
  719. int stride = _stride>>(sizeof(pixel)-1);
  720. PREDICT_8x8_DC(PIXEL_SPLAT_X4(1<<(BIT_DEPTH-1)));
  721. }
  722. static void FUNCC(pred8x8l_left_dc)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
  723. {
  724. pixel *src = (pixel*)_src;
  725. int stride = _stride>>(sizeof(pixel)-1);
  726. PREDICT_8x8_LOAD_LEFT;
  727. const pixel4 dc = PIXEL_SPLAT_X4((l0+l1+l2+l3+l4+l5+l6+l7+4) >> 3);
  728. PREDICT_8x8_DC(dc);
  729. }
  730. static void FUNCC(pred8x8l_top_dc)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride)
  731. {
  732. pixel *src = (pixel*)p_src;
  733. int stride = p_stride>>(sizeof(pixel)-1);
  734. PREDICT_8x8_LOAD_TOP;
  735. const pixel4 dc = PIXEL_SPLAT_X4((t0+t1+t2+t3+t4+t5+t6+t7+4) >> 3);
  736. PREDICT_8x8_DC(dc);
  737. }
  738. static void FUNCC(pred8x8l_dc)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride)
  739. {
  740. pixel *src = (pixel*)p_src;
  741. int stride = p_stride>>(sizeof(pixel)-1);
  742. PREDICT_8x8_LOAD_LEFT;
  743. PREDICT_8x8_LOAD_TOP;
  744. const pixel4 dc = PIXEL_SPLAT_X4((l0+l1+l2+l3+l4+l5+l6+l7
  745. +t0+t1+t2+t3+t4+t5+t6+t7+8) >> 4);
  746. PREDICT_8x8_DC(dc);
  747. }
  748. static void FUNCC(pred8x8l_horizontal)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride)
  749. {
  750. pixel *src = (pixel*)p_src;
  751. int stride = p_stride>>(sizeof(pixel)-1);
  752. pixel4 a;
  753. PREDICT_8x8_LOAD_LEFT;
  754. #define ROW(y) a = PIXEL_SPLAT_X4(l##y); \
  755. AV_WN4PA(src+y*stride, a); \
  756. AV_WN4PA(src+y*stride+4, a);
  757. ROW(0); ROW(1); ROW(2); ROW(3); ROW(4); ROW(5); ROW(6); ROW(7);
  758. #undef ROW
  759. }
  760. static void FUNCC(pred8x8l_vertical)(uint8_t *_src, int has_topleft, int has_topright, int _stride)
  761. {
  762. int y;
  763. pixel *src = (pixel*)_src;
  764. int stride = _stride>>(sizeof(pixel)-1);
  765. pixel4 a, b;
  766. PREDICT_8x8_LOAD_TOP;
  767. src[0] = t0;
  768. src[1] = t1;
  769. src[2] = t2;
  770. src[3] = t3;
  771. src[4] = t4;
  772. src[5] = t5;
  773. src[6] = t6;
  774. src[7] = t7;
  775. a = AV_RN4PA(((pixel4*)src)+0);
  776. b = AV_RN4PA(((pixel4*)src)+1);
  777. for( y = 1; y < 8; y++ ) {
  778. AV_WN4PA(((pixel4*)(src+y*stride))+0, a);
  779. AV_WN4PA(((pixel4*)(src+y*stride))+1, b);
  780. }
  781. }
  782. static void FUNCC(pred8x8l_down_left)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride)
  783. {
  784. pixel *src = (pixel*)p_src;
  785. int stride = p_stride>>(sizeof(pixel)-1);
  786. PREDICT_8x8_LOAD_TOP;
  787. PREDICT_8x8_LOAD_TOPRIGHT;
  788. SRC(0,0)= (t0 + 2*t1 + t2 + 2) >> 2;
  789. SRC(0,1)=SRC(1,0)= (t1 + 2*t2 + t3 + 2) >> 2;
  790. SRC(0,2)=SRC(1,1)=SRC(2,0)= (t2 + 2*t3 + t4 + 2) >> 2;
  791. SRC(0,3)=SRC(1,2)=SRC(2,1)=SRC(3,0)= (t3 + 2*t4 + t5 + 2) >> 2;
  792. SRC(0,4)=SRC(1,3)=SRC(2,2)=SRC(3,1)=SRC(4,0)= (t4 + 2*t5 + t6 + 2) >> 2;
  793. SRC(0,5)=SRC(1,4)=SRC(2,3)=SRC(3,2)=SRC(4,1)=SRC(5,0)= (t5 + 2*t6 + t7 + 2) >> 2;
  794. 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;
  795. 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;
  796. 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;
  797. SRC(2,7)=SRC(3,6)=SRC(4,5)=SRC(5,4)=SRC(6,3)=SRC(7,2)= (t9 + 2*t10 + t11 + 2) >> 2;
  798. SRC(3,7)=SRC(4,6)=SRC(5,5)=SRC(6,4)=SRC(7,3)= (t10 + 2*t11 + t12 + 2) >> 2;
  799. SRC(4,7)=SRC(5,6)=SRC(6,5)=SRC(7,4)= (t11 + 2*t12 + t13 + 2) >> 2;
  800. SRC(5,7)=SRC(6,6)=SRC(7,5)= (t12 + 2*t13 + t14 + 2) >> 2;
  801. SRC(6,7)=SRC(7,6)= (t13 + 2*t14 + t15 + 2) >> 2;
  802. SRC(7,7)= (t14 + 3*t15 + 2) >> 2;
  803. }
  804. static void FUNCC(pred8x8l_down_right)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride)
  805. {
  806. pixel *src = (pixel*)p_src;
  807. int stride = p_stride>>(sizeof(pixel)-1);
  808. PREDICT_8x8_LOAD_TOP;
  809. PREDICT_8x8_LOAD_LEFT;
  810. PREDICT_8x8_LOAD_TOPLEFT;
  811. SRC(0,7)= (l7 + 2*l6 + l5 + 2) >> 2;
  812. SRC(0,6)=SRC(1,7)= (l6 + 2*l5 + l4 + 2) >> 2;
  813. SRC(0,5)=SRC(1,6)=SRC(2,7)= (l5 + 2*l4 + l3 + 2) >> 2;
  814. SRC(0,4)=SRC(1,5)=SRC(2,6)=SRC(3,7)= (l4 + 2*l3 + l2 + 2) >> 2;
  815. SRC(0,3)=SRC(1,4)=SRC(2,5)=SRC(3,6)=SRC(4,7)= (l3 + 2*l2 + l1 + 2) >> 2;
  816. SRC(0,2)=SRC(1,3)=SRC(2,4)=SRC(3,5)=SRC(4,6)=SRC(5,7)= (l2 + 2*l1 + l0 + 2) >> 2;
  817. 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;
  818. 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;
  819. 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;
  820. SRC(2,0)=SRC(3,1)=SRC(4,2)=SRC(5,3)=SRC(6,4)=SRC(7,5)= (t0 + 2*t1 + t2 + 2) >> 2;
  821. SRC(3,0)=SRC(4,1)=SRC(5,2)=SRC(6,3)=SRC(7,4)= (t1 + 2*t2 + t3 + 2) >> 2;
  822. SRC(4,0)=SRC(5,1)=SRC(6,2)=SRC(7,3)= (t2 + 2*t3 + t4 + 2) >> 2;
  823. SRC(5,0)=SRC(6,1)=SRC(7,2)= (t3 + 2*t4 + t5 + 2) >> 2;
  824. SRC(6,0)=SRC(7,1)= (t4 + 2*t5 + t6 + 2) >> 2;
  825. SRC(7,0)= (t5 + 2*t6 + t7 + 2) >> 2;
  826. }
  827. static void FUNCC(pred8x8l_vertical_right)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride)
  828. {
  829. pixel *src = (pixel*)p_src;
  830. int stride = p_stride>>(sizeof(pixel)-1);
  831. PREDICT_8x8_LOAD_TOP;
  832. PREDICT_8x8_LOAD_LEFT;
  833. PREDICT_8x8_LOAD_TOPLEFT;
  834. SRC(0,6)= (l5 + 2*l4 + l3 + 2) >> 2;
  835. SRC(0,7)= (l6 + 2*l5 + l4 + 2) >> 2;
  836. SRC(0,4)=SRC(1,6)= (l3 + 2*l2 + l1 + 2) >> 2;
  837. SRC(0,5)=SRC(1,7)= (l4 + 2*l3 + l2 + 2) >> 2;
  838. SRC(0,2)=SRC(1,4)=SRC(2,6)= (l1 + 2*l0 + lt + 2) >> 2;
  839. SRC(0,3)=SRC(1,5)=SRC(2,7)= (l2 + 2*l1 + l0 + 2) >> 2;
  840. SRC(0,1)=SRC(1,3)=SRC(2,5)=SRC(3,7)= (l0 + 2*lt + t0 + 2) >> 2;
  841. SRC(0,0)=SRC(1,2)=SRC(2,4)=SRC(3,6)= (lt + t0 + 1) >> 1;
  842. SRC(1,1)=SRC(2,3)=SRC(3,5)=SRC(4,7)= (lt + 2*t0 + t1 + 2) >> 2;
  843. SRC(1,0)=SRC(2,2)=SRC(3,4)=SRC(4,6)= (t0 + t1 + 1) >> 1;
  844. SRC(2,1)=SRC(3,3)=SRC(4,5)=SRC(5,7)= (t0 + 2*t1 + t2 + 2) >> 2;
  845. SRC(2,0)=SRC(3,2)=SRC(4,4)=SRC(5,6)= (t1 + t2 + 1) >> 1;
  846. SRC(3,1)=SRC(4,3)=SRC(5,5)=SRC(6,7)= (t1 + 2*t2 + t3 + 2) >> 2;
  847. SRC(3,0)=SRC(4,2)=SRC(5,4)=SRC(6,6)= (t2 + t3 + 1) >> 1;
  848. SRC(4,1)=SRC(5,3)=SRC(6,5)=SRC(7,7)= (t2 + 2*t3 + t4 + 2) >> 2;
  849. SRC(4,0)=SRC(5,2)=SRC(6,4)=SRC(7,6)= (t3 + t4 + 1) >> 1;
  850. SRC(5,1)=SRC(6,3)=SRC(7,5)= (t3 + 2*t4 + t5 + 2) >> 2;
  851. SRC(5,0)=SRC(6,2)=SRC(7,4)= (t4 + t5 + 1) >> 1;
  852. SRC(6,1)=SRC(7,3)= (t4 + 2*t5 + t6 + 2) >> 2;
  853. SRC(6,0)=SRC(7,2)= (t5 + t6 + 1) >> 1;
  854. SRC(7,1)= (t5 + 2*t6 + t7 + 2) >> 2;
  855. SRC(7,0)= (t6 + t7 + 1) >> 1;
  856. }
  857. static void FUNCC(pred8x8l_horizontal_down)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride)
  858. {
  859. pixel *src = (pixel*)p_src;
  860. int stride = p_stride>>(sizeof(pixel)-1);
  861. PREDICT_8x8_LOAD_TOP;
  862. PREDICT_8x8_LOAD_LEFT;
  863. PREDICT_8x8_LOAD_TOPLEFT;
  864. SRC(0,7)= (l6 + l7 + 1) >> 1;
  865. SRC(1,7)= (l5 + 2*l6 + l7 + 2) >> 2;
  866. SRC(0,6)=SRC(2,7)= (l5 + l6 + 1) >> 1;
  867. SRC(1,6)=SRC(3,7)= (l4 + 2*l5 + l6 + 2) >> 2;
  868. SRC(0,5)=SRC(2,6)=SRC(4,7)= (l4 + l5 + 1) >> 1;
  869. SRC(1,5)=SRC(3,6)=SRC(5,7)= (l3 + 2*l4 + l5 + 2) >> 2;
  870. SRC(0,4)=SRC(2,5)=SRC(4,6)=SRC(6,7)= (l3 + l4 + 1) >> 1;
  871. SRC(1,4)=SRC(3,5)=SRC(5,6)=SRC(7,7)= (l2 + 2*l3 + l4 + 2) >> 2;
  872. SRC(0,3)=SRC(2,4)=SRC(4,5)=SRC(6,6)= (l2 + l3 + 1) >> 1;
  873. SRC(1,3)=SRC(3,4)=SRC(5,5)=SRC(7,6)= (l1 + 2*l2 + l3 + 2) >> 2;
  874. SRC(0,2)=SRC(2,3)=SRC(4,4)=SRC(6,5)= (l1 + l2 + 1) >> 1;
  875. SRC(1,2)=SRC(3,3)=SRC(5,4)=SRC(7,5)= (l0 + 2*l1 + l2 + 2) >> 2;
  876. SRC(0,1)=SRC(2,2)=SRC(4,3)=SRC(6,4)= (l0 + l1 + 1) >> 1;
  877. SRC(1,1)=SRC(3,2)=SRC(5,3)=SRC(7,4)= (lt + 2*l0 + l1 + 2) >> 2;
  878. SRC(0,0)=SRC(2,1)=SRC(4,2)=SRC(6,3)= (lt + l0 + 1) >> 1;
  879. SRC(1,0)=SRC(3,1)=SRC(5,2)=SRC(7,3)= (l0 + 2*lt + t0 + 2) >> 2;
  880. SRC(2,0)=SRC(4,1)=SRC(6,2)= (t1 + 2*t0 + lt + 2) >> 2;
  881. SRC(3,0)=SRC(5,1)=SRC(7,2)= (t2 + 2*t1 + t0 + 2) >> 2;
  882. SRC(4,0)=SRC(6,1)= (t3 + 2*t2 + t1 + 2) >> 2;
  883. SRC(5,0)=SRC(7,1)= (t4 + 2*t3 + t2 + 2) >> 2;
  884. SRC(6,0)= (t5 + 2*t4 + t3 + 2) >> 2;
  885. SRC(7,0)= (t6 + 2*t5 + t4 + 2) >> 2;
  886. }
  887. static void FUNCC(pred8x8l_vertical_left)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride)
  888. {
  889. pixel *src = (pixel*)p_src;
  890. int stride = p_stride>>(sizeof(pixel)-1);
  891. PREDICT_8x8_LOAD_TOP;
  892. PREDICT_8x8_LOAD_TOPRIGHT;
  893. SRC(0,0)= (t0 + t1 + 1) >> 1;
  894. SRC(0,1)= (t0 + 2*t1 + t2 + 2) >> 2;
  895. SRC(0,2)=SRC(1,0)= (t1 + t2 + 1) >> 1;
  896. SRC(0,3)=SRC(1,1)= (t1 + 2*t2 + t3 + 2) >> 2;
  897. SRC(0,4)=SRC(1,2)=SRC(2,0)= (t2 + t3 + 1) >> 1;
  898. SRC(0,5)=SRC(1,3)=SRC(2,1)= (t2 + 2*t3 + t4 + 2) >> 2;
  899. SRC(0,6)=SRC(1,4)=SRC(2,2)=SRC(3,0)= (t3 + t4 + 1) >> 1;
  900. SRC(0,7)=SRC(1,5)=SRC(2,3)=SRC(3,1)= (t3 + 2*t4 + t5 + 2) >> 2;
  901. SRC(1,6)=SRC(2,4)=SRC(3,2)=SRC(4,0)= (t4 + t5 + 1) >> 1;
  902. SRC(1,7)=SRC(2,5)=SRC(3,3)=SRC(4,1)= (t4 + 2*t5 + t6 + 2) >> 2;
  903. SRC(2,6)=SRC(3,4)=SRC(4,2)=SRC(5,0)= (t5 + t6 + 1) >> 1;
  904. SRC(2,7)=SRC(3,5)=SRC(4,3)=SRC(5,1)= (t5 + 2*t6 + t7 + 2) >> 2;
  905. SRC(3,6)=SRC(4,4)=SRC(5,2)=SRC(6,0)= (t6 + t7 + 1) >> 1;
  906. SRC(3,7)=SRC(4,5)=SRC(5,3)=SRC(6,1)= (t6 + 2*t7 + t8 + 2) >> 2;
  907. SRC(4,6)=SRC(5,4)=SRC(6,2)=SRC(7,0)= (t7 + t8 + 1) >> 1;
  908. SRC(4,7)=SRC(5,5)=SRC(6,3)=SRC(7,1)= (t7 + 2*t8 + t9 + 2) >> 2;
  909. SRC(5,6)=SRC(6,4)=SRC(7,2)= (t8 + t9 + 1) >> 1;
  910. SRC(5,7)=SRC(6,5)=SRC(7,3)= (t8 + 2*t9 + t10 + 2) >> 2;
  911. SRC(6,6)=SRC(7,4)= (t9 + t10 + 1) >> 1;
  912. SRC(6,7)=SRC(7,5)= (t9 + 2*t10 + t11 + 2) >> 2;
  913. SRC(7,6)= (t10 + t11 + 1) >> 1;
  914. SRC(7,7)= (t10 + 2*t11 + t12 + 2) >> 2;
  915. }
  916. static void FUNCC(pred8x8l_horizontal_up)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride)
  917. {
  918. pixel *src = (pixel*)p_src;
  919. int stride = p_stride>>(sizeof(pixel)-1);
  920. PREDICT_8x8_LOAD_LEFT;
  921. SRC(0,0)= (l0 + l1 + 1) >> 1;
  922. SRC(1,0)= (l0 + 2*l1 + l2 + 2) >> 2;
  923. SRC(0,1)=SRC(2,0)= (l1 + l2 + 1) >> 1;
  924. SRC(1,1)=SRC(3,0)= (l1 + 2*l2 + l3 + 2) >> 2;
  925. SRC(0,2)=SRC(2,1)=SRC(4,0)= (l2 + l3 + 1) >> 1;
  926. SRC(1,2)=SRC(3,1)=SRC(5,0)= (l2 + 2*l3 + l4 + 2) >> 2;
  927. SRC(0,3)=SRC(2,2)=SRC(4,1)=SRC(6,0)= (l3 + l4 + 1) >> 1;
  928. SRC(1,3)=SRC(3,2)=SRC(5,1)=SRC(7,0)= (l3 + 2*l4 + l5 + 2) >> 2;
  929. SRC(0,4)=SRC(2,3)=SRC(4,2)=SRC(6,1)= (l4 + l5 + 1) >> 1;
  930. SRC(1,4)=SRC(3,3)=SRC(5,2)=SRC(7,1)= (l4 + 2*l5 + l6 + 2) >> 2;
  931. SRC(0,5)=SRC(2,4)=SRC(4,3)=SRC(6,2)= (l5 + l6 + 1) >> 1;
  932. SRC(1,5)=SRC(3,4)=SRC(5,3)=SRC(7,2)= (l5 + 2*l6 + l7 + 2) >> 2;
  933. SRC(0,6)=SRC(2,5)=SRC(4,4)=SRC(6,3)= (l6 + l7 + 1) >> 1;
  934. SRC(1,6)=SRC(3,5)=SRC(5,4)=SRC(7,3)= (l6 + 3*l7 + 2) >> 2;
  935. SRC(0,7)=SRC(1,7)=SRC(2,6)=SRC(2,7)=SRC(3,6)=
  936. SRC(3,7)=SRC(4,5)=SRC(4,6)=SRC(4,7)=SRC(5,5)=
  937. SRC(5,6)=SRC(5,7)=SRC(6,4)=SRC(6,5)=SRC(6,6)=
  938. SRC(6,7)=SRC(7,4)=SRC(7,5)=SRC(7,6)=SRC(7,7)= l7;
  939. }
  940. #undef PREDICT_8x8_LOAD_LEFT
  941. #undef PREDICT_8x8_LOAD_TOP
  942. #undef PREDICT_8x8_LOAD_TOPLEFT
  943. #undef PREDICT_8x8_LOAD_TOPRIGHT
  944. #undef PREDICT_8x8_DC
  945. #undef PTR
  946. #undef PT
  947. #undef PL
  948. #undef SRC
  949. static void FUNCC(pred4x4_vertical_add)(uint8_t *p_pix, const DCTELEM *p_block, int stride){
  950. int i;
  951. pixel *pix = (pixel*)p_pix;
  952. const dctcoef *block = (const dctcoef*)p_block;
  953. stride >>= sizeof(pixel)-1;
  954. pix -= stride;
  955. for(i=0; i<4; i++){
  956. pixel v = pix[0];
  957. pix[1*stride]= v += block[0];
  958. pix[2*stride]= v += block[4];
  959. pix[3*stride]= v += block[8];
  960. pix[4*stride]= v + block[12];
  961. pix++;
  962. block++;
  963. }
  964. }
  965. static void FUNCC(pred4x4_horizontal_add)(uint8_t *p_pix, const DCTELEM *p_block, int stride){
  966. int i;
  967. pixel *pix = (pixel*)p_pix;
  968. const dctcoef *block = (const dctcoef*)p_block;
  969. stride >>= sizeof(pixel)-1;
  970. for(i=0; i<4; i++){
  971. pixel v = pix[-1];
  972. pix[0]= v += block[0];
  973. pix[1]= v += block[1];
  974. pix[2]= v += block[2];
  975. pix[3]= v + block[3];
  976. pix+= stride;
  977. block+= 4;
  978. }
  979. }
  980. static void FUNCC(pred8x8l_vertical_add)(uint8_t *p_pix, const DCTELEM *p_block, int stride){
  981. int i;
  982. pixel *pix = (pixel*)p_pix;
  983. const dctcoef *block = (const dctcoef*)p_block;
  984. stride >>= sizeof(pixel)-1;
  985. pix -= stride;
  986. for(i=0; i<8; i++){
  987. pixel v = pix[0];
  988. pix[1*stride]= v += block[0];
  989. pix[2*stride]= v += block[8];
  990. pix[3*stride]= v += block[16];
  991. pix[4*stride]= v += block[24];
  992. pix[5*stride]= v += block[32];
  993. pix[6*stride]= v += block[40];
  994. pix[7*stride]= v += block[48];
  995. pix[8*stride]= v + block[56];
  996. pix++;
  997. block++;
  998. }
  999. }
  1000. static void FUNCC(pred8x8l_horizontal_add)(uint8_t *p_pix, const DCTELEM *p_block, int stride){
  1001. int i;
  1002. pixel *pix = (pixel*)p_pix;
  1003. const dctcoef *block = (const dctcoef*)p_block;
  1004. stride >>= sizeof(pixel)-1;
  1005. for(i=0; i<8; i++){
  1006. pixel v = pix[-1];
  1007. pix[0]= v += block[0];
  1008. pix[1]= v += block[1];
  1009. pix[2]= v += block[2];
  1010. pix[3]= v += block[3];
  1011. pix[4]= v += block[4];
  1012. pix[5]= v += block[5];
  1013. pix[6]= v += block[6];
  1014. pix[7]= v + block[7];
  1015. pix+= stride;
  1016. block+= 8;
  1017. }
  1018. }
  1019. static void FUNCC(pred16x16_vertical_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){
  1020. int i;
  1021. for(i=0; i<16; i++)
  1022. FUNCC(pred4x4_vertical_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
  1023. }
  1024. static void FUNCC(pred16x16_horizontal_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){
  1025. int i;
  1026. for(i=0; i<16; i++)
  1027. FUNCC(pred4x4_horizontal_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
  1028. }
  1029. static void FUNCC(pred8x8_vertical_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){
  1030. int i;
  1031. for(i=0; i<4; i++)
  1032. FUNCC(pred4x4_vertical_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
  1033. }
  1034. static void FUNCC(pred8x16_vertical_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){
  1035. int i;
  1036. for(i=0; i<4; i++)
  1037. FUNCC(pred4x4_vertical_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
  1038. for(i=4; i<8; i++)
  1039. FUNCC(pred4x4_vertical_add)(pix + block_offset[i+4], block + i*16*sizeof(pixel), stride);
  1040. }
  1041. static void FUNCC(pred8x8_horizontal_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){
  1042. int i;
  1043. for(i=0; i<4; i++)
  1044. FUNCC(pred4x4_horizontal_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
  1045. }
  1046. static void FUNCC(pred8x16_horizontal_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){
  1047. int i;
  1048. for(i=0; i<4; i++)
  1049. FUNCC(pred4x4_horizontal_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride);
  1050. for(i=4; i<8; i++)
  1051. FUNCC(pred4x4_horizontal_add)(pix + block_offset[i+4], block + i*16*sizeof(pixel), stride);
  1052. }