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.

3681 lines
131KB

  1. /*
  2. * DSP utils
  3. * Copyright (c) 2000, 2001 Fabrice Bellard.
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
  21. */
  22. /**
  23. * @file dsputil.c
  24. * DSP utils
  25. */
  26. #include "avcodec.h"
  27. #include "dsputil.h"
  28. #include "mpegvideo.h"
  29. #include "simple_idct.h"
  30. #include "faandct.h"
  31. uint8_t cropTbl[256 + 2 * MAX_NEG_CROP] = {0, };
  32. uint32_t squareTbl[512] = {0, };
  33. const uint8_t ff_zigzag_direct[64] = {
  34. 0, 1, 8, 16, 9, 2, 3, 10,
  35. 17, 24, 32, 25, 18, 11, 4, 5,
  36. 12, 19, 26, 33, 40, 48, 41, 34,
  37. 27, 20, 13, 6, 7, 14, 21, 28,
  38. 35, 42, 49, 56, 57, 50, 43, 36,
  39. 29, 22, 15, 23, 30, 37, 44, 51,
  40. 58, 59, 52, 45, 38, 31, 39, 46,
  41. 53, 60, 61, 54, 47, 55, 62, 63
  42. };
  43. /* Specific zigzag scan for 248 idct. NOTE that unlike the
  44. specification, we interleave the fields */
  45. const uint8_t ff_zigzag248_direct[64] = {
  46. 0, 8, 1, 9, 16, 24, 2, 10,
  47. 17, 25, 32, 40, 48, 56, 33, 41,
  48. 18, 26, 3, 11, 4, 12, 19, 27,
  49. 34, 42, 49, 57, 50, 58, 35, 43,
  50. 20, 28, 5, 13, 6, 14, 21, 29,
  51. 36, 44, 51, 59, 52, 60, 37, 45,
  52. 22, 30, 7, 15, 23, 31, 38, 46,
  53. 53, 61, 54, 62, 39, 47, 55, 63,
  54. };
  55. /* not permutated inverse zigzag_direct + 1 for MMX quantizer */
  56. uint16_t __align8 inv_zigzag_direct16[64] = {0, };
  57. const uint8_t ff_alternate_horizontal_scan[64] = {
  58. 0, 1, 2, 3, 8, 9, 16, 17,
  59. 10, 11, 4, 5, 6, 7, 15, 14,
  60. 13, 12, 19, 18, 24, 25, 32, 33,
  61. 26, 27, 20, 21, 22, 23, 28, 29,
  62. 30, 31, 34, 35, 40, 41, 48, 49,
  63. 42, 43, 36, 37, 38, 39, 44, 45,
  64. 46, 47, 50, 51, 56, 57, 58, 59,
  65. 52, 53, 54, 55, 60, 61, 62, 63,
  66. };
  67. const uint8_t ff_alternate_vertical_scan[64] = {
  68. 0, 8, 16, 24, 1, 9, 2, 10,
  69. 17, 25, 32, 40, 48, 56, 57, 49,
  70. 41, 33, 26, 18, 3, 11, 4, 12,
  71. 19, 27, 34, 42, 50, 58, 35, 43,
  72. 51, 59, 20, 28, 5, 13, 6, 14,
  73. 21, 29, 36, 44, 52, 60, 37, 45,
  74. 53, 61, 22, 30, 7, 15, 23, 31,
  75. 38, 46, 54, 62, 39, 47, 55, 63,
  76. };
  77. /* a*inverse[b]>>32 == a/b for all 0<=a<=65536 && 2<=b<=255 */
  78. const uint32_t inverse[256]={
  79. 0, 4294967295U,2147483648U,1431655766, 1073741824, 858993460, 715827883, 613566757,
  80. 536870912, 477218589, 429496730, 390451573, 357913942, 330382100, 306783379, 286331154,
  81. 268435456, 252645136, 238609295, 226050911, 214748365, 204522253, 195225787, 186737709,
  82. 178956971, 171798692, 165191050, 159072863, 153391690, 148102321, 143165577, 138547333,
  83. 134217728, 130150525, 126322568, 122713352, 119304648, 116080198, 113025456, 110127367,
  84. 107374183, 104755300, 102261127, 99882961, 97612894, 95443718, 93368855, 91382283,
  85. 89478486, 87652394, 85899346, 84215046, 82595525, 81037119, 79536432, 78090315,
  86. 76695845, 75350304, 74051161, 72796056, 71582789, 70409300, 69273667, 68174085,
  87. 67108864, 66076420, 65075263, 64103990, 63161284, 62245903, 61356676, 60492498,
  88. 59652324, 58835169, 58040099, 57266231, 56512728, 55778797, 55063684, 54366675,
  89. 53687092, 53024288, 52377650, 51746594, 51130564, 50529028, 49941481, 49367441,
  90. 48806447, 48258060, 47721859, 47197443, 46684428, 46182445, 45691142, 45210183,
  91. 44739243, 44278014, 43826197, 43383509, 42949673, 42524429, 42107523, 41698712,
  92. 41297763, 40904451, 40518560, 40139882, 39768216, 39403370, 39045158, 38693400,
  93. 38347923, 38008561, 37675152, 37347542, 37025581, 36709123, 36398028, 36092163,
  94. 35791395, 35495598, 35204650, 34918434, 34636834, 34359739, 34087043, 33818641,
  95. 33554432, 33294321, 33038210, 32786010, 32537632, 32292988, 32051995, 31814573,
  96. 31580642, 31350127, 31122952, 30899046, 30678338, 30460761, 30246249, 30034737,
  97. 29826162, 29620465, 29417585, 29217465, 29020050, 28825284, 28633116, 28443493,
  98. 28256364, 28071682, 27889399, 27709467, 27531842, 27356480, 27183338, 27012373,
  99. 26843546, 26676816, 26512144, 26349493, 26188825, 26030105, 25873297, 25718368,
  100. 25565282, 25414008, 25264514, 25116768, 24970741, 24826401, 24683721, 24542671,
  101. 24403224, 24265352, 24129030, 23994231, 23860930, 23729102, 23598722, 23469767,
  102. 23342214, 23216040, 23091223, 22967740, 22845571, 22724695, 22605092, 22486740,
  103. 22369622, 22253717, 22139007, 22025474, 21913099, 21801865, 21691755, 21582751,
  104. 21474837, 21367997, 21262215, 21157475, 21053762, 20951060, 20849356, 20748635,
  105. 20648882, 20550083, 20452226, 20355296, 20259280, 20164166, 20069941, 19976593,
  106. 19884108, 19792477, 19701685, 19611723, 19522579, 19434242, 19346700, 19259944,
  107. 19173962, 19088744, 19004281, 18920561, 18837576, 18755316, 18673771, 18592933,
  108. 18512791, 18433337, 18354562, 18276457, 18199014, 18122225, 18046082, 17970575,
  109. 17895698, 17821442, 17747799, 17674763, 17602325, 17530479, 17459217, 17388532,
  110. 17318417, 17248865, 17179870, 17111424, 17043522, 16976156, 16909321, 16843010,
  111. };
  112. /* Input permutation for the simple_idct_mmx */
  113. static const uint8_t simple_mmx_permutation[64]={
  114. 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D,
  115. 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D,
  116. 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D,
  117. 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F,
  118. 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F,
  119. 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D,
  120. 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F,
  121. 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F,
  122. };
  123. static int pix_sum_c(uint8_t * pix, int line_size)
  124. {
  125. int s, i, j;
  126. s = 0;
  127. for (i = 0; i < 16; i++) {
  128. for (j = 0; j < 16; j += 8) {
  129. s += pix[0];
  130. s += pix[1];
  131. s += pix[2];
  132. s += pix[3];
  133. s += pix[4];
  134. s += pix[5];
  135. s += pix[6];
  136. s += pix[7];
  137. pix += 8;
  138. }
  139. pix += line_size - 16;
  140. }
  141. return s;
  142. }
  143. static int pix_norm1_c(uint8_t * pix, int line_size)
  144. {
  145. int s, i, j;
  146. uint32_t *sq = squareTbl + 256;
  147. s = 0;
  148. for (i = 0; i < 16; i++) {
  149. for (j = 0; j < 16; j += 8) {
  150. #if 0
  151. s += sq[pix[0]];
  152. s += sq[pix[1]];
  153. s += sq[pix[2]];
  154. s += sq[pix[3]];
  155. s += sq[pix[4]];
  156. s += sq[pix[5]];
  157. s += sq[pix[6]];
  158. s += sq[pix[7]];
  159. #else
  160. #if LONG_MAX > 2147483647
  161. register uint64_t x=*(uint64_t*)pix;
  162. s += sq[x&0xff];
  163. s += sq[(x>>8)&0xff];
  164. s += sq[(x>>16)&0xff];
  165. s += sq[(x>>24)&0xff];
  166. s += sq[(x>>32)&0xff];
  167. s += sq[(x>>40)&0xff];
  168. s += sq[(x>>48)&0xff];
  169. s += sq[(x>>56)&0xff];
  170. #else
  171. register uint32_t x=*(uint32_t*)pix;
  172. s += sq[x&0xff];
  173. s += sq[(x>>8)&0xff];
  174. s += sq[(x>>16)&0xff];
  175. s += sq[(x>>24)&0xff];
  176. x=*(uint32_t*)(pix+4);
  177. s += sq[x&0xff];
  178. s += sq[(x>>8)&0xff];
  179. s += sq[(x>>16)&0xff];
  180. s += sq[(x>>24)&0xff];
  181. #endif
  182. #endif
  183. pix += 8;
  184. }
  185. pix += line_size - 16;
  186. }
  187. return s;
  188. }
  189. static void bswap_buf(uint32_t *dst, uint32_t *src, int w){
  190. int i;
  191. for(i=0; i+8<=w; i+=8){
  192. dst[i+0]= bswap_32(src[i+0]);
  193. dst[i+1]= bswap_32(src[i+1]);
  194. dst[i+2]= bswap_32(src[i+2]);
  195. dst[i+3]= bswap_32(src[i+3]);
  196. dst[i+4]= bswap_32(src[i+4]);
  197. dst[i+5]= bswap_32(src[i+5]);
  198. dst[i+6]= bswap_32(src[i+6]);
  199. dst[i+7]= bswap_32(src[i+7]);
  200. }
  201. for(;i<w; i++){
  202. dst[i+0]= bswap_32(src[i+0]);
  203. }
  204. }
  205. static int sse4_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
  206. {
  207. int s, i;
  208. uint32_t *sq = squareTbl + 256;
  209. s = 0;
  210. for (i = 0; i < h; i++) {
  211. s += sq[pix1[0] - pix2[0]];
  212. s += sq[pix1[1] - pix2[1]];
  213. s += sq[pix1[2] - pix2[2]];
  214. s += sq[pix1[3] - pix2[3]];
  215. pix1 += line_size;
  216. pix2 += line_size;
  217. }
  218. return s;
  219. }
  220. static int sse8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
  221. {
  222. int s, i;
  223. uint32_t *sq = squareTbl + 256;
  224. s = 0;
  225. for (i = 0; i < h; i++) {
  226. s += sq[pix1[0] - pix2[0]];
  227. s += sq[pix1[1] - pix2[1]];
  228. s += sq[pix1[2] - pix2[2]];
  229. s += sq[pix1[3] - pix2[3]];
  230. s += sq[pix1[4] - pix2[4]];
  231. s += sq[pix1[5] - pix2[5]];
  232. s += sq[pix1[6] - pix2[6]];
  233. s += sq[pix1[7] - pix2[7]];
  234. pix1 += line_size;
  235. pix2 += line_size;
  236. }
  237. return s;
  238. }
  239. static int sse16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  240. {
  241. int s, i;
  242. uint32_t *sq = squareTbl + 256;
  243. s = 0;
  244. for (i = 0; i < h; i++) {
  245. s += sq[pix1[ 0] - pix2[ 0]];
  246. s += sq[pix1[ 1] - pix2[ 1]];
  247. s += sq[pix1[ 2] - pix2[ 2]];
  248. s += sq[pix1[ 3] - pix2[ 3]];
  249. s += sq[pix1[ 4] - pix2[ 4]];
  250. s += sq[pix1[ 5] - pix2[ 5]];
  251. s += sq[pix1[ 6] - pix2[ 6]];
  252. s += sq[pix1[ 7] - pix2[ 7]];
  253. s += sq[pix1[ 8] - pix2[ 8]];
  254. s += sq[pix1[ 9] - pix2[ 9]];
  255. s += sq[pix1[10] - pix2[10]];
  256. s += sq[pix1[11] - pix2[11]];
  257. s += sq[pix1[12] - pix2[12]];
  258. s += sq[pix1[13] - pix2[13]];
  259. s += sq[pix1[14] - pix2[14]];
  260. s += sq[pix1[15] - pix2[15]];
  261. pix1 += line_size;
  262. pix2 += line_size;
  263. }
  264. return s;
  265. }
  266. static inline int w_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int w, int h, int type){
  267. int s, i, j;
  268. const int dec_count= w==8 ? 3 : 4;
  269. int tmp[16*16];
  270. #if 0
  271. int level, ori;
  272. static const int scale[2][2][4][4]={
  273. {
  274. {
  275. //8x8 dec=3
  276. {268, 239, 239, 213},
  277. { 0, 224, 224, 152},
  278. { 0, 135, 135, 110},
  279. },{
  280. //16x16 dec=4
  281. {344, 310, 310, 280},
  282. { 0, 320, 320, 228},
  283. { 0, 175, 175, 136},
  284. { 0, 129, 129, 102},
  285. }
  286. },{
  287. {//FIXME 5/3
  288. //8x8 dec=3
  289. {275, 245, 245, 218},
  290. { 0, 230, 230, 156},
  291. { 0, 138, 138, 113},
  292. },{
  293. //16x16 dec=4
  294. {352, 317, 317, 286},
  295. { 0, 328, 328, 233},
  296. { 0, 180, 180, 140},
  297. { 0, 132, 132, 105},
  298. }
  299. }
  300. };
  301. #endif
  302. for (i = 0; i < h; i++) {
  303. for (j = 0; j < w; j+=4) {
  304. tmp[16*i+j+0] = (pix1[j+0] - pix2[j+0])<<4;
  305. tmp[16*i+j+1] = (pix1[j+1] - pix2[j+1])<<4;
  306. tmp[16*i+j+2] = (pix1[j+2] - pix2[j+2])<<4;
  307. tmp[16*i+j+3] = (pix1[j+3] - pix2[j+3])<<4;
  308. }
  309. pix1 += line_size;
  310. pix2 += line_size;
  311. }
  312. ff_spatial_dwt(tmp, w, h, 16, type, dec_count);
  313. s=0;
  314. #if 0
  315. for(level=0; level<dec_count; level++){
  316. for(ori= level ? 1 : 0; ori<4; ori++){
  317. int sx= (ori&1) ? 1<<level: 0;
  318. int stride= 16<<(dec_count-level);
  319. int sy= (ori&2) ? stride>>1 : 0;
  320. int size= 1<<level;
  321. for(i=0; i<size; i++){
  322. for(j=0; j<size; j++){
  323. int v= tmp[sx + sy + i*stride + j] * scale[type][dec_count-3][level][ori];
  324. s += ABS(v);
  325. }
  326. }
  327. }
  328. }
  329. #endif
  330. for (i = 0; i < h; i++) {
  331. for (j = 0; j < w; j+=4) {
  332. s+= ABS(tmp[16*i+j+0]);
  333. s+= ABS(tmp[16*i+j+1]);
  334. s+= ABS(tmp[16*i+j+2]);
  335. s+= ABS(tmp[16*i+j+3]);
  336. }
  337. }
  338. assert(s>=0);
  339. return s>>2;
  340. }
  341. static int w53_8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){
  342. return w_c(v, pix1, pix2, line_size, 8, h, 1);
  343. }
  344. static int w97_8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){
  345. return w_c(v, pix1, pix2, line_size, 8, h, 0);
  346. }
  347. static int w53_16_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){
  348. return w_c(v, pix1, pix2, line_size, 16, h, 1);
  349. }
  350. static int w97_16_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){
  351. return w_c(v, pix1, pix2, line_size, 16, h, 0);
  352. }
  353. static void get_pixels_c(DCTELEM *restrict block, const uint8_t *pixels, int line_size)
  354. {
  355. int i;
  356. /* read the pixels */
  357. for(i=0;i<8;i++) {
  358. block[0] = pixels[0];
  359. block[1] = pixels[1];
  360. block[2] = pixels[2];
  361. block[3] = pixels[3];
  362. block[4] = pixels[4];
  363. block[5] = pixels[5];
  364. block[6] = pixels[6];
  365. block[7] = pixels[7];
  366. pixels += line_size;
  367. block += 8;
  368. }
  369. }
  370. static void diff_pixels_c(DCTELEM *restrict block, const uint8_t *s1,
  371. const uint8_t *s2, int stride){
  372. int i;
  373. /* read the pixels */
  374. for(i=0;i<8;i++) {
  375. block[0] = s1[0] - s2[0];
  376. block[1] = s1[1] - s2[1];
  377. block[2] = s1[2] - s2[2];
  378. block[3] = s1[3] - s2[3];
  379. block[4] = s1[4] - s2[4];
  380. block[5] = s1[5] - s2[5];
  381. block[6] = s1[6] - s2[6];
  382. block[7] = s1[7] - s2[7];
  383. s1 += stride;
  384. s2 += stride;
  385. block += 8;
  386. }
  387. }
  388. static void put_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
  389. int line_size)
  390. {
  391. int i;
  392. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  393. /* read the pixels */
  394. for(i=0;i<8;i++) {
  395. pixels[0] = cm[block[0]];
  396. pixels[1] = cm[block[1]];
  397. pixels[2] = cm[block[2]];
  398. pixels[3] = cm[block[3]];
  399. pixels[4] = cm[block[4]];
  400. pixels[5] = cm[block[5]];
  401. pixels[6] = cm[block[6]];
  402. pixels[7] = cm[block[7]];
  403. pixels += line_size;
  404. block += 8;
  405. }
  406. }
  407. static void put_pixels_clamped4_c(const DCTELEM *block, uint8_t *restrict pixels,
  408. int line_size)
  409. {
  410. int i;
  411. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  412. /* read the pixels */
  413. for(i=0;i<4;i++) {
  414. pixels[0] = cm[block[0]];
  415. pixels[1] = cm[block[1]];
  416. pixels[2] = cm[block[2]];
  417. pixels[3] = cm[block[3]];
  418. pixels += line_size;
  419. block += 8;
  420. }
  421. }
  422. static void put_pixels_clamped2_c(const DCTELEM *block, uint8_t *restrict pixels,
  423. int line_size)
  424. {
  425. int i;
  426. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  427. /* read the pixels */
  428. for(i=0;i<2;i++) {
  429. pixels[0] = cm[block[0]];
  430. pixels[1] = cm[block[1]];
  431. pixels += line_size;
  432. block += 8;
  433. }
  434. }
  435. static void put_signed_pixels_clamped_c(const DCTELEM *block,
  436. uint8_t *restrict pixels,
  437. int line_size)
  438. {
  439. int i, j;
  440. for (i = 0; i < 8; i++) {
  441. for (j = 0; j < 8; j++) {
  442. if (*block < -128)
  443. *pixels = 0;
  444. else if (*block > 127)
  445. *pixels = 255;
  446. else
  447. *pixels = (uint8_t)(*block + 128);
  448. block++;
  449. pixels++;
  450. }
  451. pixels += (line_size - 8);
  452. }
  453. }
  454. static void add_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
  455. int line_size)
  456. {
  457. int i;
  458. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  459. /* read the pixels */
  460. for(i=0;i<8;i++) {
  461. pixels[0] = cm[pixels[0] + block[0]];
  462. pixels[1] = cm[pixels[1] + block[1]];
  463. pixels[2] = cm[pixels[2] + block[2]];
  464. pixels[3] = cm[pixels[3] + block[3]];
  465. pixels[4] = cm[pixels[4] + block[4]];
  466. pixels[5] = cm[pixels[5] + block[5]];
  467. pixels[6] = cm[pixels[6] + block[6]];
  468. pixels[7] = cm[pixels[7] + block[7]];
  469. pixels += line_size;
  470. block += 8;
  471. }
  472. }
  473. static void add_pixels_clamped4_c(const DCTELEM *block, uint8_t *restrict pixels,
  474. int line_size)
  475. {
  476. int i;
  477. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  478. /* read the pixels */
  479. for(i=0;i<4;i++) {
  480. pixels[0] = cm[pixels[0] + block[0]];
  481. pixels[1] = cm[pixels[1] + block[1]];
  482. pixels[2] = cm[pixels[2] + block[2]];
  483. pixels[3] = cm[pixels[3] + block[3]];
  484. pixels += line_size;
  485. block += 8;
  486. }
  487. }
  488. static void add_pixels_clamped2_c(const DCTELEM *block, uint8_t *restrict pixels,
  489. int line_size)
  490. {
  491. int i;
  492. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  493. /* read the pixels */
  494. for(i=0;i<2;i++) {
  495. pixels[0] = cm[pixels[0] + block[0]];
  496. pixels[1] = cm[pixels[1] + block[1]];
  497. pixels += line_size;
  498. block += 8;
  499. }
  500. }
  501. #if 0
  502. #define PIXOP2(OPNAME, OP) \
  503. static void OPNAME ## _pixels(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  504. {\
  505. int i;\
  506. for(i=0; i<h; i++){\
  507. OP(*((uint64_t*)block), LD64(pixels));\
  508. pixels+=line_size;\
  509. block +=line_size;\
  510. }\
  511. }\
  512. \
  513. static void OPNAME ## _no_rnd_pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  514. {\
  515. int i;\
  516. for(i=0; i<h; i++){\
  517. const uint64_t a= LD64(pixels );\
  518. const uint64_t b= LD64(pixels+1);\
  519. OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  520. pixels+=line_size;\
  521. block +=line_size;\
  522. }\
  523. }\
  524. \
  525. static void OPNAME ## _pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  526. {\
  527. int i;\
  528. for(i=0; i<h; i++){\
  529. const uint64_t a= LD64(pixels );\
  530. const uint64_t b= LD64(pixels+1);\
  531. OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  532. pixels+=line_size;\
  533. block +=line_size;\
  534. }\
  535. }\
  536. \
  537. static void OPNAME ## _no_rnd_pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  538. {\
  539. int i;\
  540. for(i=0; i<h; i++){\
  541. const uint64_t a= LD64(pixels );\
  542. const uint64_t b= LD64(pixels+line_size);\
  543. OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  544. pixels+=line_size;\
  545. block +=line_size;\
  546. }\
  547. }\
  548. \
  549. static void OPNAME ## _pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  550. {\
  551. int i;\
  552. for(i=0; i<h; i++){\
  553. const uint64_t a= LD64(pixels );\
  554. const uint64_t b= LD64(pixels+line_size);\
  555. OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  556. pixels+=line_size;\
  557. block +=line_size;\
  558. }\
  559. }\
  560. \
  561. static void OPNAME ## _pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  562. {\
  563. int i;\
  564. const uint64_t a= LD64(pixels );\
  565. const uint64_t b= LD64(pixels+1);\
  566. uint64_t l0= (a&0x0303030303030303ULL)\
  567. + (b&0x0303030303030303ULL)\
  568. + 0x0202020202020202ULL;\
  569. uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  570. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  571. uint64_t l1,h1;\
  572. \
  573. pixels+=line_size;\
  574. for(i=0; i<h; i+=2){\
  575. uint64_t a= LD64(pixels );\
  576. uint64_t b= LD64(pixels+1);\
  577. l1= (a&0x0303030303030303ULL)\
  578. + (b&0x0303030303030303ULL);\
  579. h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  580. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  581. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  582. pixels+=line_size;\
  583. block +=line_size;\
  584. a= LD64(pixels );\
  585. b= LD64(pixels+1);\
  586. l0= (a&0x0303030303030303ULL)\
  587. + (b&0x0303030303030303ULL)\
  588. + 0x0202020202020202ULL;\
  589. h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  590. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  591. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  592. pixels+=line_size;\
  593. block +=line_size;\
  594. }\
  595. }\
  596. \
  597. static void OPNAME ## _no_rnd_pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  598. {\
  599. int i;\
  600. const uint64_t a= LD64(pixels );\
  601. const uint64_t b= LD64(pixels+1);\
  602. uint64_t l0= (a&0x0303030303030303ULL)\
  603. + (b&0x0303030303030303ULL)\
  604. + 0x0101010101010101ULL;\
  605. uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  606. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  607. uint64_t l1,h1;\
  608. \
  609. pixels+=line_size;\
  610. for(i=0; i<h; i+=2){\
  611. uint64_t a= LD64(pixels );\
  612. uint64_t b= LD64(pixels+1);\
  613. l1= (a&0x0303030303030303ULL)\
  614. + (b&0x0303030303030303ULL);\
  615. h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  616. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  617. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  618. pixels+=line_size;\
  619. block +=line_size;\
  620. a= LD64(pixels );\
  621. b= LD64(pixels+1);\
  622. l0= (a&0x0303030303030303ULL)\
  623. + (b&0x0303030303030303ULL)\
  624. + 0x0101010101010101ULL;\
  625. h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  626. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  627. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  628. pixels+=line_size;\
  629. block +=line_size;\
  630. }\
  631. }\
  632. \
  633. CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels_c , 8)\
  634. CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels_x2_c , 8)\
  635. CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels_y2_c , 8)\
  636. CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels_xy2_c, 8)\
  637. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels_x2_c , 8)\
  638. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels_y2_c , 8)\
  639. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels_xy2_c, 8)
  640. #define op_avg(a, b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEFEFEFEFEULL)>>1) )
  641. #else // 64 bit variant
  642. #define PIXOP2(OPNAME, OP) \
  643. static void OPNAME ## _pixels2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  644. int i;\
  645. for(i=0; i<h; i++){\
  646. OP(*((uint16_t*)(block )), LD16(pixels ));\
  647. pixels+=line_size;\
  648. block +=line_size;\
  649. }\
  650. }\
  651. static void OPNAME ## _pixels4_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  652. int i;\
  653. for(i=0; i<h; i++){\
  654. OP(*((uint32_t*)(block )), LD32(pixels ));\
  655. pixels+=line_size;\
  656. block +=line_size;\
  657. }\
  658. }\
  659. static void OPNAME ## _pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  660. int i;\
  661. for(i=0; i<h; i++){\
  662. OP(*((uint32_t*)(block )), LD32(pixels ));\
  663. OP(*((uint32_t*)(block+4)), LD32(pixels+4));\
  664. pixels+=line_size;\
  665. block +=line_size;\
  666. }\
  667. }\
  668. static inline void OPNAME ## _no_rnd_pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  669. OPNAME ## _pixels8_c(block, pixels, line_size, h);\
  670. }\
  671. \
  672. static inline void OPNAME ## _no_rnd_pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  673. int src_stride1, int src_stride2, int h){\
  674. int i;\
  675. for(i=0; i<h; i++){\
  676. uint32_t a,b;\
  677. a= LD32(&src1[i*src_stride1 ]);\
  678. b= LD32(&src2[i*src_stride2 ]);\
  679. OP(*((uint32_t*)&dst[i*dst_stride ]), no_rnd_avg32(a, b));\
  680. a= LD32(&src1[i*src_stride1+4]);\
  681. b= LD32(&src2[i*src_stride2+4]);\
  682. OP(*((uint32_t*)&dst[i*dst_stride+4]), no_rnd_avg32(a, b));\
  683. }\
  684. }\
  685. \
  686. static inline void OPNAME ## _pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  687. int src_stride1, int src_stride2, int h){\
  688. int i;\
  689. for(i=0; i<h; i++){\
  690. uint32_t a,b;\
  691. a= LD32(&src1[i*src_stride1 ]);\
  692. b= LD32(&src2[i*src_stride2 ]);\
  693. OP(*((uint32_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
  694. a= LD32(&src1[i*src_stride1+4]);\
  695. b= LD32(&src2[i*src_stride2+4]);\
  696. OP(*((uint32_t*)&dst[i*dst_stride+4]), rnd_avg32(a, b));\
  697. }\
  698. }\
  699. \
  700. static inline void OPNAME ## _pixels4_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  701. int src_stride1, int src_stride2, int h){\
  702. int i;\
  703. for(i=0; i<h; i++){\
  704. uint32_t a,b;\
  705. a= LD32(&src1[i*src_stride1 ]);\
  706. b= LD32(&src2[i*src_stride2 ]);\
  707. OP(*((uint32_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
  708. }\
  709. }\
  710. \
  711. static inline void OPNAME ## _pixels2_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  712. int src_stride1, int src_stride2, int h){\
  713. int i;\
  714. for(i=0; i<h; i++){\
  715. uint32_t a,b;\
  716. a= LD16(&src1[i*src_stride1 ]);\
  717. b= LD16(&src2[i*src_stride2 ]);\
  718. OP(*((uint16_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
  719. }\
  720. }\
  721. \
  722. static inline void OPNAME ## _pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  723. int src_stride1, int src_stride2, int h){\
  724. OPNAME ## _pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
  725. OPNAME ## _pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
  726. }\
  727. \
  728. static inline void OPNAME ## _no_rnd_pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  729. int src_stride1, int src_stride2, int h){\
  730. OPNAME ## _no_rnd_pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
  731. OPNAME ## _no_rnd_pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
  732. }\
  733. \
  734. static inline void OPNAME ## _no_rnd_pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  735. OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
  736. }\
  737. \
  738. static inline void OPNAME ## _pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  739. OPNAME ## _pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
  740. }\
  741. \
  742. static inline void OPNAME ## _no_rnd_pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  743. OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
  744. }\
  745. \
  746. static inline void OPNAME ## _pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  747. OPNAME ## _pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
  748. }\
  749. \
  750. static inline void OPNAME ## _pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
  751. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  752. int i;\
  753. for(i=0; i<h; i++){\
  754. uint32_t a, b, c, d, l0, l1, h0, h1;\
  755. a= LD32(&src1[i*src_stride1]);\
  756. b= LD32(&src2[i*src_stride2]);\
  757. c= LD32(&src3[i*src_stride3]);\
  758. d= LD32(&src4[i*src_stride4]);\
  759. l0= (a&0x03030303UL)\
  760. + (b&0x03030303UL)\
  761. + 0x02020202UL;\
  762. h0= ((a&0xFCFCFCFCUL)>>2)\
  763. + ((b&0xFCFCFCFCUL)>>2);\
  764. l1= (c&0x03030303UL)\
  765. + (d&0x03030303UL);\
  766. h1= ((c&0xFCFCFCFCUL)>>2)\
  767. + ((d&0xFCFCFCFCUL)>>2);\
  768. OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  769. a= LD32(&src1[i*src_stride1+4]);\
  770. b= LD32(&src2[i*src_stride2+4]);\
  771. c= LD32(&src3[i*src_stride3+4]);\
  772. d= LD32(&src4[i*src_stride4+4]);\
  773. l0= (a&0x03030303UL)\
  774. + (b&0x03030303UL)\
  775. + 0x02020202UL;\
  776. h0= ((a&0xFCFCFCFCUL)>>2)\
  777. + ((b&0xFCFCFCFCUL)>>2);\
  778. l1= (c&0x03030303UL)\
  779. + (d&0x03030303UL);\
  780. h1= ((c&0xFCFCFCFCUL)>>2)\
  781. + ((d&0xFCFCFCFCUL)>>2);\
  782. OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  783. }\
  784. }\
  785. \
  786. static inline void OPNAME ## _pixels4_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  787. OPNAME ## _pixels4_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
  788. }\
  789. \
  790. static inline void OPNAME ## _pixels4_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  791. OPNAME ## _pixels4_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
  792. }\
  793. \
  794. static inline void OPNAME ## _pixels2_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  795. OPNAME ## _pixels2_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
  796. }\
  797. \
  798. static inline void OPNAME ## _pixels2_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  799. OPNAME ## _pixels2_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
  800. }\
  801. \
  802. static inline void OPNAME ## _no_rnd_pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
  803. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  804. int i;\
  805. for(i=0; i<h; i++){\
  806. uint32_t a, b, c, d, l0, l1, h0, h1;\
  807. a= LD32(&src1[i*src_stride1]);\
  808. b= LD32(&src2[i*src_stride2]);\
  809. c= LD32(&src3[i*src_stride3]);\
  810. d= LD32(&src4[i*src_stride4]);\
  811. l0= (a&0x03030303UL)\
  812. + (b&0x03030303UL)\
  813. + 0x01010101UL;\
  814. h0= ((a&0xFCFCFCFCUL)>>2)\
  815. + ((b&0xFCFCFCFCUL)>>2);\
  816. l1= (c&0x03030303UL)\
  817. + (d&0x03030303UL);\
  818. h1= ((c&0xFCFCFCFCUL)>>2)\
  819. + ((d&0xFCFCFCFCUL)>>2);\
  820. OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  821. a= LD32(&src1[i*src_stride1+4]);\
  822. b= LD32(&src2[i*src_stride2+4]);\
  823. c= LD32(&src3[i*src_stride3+4]);\
  824. d= LD32(&src4[i*src_stride4+4]);\
  825. l0= (a&0x03030303UL)\
  826. + (b&0x03030303UL)\
  827. + 0x01010101UL;\
  828. h0= ((a&0xFCFCFCFCUL)>>2)\
  829. + ((b&0xFCFCFCFCUL)>>2);\
  830. l1= (c&0x03030303UL)\
  831. + (d&0x03030303UL);\
  832. h1= ((c&0xFCFCFCFCUL)>>2)\
  833. + ((d&0xFCFCFCFCUL)>>2);\
  834. OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  835. }\
  836. }\
  837. static inline void OPNAME ## _pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
  838. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  839. OPNAME ## _pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  840. OPNAME ## _pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  841. }\
  842. static inline void OPNAME ## _no_rnd_pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
  843. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  844. OPNAME ## _no_rnd_pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  845. OPNAME ## _no_rnd_pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  846. }\
  847. \
  848. static inline void OPNAME ## _pixels2_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  849. {\
  850. int i, a0, b0, a1, b1;\
  851. a0= pixels[0];\
  852. b0= pixels[1] + 2;\
  853. a0 += b0;\
  854. b0 += pixels[2];\
  855. \
  856. pixels+=line_size;\
  857. for(i=0; i<h; i+=2){\
  858. a1= pixels[0];\
  859. b1= pixels[1];\
  860. a1 += b1;\
  861. b1 += pixels[2];\
  862. \
  863. block[0]= (a1+a0)>>2; /* FIXME non put */\
  864. block[1]= (b1+b0)>>2;\
  865. \
  866. pixels+=line_size;\
  867. block +=line_size;\
  868. \
  869. a0= pixels[0];\
  870. b0= pixels[1] + 2;\
  871. a0 += b0;\
  872. b0 += pixels[2];\
  873. \
  874. block[0]= (a1+a0)>>2;\
  875. block[1]= (b1+b0)>>2;\
  876. pixels+=line_size;\
  877. block +=line_size;\
  878. }\
  879. }\
  880. \
  881. static inline void OPNAME ## _pixels4_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  882. {\
  883. int i;\
  884. const uint32_t a= LD32(pixels );\
  885. const uint32_t b= LD32(pixels+1);\
  886. uint32_t l0= (a&0x03030303UL)\
  887. + (b&0x03030303UL)\
  888. + 0x02020202UL;\
  889. uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
  890. + ((b&0xFCFCFCFCUL)>>2);\
  891. uint32_t l1,h1;\
  892. \
  893. pixels+=line_size;\
  894. for(i=0; i<h; i+=2){\
  895. uint32_t a= LD32(pixels );\
  896. uint32_t b= LD32(pixels+1);\
  897. l1= (a&0x03030303UL)\
  898. + (b&0x03030303UL);\
  899. h1= ((a&0xFCFCFCFCUL)>>2)\
  900. + ((b&0xFCFCFCFCUL)>>2);\
  901. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  902. pixels+=line_size;\
  903. block +=line_size;\
  904. a= LD32(pixels );\
  905. b= LD32(pixels+1);\
  906. l0= (a&0x03030303UL)\
  907. + (b&0x03030303UL)\
  908. + 0x02020202UL;\
  909. h0= ((a&0xFCFCFCFCUL)>>2)\
  910. + ((b&0xFCFCFCFCUL)>>2);\
  911. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  912. pixels+=line_size;\
  913. block +=line_size;\
  914. }\
  915. }\
  916. \
  917. static inline void OPNAME ## _pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  918. {\
  919. int j;\
  920. for(j=0; j<2; j++){\
  921. int i;\
  922. const uint32_t a= LD32(pixels );\
  923. const uint32_t b= LD32(pixels+1);\
  924. uint32_t l0= (a&0x03030303UL)\
  925. + (b&0x03030303UL)\
  926. + 0x02020202UL;\
  927. uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
  928. + ((b&0xFCFCFCFCUL)>>2);\
  929. uint32_t l1,h1;\
  930. \
  931. pixels+=line_size;\
  932. for(i=0; i<h; i+=2){\
  933. uint32_t a= LD32(pixels );\
  934. uint32_t b= LD32(pixels+1);\
  935. l1= (a&0x03030303UL)\
  936. + (b&0x03030303UL);\
  937. h1= ((a&0xFCFCFCFCUL)>>2)\
  938. + ((b&0xFCFCFCFCUL)>>2);\
  939. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  940. pixels+=line_size;\
  941. block +=line_size;\
  942. a= LD32(pixels );\
  943. b= LD32(pixels+1);\
  944. l0= (a&0x03030303UL)\
  945. + (b&0x03030303UL)\
  946. + 0x02020202UL;\
  947. h0= ((a&0xFCFCFCFCUL)>>2)\
  948. + ((b&0xFCFCFCFCUL)>>2);\
  949. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  950. pixels+=line_size;\
  951. block +=line_size;\
  952. }\
  953. pixels+=4-line_size*(h+1);\
  954. block +=4-line_size*h;\
  955. }\
  956. }\
  957. \
  958. static inline void OPNAME ## _no_rnd_pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  959. {\
  960. int j;\
  961. for(j=0; j<2; j++){\
  962. int i;\
  963. const uint32_t a= LD32(pixels );\
  964. const uint32_t b= LD32(pixels+1);\
  965. uint32_t l0= (a&0x03030303UL)\
  966. + (b&0x03030303UL)\
  967. + 0x01010101UL;\
  968. uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
  969. + ((b&0xFCFCFCFCUL)>>2);\
  970. uint32_t l1,h1;\
  971. \
  972. pixels+=line_size;\
  973. for(i=0; i<h; i+=2){\
  974. uint32_t a= LD32(pixels );\
  975. uint32_t b= LD32(pixels+1);\
  976. l1= (a&0x03030303UL)\
  977. + (b&0x03030303UL);\
  978. h1= ((a&0xFCFCFCFCUL)>>2)\
  979. + ((b&0xFCFCFCFCUL)>>2);\
  980. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  981. pixels+=line_size;\
  982. block +=line_size;\
  983. a= LD32(pixels );\
  984. b= LD32(pixels+1);\
  985. l0= (a&0x03030303UL)\
  986. + (b&0x03030303UL)\
  987. + 0x01010101UL;\
  988. h0= ((a&0xFCFCFCFCUL)>>2)\
  989. + ((b&0xFCFCFCFCUL)>>2);\
  990. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  991. pixels+=line_size;\
  992. block +=line_size;\
  993. }\
  994. pixels+=4-line_size*(h+1);\
  995. block +=4-line_size*h;\
  996. }\
  997. }\
  998. \
  999. CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels8_c , 8)\
  1000. CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels8_x2_c , 8)\
  1001. CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels8_y2_c , 8)\
  1002. CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels8_xy2_c, 8)\
  1003. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_c , OPNAME ## _pixels8_c , 8)\
  1004. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels8_x2_c , 8)\
  1005. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels8_y2_c , 8)\
  1006. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels8_xy2_c, 8)\
  1007. #define op_avg(a, b) a = rnd_avg32(a, b)
  1008. #endif
  1009. #define op_put(a, b) a = b
  1010. PIXOP2(avg, op_avg)
  1011. PIXOP2(put, op_put)
  1012. #undef op_avg
  1013. #undef op_put
  1014. #define avg2(a,b) ((a+b+1)>>1)
  1015. #define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
  1016. static void put_no_rnd_pixels16_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){
  1017. put_no_rnd_pixels16_l2(dst, a, b, stride, stride, stride, h);
  1018. }
  1019. static void put_no_rnd_pixels8_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){
  1020. put_no_rnd_pixels8_l2(dst, a, b, stride, stride, stride, h);
  1021. }
  1022. static void gmc1_c(uint8_t *dst, uint8_t *src, int stride, int h, int x16, int y16, int rounder)
  1023. {
  1024. const int A=(16-x16)*(16-y16);
  1025. const int B=( x16)*(16-y16);
  1026. const int C=(16-x16)*( y16);
  1027. const int D=( x16)*( y16);
  1028. int i;
  1029. for(i=0; i<h; i++)
  1030. {
  1031. dst[0]= (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + rounder)>>8;
  1032. dst[1]= (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + rounder)>>8;
  1033. dst[2]= (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + rounder)>>8;
  1034. dst[3]= (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + rounder)>>8;
  1035. dst[4]= (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + rounder)>>8;
  1036. dst[5]= (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + rounder)>>8;
  1037. dst[6]= (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + rounder)>>8;
  1038. dst[7]= (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + rounder)>>8;
  1039. dst+= stride;
  1040. src+= stride;
  1041. }
  1042. }
  1043. static void gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
  1044. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
  1045. {
  1046. int y, vx, vy;
  1047. const int s= 1<<shift;
  1048. width--;
  1049. height--;
  1050. for(y=0; y<h; y++){
  1051. int x;
  1052. vx= ox;
  1053. vy= oy;
  1054. for(x=0; x<8; x++){ //XXX FIXME optimize
  1055. int src_x, src_y, frac_x, frac_y, index;
  1056. src_x= vx>>16;
  1057. src_y= vy>>16;
  1058. frac_x= src_x&(s-1);
  1059. frac_y= src_y&(s-1);
  1060. src_x>>=shift;
  1061. src_y>>=shift;
  1062. if((unsigned)src_x < width){
  1063. if((unsigned)src_y < height){
  1064. index= src_x + src_y*stride;
  1065. dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
  1066. + src[index +1]* frac_x )*(s-frac_y)
  1067. + ( src[index+stride ]*(s-frac_x)
  1068. + src[index+stride+1]* frac_x )* frac_y
  1069. + r)>>(shift*2);
  1070. }else{
  1071. index= src_x + clip(src_y, 0, height)*stride;
  1072. dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
  1073. + src[index +1]* frac_x )*s
  1074. + r)>>(shift*2);
  1075. }
  1076. }else{
  1077. if((unsigned)src_y < height){
  1078. index= clip(src_x, 0, width) + src_y*stride;
  1079. dst[y*stride + x]= ( ( src[index ]*(s-frac_y)
  1080. + src[index+stride ]* frac_y )*s
  1081. + r)>>(shift*2);
  1082. }else{
  1083. index= clip(src_x, 0, width) + clip(src_y, 0, height)*stride;
  1084. dst[y*stride + x]= src[index ];
  1085. }
  1086. }
  1087. vx+= dxx;
  1088. vy+= dyx;
  1089. }
  1090. ox += dxy;
  1091. oy += dyy;
  1092. }
  1093. }
  1094. static inline void put_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1095. switch(width){
  1096. case 2: put_pixels2_c (dst, src, stride, height); break;
  1097. case 4: put_pixels4_c (dst, src, stride, height); break;
  1098. case 8: put_pixels8_c (dst, src, stride, height); break;
  1099. case 16:put_pixels16_c(dst, src, stride, height); break;
  1100. }
  1101. }
  1102. static inline void put_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1103. int i,j;
  1104. for (i=0; i < height; i++) {
  1105. for (j=0; j < width; j++) {
  1106. dst[j] = (683*(2*src[j] + src[j+1] + 1)) >> 11;
  1107. }
  1108. src += stride;
  1109. dst += stride;
  1110. }
  1111. }
  1112. static inline void put_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1113. int i,j;
  1114. for (i=0; i < height; i++) {
  1115. for (j=0; j < width; j++) {
  1116. dst[j] = (683*(src[j] + 2*src[j+1] + 1)) >> 11;
  1117. }
  1118. src += stride;
  1119. dst += stride;
  1120. }
  1121. }
  1122. static inline void put_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1123. int i,j;
  1124. for (i=0; i < height; i++) {
  1125. for (j=0; j < width; j++) {
  1126. dst[j] = (683*(2*src[j] + src[j+stride] + 1)) >> 11;
  1127. }
  1128. src += stride;
  1129. dst += stride;
  1130. }
  1131. }
  1132. static inline void put_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1133. int i,j;
  1134. for (i=0; i < height; i++) {
  1135. for (j=0; j < width; j++) {
  1136. dst[j] = (2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15;
  1137. }
  1138. src += stride;
  1139. dst += stride;
  1140. }
  1141. }
  1142. static inline void put_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1143. int i,j;
  1144. for (i=0; i < height; i++) {
  1145. for (j=0; j < width; j++) {
  1146. dst[j] = (2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
  1147. }
  1148. src += stride;
  1149. dst += stride;
  1150. }
  1151. }
  1152. static inline void put_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1153. int i,j;
  1154. for (i=0; i < height; i++) {
  1155. for (j=0; j < width; j++) {
  1156. dst[j] = (683*(src[j] + 2*src[j+stride] + 1)) >> 11;
  1157. }
  1158. src += stride;
  1159. dst += stride;
  1160. }
  1161. }
  1162. static inline void put_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1163. int i,j;
  1164. for (i=0; i < height; i++) {
  1165. for (j=0; j < width; j++) {
  1166. dst[j] = (2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
  1167. }
  1168. src += stride;
  1169. dst += stride;
  1170. }
  1171. }
  1172. static inline void put_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1173. int i,j;
  1174. for (i=0; i < height; i++) {
  1175. for (j=0; j < width; j++) {
  1176. dst[j] = (2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15;
  1177. }
  1178. src += stride;
  1179. dst += stride;
  1180. }
  1181. }
  1182. static inline void avg_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1183. switch(width){
  1184. case 2: avg_pixels2_c (dst, src, stride, height); break;
  1185. case 4: avg_pixels4_c (dst, src, stride, height); break;
  1186. case 8: avg_pixels8_c (dst, src, stride, height); break;
  1187. case 16:avg_pixels16_c(dst, src, stride, height); break;
  1188. }
  1189. }
  1190. static inline void avg_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1191. int i,j;
  1192. for (i=0; i < height; i++) {
  1193. for (j=0; j < width; j++) {
  1194. dst[j] = (dst[j] + ((683*(2*src[j] + src[j+1] + 1)) >> 11) + 1) >> 1;
  1195. }
  1196. src += stride;
  1197. dst += stride;
  1198. }
  1199. }
  1200. static inline void avg_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1201. int i,j;
  1202. for (i=0; i < height; i++) {
  1203. for (j=0; j < width; j++) {
  1204. dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+1] + 1)) >> 11) + 1) >> 1;
  1205. }
  1206. src += stride;
  1207. dst += stride;
  1208. }
  1209. }
  1210. static inline void avg_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1211. int i,j;
  1212. for (i=0; i < height; i++) {
  1213. for (j=0; j < width; j++) {
  1214. dst[j] = (dst[j] + ((683*(2*src[j] + src[j+stride] + 1)) >> 11) + 1) >> 1;
  1215. }
  1216. src += stride;
  1217. dst += stride;
  1218. }
  1219. }
  1220. static inline void avg_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1221. int i,j;
  1222. for (i=0; i < height; i++) {
  1223. for (j=0; j < width; j++) {
  1224. dst[j] = (dst[j] + ((2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
  1225. }
  1226. src += stride;
  1227. dst += stride;
  1228. }
  1229. }
  1230. static inline void avg_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1231. int i,j;
  1232. for (i=0; i < height; i++) {
  1233. for (j=0; j < width; j++) {
  1234. dst[j] = (dst[j] + ((2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
  1235. }
  1236. src += stride;
  1237. dst += stride;
  1238. }
  1239. }
  1240. static inline void avg_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1241. int i,j;
  1242. for (i=0; i < height; i++) {
  1243. for (j=0; j < width; j++) {
  1244. dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+stride] + 1)) >> 11) + 1) >> 1;
  1245. }
  1246. src += stride;
  1247. dst += stride;
  1248. }
  1249. }
  1250. static inline void avg_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1251. int i,j;
  1252. for (i=0; i < height; i++) {
  1253. for (j=0; j < width; j++) {
  1254. dst[j] = (dst[j] + ((2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
  1255. }
  1256. src += stride;
  1257. dst += stride;
  1258. }
  1259. }
  1260. static inline void avg_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1261. int i,j;
  1262. for (i=0; i < height; i++) {
  1263. for (j=0; j < width; j++) {
  1264. dst[j] = (dst[j] + ((2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
  1265. }
  1266. src += stride;
  1267. dst += stride;
  1268. }
  1269. }
  1270. #if 0
  1271. #define TPEL_WIDTH(width)\
  1272. static void put_tpel_pixels ## width ## _mc00_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1273. void put_tpel_pixels_mc00_c(dst, src, stride, width, height);}\
  1274. static void put_tpel_pixels ## width ## _mc10_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1275. void put_tpel_pixels_mc10_c(dst, src, stride, width, height);}\
  1276. static void put_tpel_pixels ## width ## _mc20_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1277. void put_tpel_pixels_mc20_c(dst, src, stride, width, height);}\
  1278. static void put_tpel_pixels ## width ## _mc01_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1279. void put_tpel_pixels_mc01_c(dst, src, stride, width, height);}\
  1280. static void put_tpel_pixels ## width ## _mc11_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1281. void put_tpel_pixels_mc11_c(dst, src, stride, width, height);}\
  1282. static void put_tpel_pixels ## width ## _mc21_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1283. void put_tpel_pixels_mc21_c(dst, src, stride, width, height);}\
  1284. static void put_tpel_pixels ## width ## _mc02_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1285. void put_tpel_pixels_mc02_c(dst, src, stride, width, height);}\
  1286. static void put_tpel_pixels ## width ## _mc12_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1287. void put_tpel_pixels_mc12_c(dst, src, stride, width, height);}\
  1288. static void put_tpel_pixels ## width ## _mc22_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1289. void put_tpel_pixels_mc22_c(dst, src, stride, width, height);}
  1290. #endif
  1291. #define H264_CHROMA_MC(OPNAME, OP)\
  1292. static void OPNAME ## h264_chroma_mc2_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
  1293. const int A=(8-x)*(8-y);\
  1294. const int B=( x)*(8-y);\
  1295. const int C=(8-x)*( y);\
  1296. const int D=( x)*( y);\
  1297. int i;\
  1298. \
  1299. assert(x<8 && y<8 && x>=0 && y>=0);\
  1300. \
  1301. for(i=0; i<h; i++)\
  1302. {\
  1303. OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
  1304. OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
  1305. dst+= stride;\
  1306. src+= stride;\
  1307. }\
  1308. }\
  1309. \
  1310. static void OPNAME ## h264_chroma_mc4_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
  1311. const int A=(8-x)*(8-y);\
  1312. const int B=( x)*(8-y);\
  1313. const int C=(8-x)*( y);\
  1314. const int D=( x)*( y);\
  1315. int i;\
  1316. \
  1317. assert(x<8 && y<8 && x>=0 && y>=0);\
  1318. \
  1319. for(i=0; i<h; i++)\
  1320. {\
  1321. OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
  1322. OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
  1323. OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
  1324. OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
  1325. dst+= stride;\
  1326. src+= stride;\
  1327. }\
  1328. }\
  1329. \
  1330. static void OPNAME ## h264_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
  1331. const int A=(8-x)*(8-y);\
  1332. const int B=( x)*(8-y);\
  1333. const int C=(8-x)*( y);\
  1334. const int D=( x)*( y);\
  1335. int i;\
  1336. \
  1337. assert(x<8 && y<8 && x>=0 && y>=0);\
  1338. \
  1339. for(i=0; i<h; i++)\
  1340. {\
  1341. OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
  1342. OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
  1343. OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
  1344. OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
  1345. OP(dst[4], (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5]));\
  1346. OP(dst[5], (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6]));\
  1347. OP(dst[6], (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7]));\
  1348. OP(dst[7], (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8]));\
  1349. dst+= stride;\
  1350. src+= stride;\
  1351. }\
  1352. }
  1353. #define op_avg(a, b) a = (((a)+(((b) + 32)>>6)+1)>>1)
  1354. #define op_put(a, b) a = (((b) + 32)>>6)
  1355. H264_CHROMA_MC(put_ , op_put)
  1356. H264_CHROMA_MC(avg_ , op_avg)
  1357. #undef op_avg
  1358. #undef op_put
  1359. static inline void copy_block4(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  1360. {
  1361. int i;
  1362. for(i=0; i<h; i++)
  1363. {
  1364. ST32(dst , LD32(src ));
  1365. dst+=dstStride;
  1366. src+=srcStride;
  1367. }
  1368. }
  1369. static inline void copy_block8(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  1370. {
  1371. int i;
  1372. for(i=0; i<h; i++)
  1373. {
  1374. ST32(dst , LD32(src ));
  1375. ST32(dst+4 , LD32(src+4 ));
  1376. dst+=dstStride;
  1377. src+=srcStride;
  1378. }
  1379. }
  1380. static inline void copy_block16(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  1381. {
  1382. int i;
  1383. for(i=0; i<h; i++)
  1384. {
  1385. ST32(dst , LD32(src ));
  1386. ST32(dst+4 , LD32(src+4 ));
  1387. ST32(dst+8 , LD32(src+8 ));
  1388. ST32(dst+12, LD32(src+12));
  1389. dst+=dstStride;
  1390. src+=srcStride;
  1391. }
  1392. }
  1393. static inline void copy_block17(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  1394. {
  1395. int i;
  1396. for(i=0; i<h; i++)
  1397. {
  1398. ST32(dst , LD32(src ));
  1399. ST32(dst+4 , LD32(src+4 ));
  1400. ST32(dst+8 , LD32(src+8 ));
  1401. ST32(dst+12, LD32(src+12));
  1402. dst[16]= src[16];
  1403. dst+=dstStride;
  1404. src+=srcStride;
  1405. }
  1406. }
  1407. static inline void copy_block9(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  1408. {
  1409. int i;
  1410. for(i=0; i<h; i++)
  1411. {
  1412. ST32(dst , LD32(src ));
  1413. ST32(dst+4 , LD32(src+4 ));
  1414. dst[8]= src[8];
  1415. dst+=dstStride;
  1416. src+=srcStride;
  1417. }
  1418. }
  1419. #define QPEL_MC(r, OPNAME, RND, OP) \
  1420. static void OPNAME ## mpeg4_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  1421. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1422. int i;\
  1423. for(i=0; i<h; i++)\
  1424. {\
  1425. OP(dst[0], (src[0]+src[1])*20 - (src[0]+src[2])*6 + (src[1]+src[3])*3 - (src[2]+src[4]));\
  1426. OP(dst[1], (src[1]+src[2])*20 - (src[0]+src[3])*6 + (src[0]+src[4])*3 - (src[1]+src[5]));\
  1427. OP(dst[2], (src[2]+src[3])*20 - (src[1]+src[4])*6 + (src[0]+src[5])*3 - (src[0]+src[6]));\
  1428. OP(dst[3], (src[3]+src[4])*20 - (src[2]+src[5])*6 + (src[1]+src[6])*3 - (src[0]+src[7]));\
  1429. OP(dst[4], (src[4]+src[5])*20 - (src[3]+src[6])*6 + (src[2]+src[7])*3 - (src[1]+src[8]));\
  1430. OP(dst[5], (src[5]+src[6])*20 - (src[4]+src[7])*6 + (src[3]+src[8])*3 - (src[2]+src[8]));\
  1431. OP(dst[6], (src[6]+src[7])*20 - (src[5]+src[8])*6 + (src[4]+src[8])*3 - (src[3]+src[7]));\
  1432. OP(dst[7], (src[7]+src[8])*20 - (src[6]+src[8])*6 + (src[5]+src[7])*3 - (src[4]+src[6]));\
  1433. dst+=dstStride;\
  1434. src+=srcStride;\
  1435. }\
  1436. }\
  1437. \
  1438. static void OPNAME ## mpeg4_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1439. const int w=8;\
  1440. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1441. int i;\
  1442. for(i=0; i<w; i++)\
  1443. {\
  1444. const int src0= src[0*srcStride];\
  1445. const int src1= src[1*srcStride];\
  1446. const int src2= src[2*srcStride];\
  1447. const int src3= src[3*srcStride];\
  1448. const int src4= src[4*srcStride];\
  1449. const int src5= src[5*srcStride];\
  1450. const int src6= src[6*srcStride];\
  1451. const int src7= src[7*srcStride];\
  1452. const int src8= src[8*srcStride];\
  1453. OP(dst[0*dstStride], (src0+src1)*20 - (src0+src2)*6 + (src1+src3)*3 - (src2+src4));\
  1454. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*6 + (src0+src4)*3 - (src1+src5));\
  1455. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*6 + (src0+src5)*3 - (src0+src6));\
  1456. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*6 + (src1+src6)*3 - (src0+src7));\
  1457. OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*6 + (src2+src7)*3 - (src1+src8));\
  1458. OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*6 + (src3+src8)*3 - (src2+src8));\
  1459. OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*6 + (src4+src8)*3 - (src3+src7));\
  1460. OP(dst[7*dstStride], (src7+src8)*20 - (src6+src8)*6 + (src5+src7)*3 - (src4+src6));\
  1461. dst++;\
  1462. src++;\
  1463. }\
  1464. }\
  1465. \
  1466. static void OPNAME ## mpeg4_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  1467. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1468. int i;\
  1469. \
  1470. for(i=0; i<h; i++)\
  1471. {\
  1472. OP(dst[ 0], (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]));\
  1473. OP(dst[ 1], (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]));\
  1474. OP(dst[ 2], (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]));\
  1475. OP(dst[ 3], (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]));\
  1476. OP(dst[ 4], (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]));\
  1477. OP(dst[ 5], (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]));\
  1478. OP(dst[ 6], (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]));\
  1479. OP(dst[ 7], (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]));\
  1480. OP(dst[ 8], (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]));\
  1481. OP(dst[ 9], (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]));\
  1482. OP(dst[10], (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]));\
  1483. OP(dst[11], (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]));\
  1484. OP(dst[12], (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]));\
  1485. OP(dst[13], (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]));\
  1486. OP(dst[14], (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]));\
  1487. OP(dst[15], (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]));\
  1488. dst+=dstStride;\
  1489. src+=srcStride;\
  1490. }\
  1491. }\
  1492. \
  1493. static void OPNAME ## mpeg4_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1494. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1495. int i;\
  1496. const int w=16;\
  1497. for(i=0; i<w; i++)\
  1498. {\
  1499. const int src0= src[0*srcStride];\
  1500. const int src1= src[1*srcStride];\
  1501. const int src2= src[2*srcStride];\
  1502. const int src3= src[3*srcStride];\
  1503. const int src4= src[4*srcStride];\
  1504. const int src5= src[5*srcStride];\
  1505. const int src6= src[6*srcStride];\
  1506. const int src7= src[7*srcStride];\
  1507. const int src8= src[8*srcStride];\
  1508. const int src9= src[9*srcStride];\
  1509. const int src10= src[10*srcStride];\
  1510. const int src11= src[11*srcStride];\
  1511. const int src12= src[12*srcStride];\
  1512. const int src13= src[13*srcStride];\
  1513. const int src14= src[14*srcStride];\
  1514. const int src15= src[15*srcStride];\
  1515. const int src16= src[16*srcStride];\
  1516. OP(dst[ 0*dstStride], (src0 +src1 )*20 - (src0 +src2 )*6 + (src1 +src3 )*3 - (src2 +src4 ));\
  1517. OP(dst[ 1*dstStride], (src1 +src2 )*20 - (src0 +src3 )*6 + (src0 +src4 )*3 - (src1 +src5 ));\
  1518. OP(dst[ 2*dstStride], (src2 +src3 )*20 - (src1 +src4 )*6 + (src0 +src5 )*3 - (src0 +src6 ));\
  1519. OP(dst[ 3*dstStride], (src3 +src4 )*20 - (src2 +src5 )*6 + (src1 +src6 )*3 - (src0 +src7 ));\
  1520. OP(dst[ 4*dstStride], (src4 +src5 )*20 - (src3 +src6 )*6 + (src2 +src7 )*3 - (src1 +src8 ));\
  1521. OP(dst[ 5*dstStride], (src5 +src6 )*20 - (src4 +src7 )*6 + (src3 +src8 )*3 - (src2 +src9 ));\
  1522. OP(dst[ 6*dstStride], (src6 +src7 )*20 - (src5 +src8 )*6 + (src4 +src9 )*3 - (src3 +src10));\
  1523. OP(dst[ 7*dstStride], (src7 +src8 )*20 - (src6 +src9 )*6 + (src5 +src10)*3 - (src4 +src11));\
  1524. OP(dst[ 8*dstStride], (src8 +src9 )*20 - (src7 +src10)*6 + (src6 +src11)*3 - (src5 +src12));\
  1525. OP(dst[ 9*dstStride], (src9 +src10)*20 - (src8 +src11)*6 + (src7 +src12)*3 - (src6 +src13));\
  1526. OP(dst[10*dstStride], (src10+src11)*20 - (src9 +src12)*6 + (src8 +src13)*3 - (src7 +src14));\
  1527. OP(dst[11*dstStride], (src11+src12)*20 - (src10+src13)*6 + (src9 +src14)*3 - (src8 +src15));\
  1528. OP(dst[12*dstStride], (src12+src13)*20 - (src11+src14)*6 + (src10+src15)*3 - (src9 +src16));\
  1529. OP(dst[13*dstStride], (src13+src14)*20 - (src12+src15)*6 + (src11+src16)*3 - (src10+src16));\
  1530. OP(dst[14*dstStride], (src14+src15)*20 - (src13+src16)*6 + (src12+src16)*3 - (src11+src15));\
  1531. OP(dst[15*dstStride], (src15+src16)*20 - (src14+src16)*6 + (src13+src15)*3 - (src12+src14));\
  1532. dst++;\
  1533. src++;\
  1534. }\
  1535. }\
  1536. \
  1537. static void OPNAME ## qpel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
  1538. OPNAME ## pixels8_c(dst, src, stride, 8);\
  1539. }\
  1540. \
  1541. static void OPNAME ## qpel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  1542. uint8_t half[64];\
  1543. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  1544. OPNAME ## pixels8_l2(dst, src, half, stride, stride, 8, 8);\
  1545. }\
  1546. \
  1547. static void OPNAME ## qpel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  1548. OPNAME ## mpeg4_qpel8_h_lowpass(dst, src, stride, stride, 8);\
  1549. }\
  1550. \
  1551. static void OPNAME ## qpel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  1552. uint8_t half[64];\
  1553. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  1554. OPNAME ## pixels8_l2(dst, src+1, half, stride, stride, 8, 8);\
  1555. }\
  1556. \
  1557. static void OPNAME ## qpel8_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  1558. uint8_t full[16*9];\
  1559. uint8_t half[64];\
  1560. copy_block9(full, src, 16, stride, 9);\
  1561. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
  1562. OPNAME ## pixels8_l2(dst, full, half, stride, 16, 8, 8);\
  1563. }\
  1564. \
  1565. static void OPNAME ## qpel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  1566. uint8_t full[16*9];\
  1567. copy_block9(full, src, 16, stride, 9);\
  1568. OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);\
  1569. }\
  1570. \
  1571. static void OPNAME ## qpel8_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  1572. uint8_t full[16*9];\
  1573. uint8_t half[64];\
  1574. copy_block9(full, src, 16, stride, 9);\
  1575. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
  1576. OPNAME ## pixels8_l2(dst, full+16, half, stride, 16, 8, 8);\
  1577. }\
  1578. void ff_ ## OPNAME ## qpel8_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1579. uint8_t full[16*9];\
  1580. uint8_t halfH[72];\
  1581. uint8_t halfV[64];\
  1582. uint8_t halfHV[64];\
  1583. copy_block9(full, src, 16, stride, 9);\
  1584. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1585. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  1586. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1587. OPNAME ## pixels8_l4(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1588. }\
  1589. static void OPNAME ## qpel8_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  1590. uint8_t full[16*9];\
  1591. uint8_t halfH[72];\
  1592. uint8_t halfHV[64];\
  1593. copy_block9(full, src, 16, stride, 9);\
  1594. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1595. put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
  1596. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1597. OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
  1598. }\
  1599. void ff_ ## OPNAME ## qpel8_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1600. uint8_t full[16*9];\
  1601. uint8_t halfH[72];\
  1602. uint8_t halfV[64];\
  1603. uint8_t halfHV[64];\
  1604. copy_block9(full, src, 16, stride, 9);\
  1605. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1606. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  1607. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1608. OPNAME ## pixels8_l4(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1609. }\
  1610. static void OPNAME ## qpel8_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  1611. uint8_t full[16*9];\
  1612. uint8_t halfH[72];\
  1613. uint8_t halfHV[64];\
  1614. copy_block9(full, src, 16, stride, 9);\
  1615. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1616. put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
  1617. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1618. OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
  1619. }\
  1620. void ff_ ## OPNAME ## qpel8_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1621. uint8_t full[16*9];\
  1622. uint8_t halfH[72];\
  1623. uint8_t halfV[64];\
  1624. uint8_t halfHV[64];\
  1625. copy_block9(full, src, 16, stride, 9);\
  1626. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1627. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  1628. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1629. OPNAME ## pixels8_l4(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1630. }\
  1631. static void OPNAME ## qpel8_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  1632. uint8_t full[16*9];\
  1633. uint8_t halfH[72];\
  1634. uint8_t halfHV[64];\
  1635. copy_block9(full, src, 16, stride, 9);\
  1636. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1637. put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
  1638. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1639. OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  1640. }\
  1641. void ff_ ## OPNAME ## qpel8_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1642. uint8_t full[16*9];\
  1643. uint8_t halfH[72];\
  1644. uint8_t halfV[64];\
  1645. uint8_t halfHV[64];\
  1646. copy_block9(full, src, 16, stride, 9);\
  1647. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full , 8, 16, 9);\
  1648. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  1649. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1650. OPNAME ## pixels8_l4(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1651. }\
  1652. static void OPNAME ## qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  1653. uint8_t full[16*9];\
  1654. uint8_t halfH[72];\
  1655. uint8_t halfHV[64];\
  1656. copy_block9(full, src, 16, stride, 9);\
  1657. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1658. put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
  1659. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1660. OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  1661. }\
  1662. static void OPNAME ## qpel8_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  1663. uint8_t halfH[72];\
  1664. uint8_t halfHV[64];\
  1665. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1666. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1667. OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
  1668. }\
  1669. static void OPNAME ## qpel8_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  1670. uint8_t halfH[72];\
  1671. uint8_t halfHV[64];\
  1672. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1673. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1674. OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  1675. }\
  1676. void ff_ ## OPNAME ## qpel8_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1677. uint8_t full[16*9];\
  1678. uint8_t halfH[72];\
  1679. uint8_t halfV[64];\
  1680. uint8_t halfHV[64];\
  1681. copy_block9(full, src, 16, stride, 9);\
  1682. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1683. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  1684. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1685. OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
  1686. }\
  1687. static void OPNAME ## qpel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  1688. uint8_t full[16*9];\
  1689. uint8_t halfH[72];\
  1690. copy_block9(full, src, 16, stride, 9);\
  1691. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1692. put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
  1693. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1694. }\
  1695. void ff_ ## OPNAME ## qpel8_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1696. uint8_t full[16*9];\
  1697. uint8_t halfH[72];\
  1698. uint8_t halfV[64];\
  1699. uint8_t halfHV[64];\
  1700. copy_block9(full, src, 16, stride, 9);\
  1701. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1702. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  1703. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1704. OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
  1705. }\
  1706. static void OPNAME ## qpel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  1707. uint8_t full[16*9];\
  1708. uint8_t halfH[72];\
  1709. copy_block9(full, src, 16, stride, 9);\
  1710. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1711. put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
  1712. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1713. }\
  1714. static void OPNAME ## qpel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  1715. uint8_t halfH[72];\
  1716. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1717. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1718. }\
  1719. static void OPNAME ## qpel16_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
  1720. OPNAME ## pixels16_c(dst, src, stride, 16);\
  1721. }\
  1722. \
  1723. static void OPNAME ## qpel16_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  1724. uint8_t half[256];\
  1725. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  1726. OPNAME ## pixels16_l2(dst, src, half, stride, stride, 16, 16);\
  1727. }\
  1728. \
  1729. static void OPNAME ## qpel16_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  1730. OPNAME ## mpeg4_qpel16_h_lowpass(dst, src, stride, stride, 16);\
  1731. }\
  1732. \
  1733. static void OPNAME ## qpel16_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  1734. uint8_t half[256];\
  1735. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  1736. OPNAME ## pixels16_l2(dst, src+1, half, stride, stride, 16, 16);\
  1737. }\
  1738. \
  1739. static void OPNAME ## qpel16_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  1740. uint8_t full[24*17];\
  1741. uint8_t half[256];\
  1742. copy_block17(full, src, 24, stride, 17);\
  1743. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
  1744. OPNAME ## pixels16_l2(dst, full, half, stride, 24, 16, 16);\
  1745. }\
  1746. \
  1747. static void OPNAME ## qpel16_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  1748. uint8_t full[24*17];\
  1749. copy_block17(full, src, 24, stride, 17);\
  1750. OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);\
  1751. }\
  1752. \
  1753. static void OPNAME ## qpel16_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  1754. uint8_t full[24*17];\
  1755. uint8_t half[256];\
  1756. copy_block17(full, src, 24, stride, 17);\
  1757. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
  1758. OPNAME ## pixels16_l2(dst, full+24, half, stride, 24, 16, 16);\
  1759. }\
  1760. void ff_ ## OPNAME ## qpel16_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1761. uint8_t full[24*17];\
  1762. uint8_t halfH[272];\
  1763. uint8_t halfV[256];\
  1764. uint8_t halfHV[256];\
  1765. copy_block17(full, src, 24, stride, 17);\
  1766. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1767. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1768. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1769. OPNAME ## pixels16_l4(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1770. }\
  1771. static void OPNAME ## qpel16_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  1772. uint8_t full[24*17];\
  1773. uint8_t halfH[272];\
  1774. uint8_t halfHV[256];\
  1775. copy_block17(full, src, 24, stride, 17);\
  1776. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1777. put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
  1778. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1779. OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
  1780. }\
  1781. void ff_ ## OPNAME ## qpel16_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1782. uint8_t full[24*17];\
  1783. uint8_t halfH[272];\
  1784. uint8_t halfV[256];\
  1785. uint8_t halfHV[256];\
  1786. copy_block17(full, src, 24, stride, 17);\
  1787. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1788. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1789. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1790. OPNAME ## pixels16_l4(dst, full+1, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1791. }\
  1792. static void OPNAME ## qpel16_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  1793. uint8_t full[24*17];\
  1794. uint8_t halfH[272];\
  1795. uint8_t halfHV[256];\
  1796. copy_block17(full, src, 24, stride, 17);\
  1797. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1798. put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
  1799. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1800. OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
  1801. }\
  1802. void ff_ ## OPNAME ## qpel16_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1803. uint8_t full[24*17];\
  1804. uint8_t halfH[272];\
  1805. uint8_t halfV[256];\
  1806. uint8_t halfHV[256];\
  1807. copy_block17(full, src, 24, stride, 17);\
  1808. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1809. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1810. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1811. OPNAME ## pixels16_l4(dst, full+24, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1812. }\
  1813. static void OPNAME ## qpel16_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  1814. uint8_t full[24*17];\
  1815. uint8_t halfH[272];\
  1816. uint8_t halfHV[256];\
  1817. copy_block17(full, src, 24, stride, 17);\
  1818. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1819. put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
  1820. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1821. OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1822. }\
  1823. void ff_ ## OPNAME ## qpel16_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1824. uint8_t full[24*17];\
  1825. uint8_t halfH[272];\
  1826. uint8_t halfV[256];\
  1827. uint8_t halfHV[256];\
  1828. copy_block17(full, src, 24, stride, 17);\
  1829. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full , 16, 24, 17);\
  1830. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1831. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1832. OPNAME ## pixels16_l4(dst, full+25, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1833. }\
  1834. static void OPNAME ## qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  1835. uint8_t full[24*17];\
  1836. uint8_t halfH[272];\
  1837. uint8_t halfHV[256];\
  1838. copy_block17(full, src, 24, stride, 17);\
  1839. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1840. put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
  1841. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1842. OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1843. }\
  1844. static void OPNAME ## qpel16_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  1845. uint8_t halfH[272];\
  1846. uint8_t halfHV[256];\
  1847. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1848. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1849. OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
  1850. }\
  1851. static void OPNAME ## qpel16_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  1852. uint8_t halfH[272];\
  1853. uint8_t halfHV[256];\
  1854. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1855. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1856. OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1857. }\
  1858. void ff_ ## OPNAME ## qpel16_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1859. uint8_t full[24*17];\
  1860. uint8_t halfH[272];\
  1861. uint8_t halfV[256];\
  1862. uint8_t halfHV[256];\
  1863. copy_block17(full, src, 24, stride, 17);\
  1864. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1865. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1866. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1867. OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
  1868. }\
  1869. static void OPNAME ## qpel16_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  1870. uint8_t full[24*17];\
  1871. uint8_t halfH[272];\
  1872. copy_block17(full, src, 24, stride, 17);\
  1873. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1874. put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
  1875. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1876. }\
  1877. void ff_ ## OPNAME ## qpel16_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1878. uint8_t full[24*17];\
  1879. uint8_t halfH[272];\
  1880. uint8_t halfV[256];\
  1881. uint8_t halfHV[256];\
  1882. copy_block17(full, src, 24, stride, 17);\
  1883. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1884. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1885. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1886. OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
  1887. }\
  1888. static void OPNAME ## qpel16_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  1889. uint8_t full[24*17];\
  1890. uint8_t halfH[272];\
  1891. copy_block17(full, src, 24, stride, 17);\
  1892. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1893. put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
  1894. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1895. }\
  1896. static void OPNAME ## qpel16_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  1897. uint8_t halfH[272];\
  1898. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1899. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1900. }
  1901. #define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
  1902. #define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1)
  1903. #define op_put(a, b) a = cm[((b) + 16)>>5]
  1904. #define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5]
  1905. QPEL_MC(0, put_ , _ , op_put)
  1906. QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd)
  1907. QPEL_MC(0, avg_ , _ , op_avg)
  1908. //QPEL_MC(1, avg_no_rnd , _ , op_avg)
  1909. #undef op_avg
  1910. #undef op_avg_no_rnd
  1911. #undef op_put
  1912. #undef op_put_no_rnd
  1913. #if 1
  1914. #define H264_LOWPASS(OPNAME, OP, OP2) \
  1915. static void OPNAME ## h264_qpel4_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1916. const int h=4;\
  1917. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1918. int i;\
  1919. for(i=0; i<h; i++)\
  1920. {\
  1921. OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
  1922. OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
  1923. OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]));\
  1924. OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]));\
  1925. dst+=dstStride;\
  1926. src+=srcStride;\
  1927. }\
  1928. }\
  1929. \
  1930. static void OPNAME ## h264_qpel4_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1931. const int w=4;\
  1932. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1933. int i;\
  1934. for(i=0; i<w; i++)\
  1935. {\
  1936. const int srcB= src[-2*srcStride];\
  1937. const int srcA= src[-1*srcStride];\
  1938. const int src0= src[0 *srcStride];\
  1939. const int src1= src[1 *srcStride];\
  1940. const int src2= src[2 *srcStride];\
  1941. const int src3= src[3 *srcStride];\
  1942. const int src4= src[4 *srcStride];\
  1943. const int src5= src[5 *srcStride];\
  1944. const int src6= src[6 *srcStride];\
  1945. OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
  1946. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
  1947. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
  1948. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
  1949. dst++;\
  1950. src++;\
  1951. }\
  1952. }\
  1953. \
  1954. static void OPNAME ## h264_qpel4_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  1955. const int h=4;\
  1956. const int w=4;\
  1957. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1958. int i;\
  1959. src -= 2*srcStride;\
  1960. for(i=0; i<h+5; i++)\
  1961. {\
  1962. tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
  1963. tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
  1964. tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]);\
  1965. tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]);\
  1966. tmp+=tmpStride;\
  1967. src+=srcStride;\
  1968. }\
  1969. tmp -= tmpStride*(h+5-2);\
  1970. for(i=0; i<w; i++)\
  1971. {\
  1972. const int tmpB= tmp[-2*tmpStride];\
  1973. const int tmpA= tmp[-1*tmpStride];\
  1974. const int tmp0= tmp[0 *tmpStride];\
  1975. const int tmp1= tmp[1 *tmpStride];\
  1976. const int tmp2= tmp[2 *tmpStride];\
  1977. const int tmp3= tmp[3 *tmpStride];\
  1978. const int tmp4= tmp[4 *tmpStride];\
  1979. const int tmp5= tmp[5 *tmpStride];\
  1980. const int tmp6= tmp[6 *tmpStride];\
  1981. OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
  1982. OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
  1983. OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
  1984. OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
  1985. dst++;\
  1986. tmp++;\
  1987. }\
  1988. }\
  1989. \
  1990. static void OPNAME ## h264_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1991. const int h=8;\
  1992. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1993. int i;\
  1994. for(i=0; i<h; i++)\
  1995. {\
  1996. OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]));\
  1997. OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]));\
  1998. OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]));\
  1999. OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]));\
  2000. OP(dst[4], (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]));\
  2001. OP(dst[5], (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]));\
  2002. OP(dst[6], (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]));\
  2003. OP(dst[7], (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]));\
  2004. dst+=dstStride;\
  2005. src+=srcStride;\
  2006. }\
  2007. }\
  2008. \
  2009. static void OPNAME ## h264_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2010. const int w=8;\
  2011. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  2012. int i;\
  2013. for(i=0; i<w; i++)\
  2014. {\
  2015. const int srcB= src[-2*srcStride];\
  2016. const int srcA= src[-1*srcStride];\
  2017. const int src0= src[0 *srcStride];\
  2018. const int src1= src[1 *srcStride];\
  2019. const int src2= src[2 *srcStride];\
  2020. const int src3= src[3 *srcStride];\
  2021. const int src4= src[4 *srcStride];\
  2022. const int src5= src[5 *srcStride];\
  2023. const int src6= src[6 *srcStride];\
  2024. const int src7= src[7 *srcStride];\
  2025. const int src8= src[8 *srcStride];\
  2026. const int src9= src[9 *srcStride];\
  2027. const int src10=src[10*srcStride];\
  2028. OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
  2029. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
  2030. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
  2031. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
  2032. OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*5 + (src2+src7));\
  2033. OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*5 + (src3+src8));\
  2034. OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*5 + (src4+src9));\
  2035. OP(dst[7*dstStride], (src7+src8)*20 - (src6+src9)*5 + (src5+src10));\
  2036. dst++;\
  2037. src++;\
  2038. }\
  2039. }\
  2040. \
  2041. static void OPNAME ## h264_qpel8_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  2042. const int h=8;\
  2043. const int w=8;\
  2044. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  2045. int i;\
  2046. src -= 2*srcStride;\
  2047. for(i=0; i<h+5; i++)\
  2048. {\
  2049. tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]);\
  2050. tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]);\
  2051. tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]);\
  2052. tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]);\
  2053. tmp[4]= (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]);\
  2054. tmp[5]= (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]);\
  2055. tmp[6]= (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]);\
  2056. tmp[7]= (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]);\
  2057. tmp+=tmpStride;\
  2058. src+=srcStride;\
  2059. }\
  2060. tmp -= tmpStride*(h+5-2);\
  2061. for(i=0; i<w; i++)\
  2062. {\
  2063. const int tmpB= tmp[-2*tmpStride];\
  2064. const int tmpA= tmp[-1*tmpStride];\
  2065. const int tmp0= tmp[0 *tmpStride];\
  2066. const int tmp1= tmp[1 *tmpStride];\
  2067. const int tmp2= tmp[2 *tmpStride];\
  2068. const int tmp3= tmp[3 *tmpStride];\
  2069. const int tmp4= tmp[4 *tmpStride];\
  2070. const int tmp5= tmp[5 *tmpStride];\
  2071. const int tmp6= tmp[6 *tmpStride];\
  2072. const int tmp7= tmp[7 *tmpStride];\
  2073. const int tmp8= tmp[8 *tmpStride];\
  2074. const int tmp9= tmp[9 *tmpStride];\
  2075. const int tmp10=tmp[10*tmpStride];\
  2076. OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
  2077. OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
  2078. OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
  2079. OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
  2080. OP2(dst[4*dstStride], (tmp4+tmp5)*20 - (tmp3+tmp6)*5 + (tmp2+tmp7));\
  2081. OP2(dst[5*dstStride], (tmp5+tmp6)*20 - (tmp4+tmp7)*5 + (tmp3+tmp8));\
  2082. OP2(dst[6*dstStride], (tmp6+tmp7)*20 - (tmp5+tmp8)*5 + (tmp4+tmp9));\
  2083. OP2(dst[7*dstStride], (tmp7+tmp8)*20 - (tmp6+tmp9)*5 + (tmp5+tmp10));\
  2084. dst++;\
  2085. tmp++;\
  2086. }\
  2087. }\
  2088. \
  2089. static void OPNAME ## h264_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2090. OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
  2091. OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
  2092. src += 8*srcStride;\
  2093. dst += 8*dstStride;\
  2094. OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
  2095. OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
  2096. }\
  2097. \
  2098. static void OPNAME ## h264_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2099. OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
  2100. OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
  2101. src += 8*srcStride;\
  2102. dst += 8*dstStride;\
  2103. OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
  2104. OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
  2105. }\
  2106. \
  2107. static void OPNAME ## h264_qpel16_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  2108. OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
  2109. OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
  2110. src += 8*srcStride;\
  2111. dst += 8*dstStride;\
  2112. OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
  2113. OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
  2114. }\
  2115. #define H264_MC(OPNAME, SIZE) \
  2116. static void OPNAME ## h264_qpel ## SIZE ## _mc00_c (uint8_t *dst, uint8_t *src, int stride){\
  2117. OPNAME ## pixels ## SIZE ## _c(dst, src, stride, SIZE);\
  2118. }\
  2119. \
  2120. static void OPNAME ## h264_qpel ## SIZE ## _mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  2121. uint8_t half[SIZE*SIZE];\
  2122. put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
  2123. OPNAME ## pixels ## SIZE ## _l2(dst, src, half, stride, stride, SIZE, SIZE);\
  2124. }\
  2125. \
  2126. static void OPNAME ## h264_qpel ## SIZE ## _mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  2127. OPNAME ## h264_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride);\
  2128. }\
  2129. \
  2130. static void OPNAME ## h264_qpel ## SIZE ## _mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  2131. uint8_t half[SIZE*SIZE];\
  2132. put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
  2133. OPNAME ## pixels ## SIZE ## _l2(dst, src+1, half, stride, stride, SIZE, SIZE);\
  2134. }\
  2135. \
  2136. static void OPNAME ## h264_qpel ## SIZE ## _mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  2137. uint8_t full[SIZE*(SIZE+5)];\
  2138. uint8_t * const full_mid= full + SIZE*2;\
  2139. uint8_t half[SIZE*SIZE];\
  2140. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2141. put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
  2142. OPNAME ## pixels ## SIZE ## _l2(dst, full_mid, half, stride, SIZE, SIZE, SIZE);\
  2143. }\
  2144. \
  2145. static void OPNAME ## h264_qpel ## SIZE ## _mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  2146. uint8_t full[SIZE*(SIZE+5)];\
  2147. uint8_t * const full_mid= full + SIZE*2;\
  2148. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2149. OPNAME ## h264_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE);\
  2150. }\
  2151. \
  2152. static void OPNAME ## h264_qpel ## SIZE ## _mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  2153. uint8_t full[SIZE*(SIZE+5)];\
  2154. uint8_t * const full_mid= full + SIZE*2;\
  2155. uint8_t half[SIZE*SIZE];\
  2156. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2157. put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
  2158. OPNAME ## pixels ## SIZE ## _l2(dst, full_mid+SIZE, half, stride, SIZE, SIZE, SIZE);\
  2159. }\
  2160. \
  2161. static void OPNAME ## h264_qpel ## SIZE ## _mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  2162. uint8_t full[SIZE*(SIZE+5)];\
  2163. uint8_t * const full_mid= full + SIZE*2;\
  2164. uint8_t halfH[SIZE*SIZE];\
  2165. uint8_t halfV[SIZE*SIZE];\
  2166. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
  2167. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2168. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2169. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2170. }\
  2171. \
  2172. static void OPNAME ## h264_qpel ## SIZE ## _mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  2173. uint8_t full[SIZE*(SIZE+5)];\
  2174. uint8_t * const full_mid= full + SIZE*2;\
  2175. uint8_t halfH[SIZE*SIZE];\
  2176. uint8_t halfV[SIZE*SIZE];\
  2177. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
  2178. copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
  2179. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2180. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2181. }\
  2182. \
  2183. static void OPNAME ## h264_qpel ## SIZE ## _mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  2184. uint8_t full[SIZE*(SIZE+5)];\
  2185. uint8_t * const full_mid= full + SIZE*2;\
  2186. uint8_t halfH[SIZE*SIZE];\
  2187. uint8_t halfV[SIZE*SIZE];\
  2188. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
  2189. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2190. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2191. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2192. }\
  2193. \
  2194. static void OPNAME ## h264_qpel ## SIZE ## _mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  2195. uint8_t full[SIZE*(SIZE+5)];\
  2196. uint8_t * const full_mid= full + SIZE*2;\
  2197. uint8_t halfH[SIZE*SIZE];\
  2198. uint8_t halfV[SIZE*SIZE];\
  2199. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
  2200. copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
  2201. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2202. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2203. }\
  2204. \
  2205. static void OPNAME ## h264_qpel ## SIZE ## _mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  2206. int16_t tmp[SIZE*(SIZE+5)];\
  2207. OPNAME ## h264_qpel ## SIZE ## _hv_lowpass(dst, tmp, src, stride, SIZE, stride);\
  2208. }\
  2209. \
  2210. static void OPNAME ## h264_qpel ## SIZE ## _mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  2211. int16_t tmp[SIZE*(SIZE+5)];\
  2212. uint8_t halfH[SIZE*SIZE];\
  2213. uint8_t halfHV[SIZE*SIZE];\
  2214. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
  2215. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2216. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
  2217. }\
  2218. \
  2219. static void OPNAME ## h264_qpel ## SIZE ## _mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  2220. int16_t tmp[SIZE*(SIZE+5)];\
  2221. uint8_t halfH[SIZE*SIZE];\
  2222. uint8_t halfHV[SIZE*SIZE];\
  2223. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
  2224. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2225. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
  2226. }\
  2227. \
  2228. static void OPNAME ## h264_qpel ## SIZE ## _mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  2229. uint8_t full[SIZE*(SIZE+5)];\
  2230. uint8_t * const full_mid= full + SIZE*2;\
  2231. int16_t tmp[SIZE*(SIZE+5)];\
  2232. uint8_t halfV[SIZE*SIZE];\
  2233. uint8_t halfHV[SIZE*SIZE];\
  2234. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2235. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2236. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2237. OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
  2238. }\
  2239. \
  2240. static void OPNAME ## h264_qpel ## SIZE ## _mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  2241. uint8_t full[SIZE*(SIZE+5)];\
  2242. uint8_t * const full_mid= full + SIZE*2;\
  2243. int16_t tmp[SIZE*(SIZE+5)];\
  2244. uint8_t halfV[SIZE*SIZE];\
  2245. uint8_t halfHV[SIZE*SIZE];\
  2246. copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
  2247. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2248. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2249. OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
  2250. }\
  2251. #define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
  2252. //#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7)
  2253. #define op_put(a, b) a = cm[((b) + 16)>>5]
  2254. #define op2_avg(a, b) a = (((a)+cm[((b) + 512)>>10]+1)>>1)
  2255. #define op2_put(a, b) a = cm[((b) + 512)>>10]
  2256. H264_LOWPASS(put_ , op_put, op2_put)
  2257. H264_LOWPASS(avg_ , op_avg, op2_avg)
  2258. H264_MC(put_, 4)
  2259. H264_MC(put_, 8)
  2260. H264_MC(put_, 16)
  2261. H264_MC(avg_, 4)
  2262. H264_MC(avg_, 8)
  2263. H264_MC(avg_, 16)
  2264. #undef op_avg
  2265. #undef op_put
  2266. #undef op2_avg
  2267. #undef op2_put
  2268. #endif
  2269. static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){
  2270. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  2271. int i;
  2272. for(i=0; i<h; i++){
  2273. dst[0]= cm[(9*(src[0] + src[1]) - (src[-1] + src[2]) + 8)>>4];
  2274. dst[1]= cm[(9*(src[1] + src[2]) - (src[ 0] + src[3]) + 8)>>4];
  2275. dst[2]= cm[(9*(src[2] + src[3]) - (src[ 1] + src[4]) + 8)>>4];
  2276. dst[3]= cm[(9*(src[3] + src[4]) - (src[ 2] + src[5]) + 8)>>4];
  2277. dst[4]= cm[(9*(src[4] + src[5]) - (src[ 3] + src[6]) + 8)>>4];
  2278. dst[5]= cm[(9*(src[5] + src[6]) - (src[ 4] + src[7]) + 8)>>4];
  2279. dst[6]= cm[(9*(src[6] + src[7]) - (src[ 5] + src[8]) + 8)>>4];
  2280. dst[7]= cm[(9*(src[7] + src[8]) - (src[ 6] + src[9]) + 8)>>4];
  2281. dst+=dstStride;
  2282. src+=srcStride;
  2283. }
  2284. }
  2285. static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){
  2286. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  2287. int i;
  2288. for(i=0; i<w; i++){
  2289. const int src_1= src[ -srcStride];
  2290. const int src0 = src[0 ];
  2291. const int src1 = src[ srcStride];
  2292. const int src2 = src[2*srcStride];
  2293. const int src3 = src[3*srcStride];
  2294. const int src4 = src[4*srcStride];
  2295. const int src5 = src[5*srcStride];
  2296. const int src6 = src[6*srcStride];
  2297. const int src7 = src[7*srcStride];
  2298. const int src8 = src[8*srcStride];
  2299. const int src9 = src[9*srcStride];
  2300. dst[0*dstStride]= cm[(9*(src0 + src1) - (src_1 + src2) + 8)>>4];
  2301. dst[1*dstStride]= cm[(9*(src1 + src2) - (src0 + src3) + 8)>>4];
  2302. dst[2*dstStride]= cm[(9*(src2 + src3) - (src1 + src4) + 8)>>4];
  2303. dst[3*dstStride]= cm[(9*(src3 + src4) - (src2 + src5) + 8)>>4];
  2304. dst[4*dstStride]= cm[(9*(src4 + src5) - (src3 + src6) + 8)>>4];
  2305. dst[5*dstStride]= cm[(9*(src5 + src6) - (src4 + src7) + 8)>>4];
  2306. dst[6*dstStride]= cm[(9*(src6 + src7) - (src5 + src8) + 8)>>4];
  2307. dst[7*dstStride]= cm[(9*(src7 + src8) - (src6 + src9) + 8)>>4];
  2308. src++;
  2309. dst++;
  2310. }
  2311. }
  2312. static void put_mspel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){
  2313. put_pixels8_c(dst, src, stride, 8);
  2314. }
  2315. static void put_mspel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){
  2316. uint8_t half[64];
  2317. wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
  2318. put_pixels8_l2(dst, src, half, stride, stride, 8, 8);
  2319. }
  2320. static void put_mspel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){
  2321. wmv2_mspel8_h_lowpass(dst, src, stride, stride, 8);
  2322. }
  2323. static void put_mspel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){
  2324. uint8_t half[64];
  2325. wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
  2326. put_pixels8_l2(dst, src+1, half, stride, stride, 8, 8);
  2327. }
  2328. static void put_mspel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){
  2329. wmv2_mspel8_v_lowpass(dst, src, stride, stride, 8);
  2330. }
  2331. static void put_mspel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){
  2332. uint8_t halfH[88];
  2333. uint8_t halfV[64];
  2334. uint8_t halfHV[64];
  2335. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  2336. wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8);
  2337. wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
  2338. put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
  2339. }
  2340. static void put_mspel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){
  2341. uint8_t halfH[88];
  2342. uint8_t halfV[64];
  2343. uint8_t halfHV[64];
  2344. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  2345. wmv2_mspel8_v_lowpass(halfV, src+1, 8, stride, 8);
  2346. wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
  2347. put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
  2348. }
  2349. static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){
  2350. uint8_t halfH[88];
  2351. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  2352. wmv2_mspel8_v_lowpass(dst, halfH+8, stride, 8, 8);
  2353. }
  2354. static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale){
  2355. int x;
  2356. const int strength= ff_h263_loop_filter_strength[qscale];
  2357. for(x=0; x<8; x++){
  2358. int d1, d2, ad1;
  2359. int p0= src[x-2*stride];
  2360. int p1= src[x-1*stride];
  2361. int p2= src[x+0*stride];
  2362. int p3= src[x+1*stride];
  2363. int d = (p0 - p3 + 4*(p2 - p1)) / 8;
  2364. if (d<-2*strength) d1= 0;
  2365. else if(d<- strength) d1=-2*strength - d;
  2366. else if(d< strength) d1= d;
  2367. else if(d< 2*strength) d1= 2*strength - d;
  2368. else d1= 0;
  2369. p1 += d1;
  2370. p2 -= d1;
  2371. if(p1&256) p1= ~(p1>>31);
  2372. if(p2&256) p2= ~(p2>>31);
  2373. src[x-1*stride] = p1;
  2374. src[x+0*stride] = p2;
  2375. ad1= ABS(d1)>>1;
  2376. d2= clip((p0-p3)/4, -ad1, ad1);
  2377. src[x-2*stride] = p0 - d2;
  2378. src[x+ stride] = p3 + d2;
  2379. }
  2380. }
  2381. static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale){
  2382. int y;
  2383. const int strength= ff_h263_loop_filter_strength[qscale];
  2384. for(y=0; y<8; y++){
  2385. int d1, d2, ad1;
  2386. int p0= src[y*stride-2];
  2387. int p1= src[y*stride-1];
  2388. int p2= src[y*stride+0];
  2389. int p3= src[y*stride+1];
  2390. int d = (p0 - p3 + 4*(p2 - p1)) / 8;
  2391. if (d<-2*strength) d1= 0;
  2392. else if(d<- strength) d1=-2*strength - d;
  2393. else if(d< strength) d1= d;
  2394. else if(d< 2*strength) d1= 2*strength - d;
  2395. else d1= 0;
  2396. p1 += d1;
  2397. p2 -= d1;
  2398. if(p1&256) p1= ~(p1>>31);
  2399. if(p2&256) p2= ~(p2>>31);
  2400. src[y*stride-1] = p1;
  2401. src[y*stride+0] = p2;
  2402. ad1= ABS(d1)>>1;
  2403. d2= clip((p0-p3)/4, -ad1, ad1);
  2404. src[y*stride-2] = p0 - d2;
  2405. src[y*stride+1] = p3 + d2;
  2406. }
  2407. }
  2408. static void h261_loop_filter_c(uint8_t *src, int stride){
  2409. int x,y,xy,yz;
  2410. int temp[64];
  2411. for(x=0; x<8; x++){
  2412. temp[x ] = 4*src[x ];
  2413. temp[x + 7*8] = 4*src[x + 7*stride];
  2414. }
  2415. for(y=1; y<7; y++){
  2416. for(x=0; x<8; x++){
  2417. xy = y * stride + x;
  2418. yz = y * 8 + x;
  2419. temp[yz] = src[xy - stride] + 2*src[xy] + src[xy + stride];
  2420. }
  2421. }
  2422. for(y=0; y<8; y++){
  2423. src[ y*stride] = (temp[ y*8] + 2)>>2;
  2424. src[7+y*stride] = (temp[7+y*8] + 2)>>2;
  2425. for(x=1; x<7; x++){
  2426. xy = y * stride + x;
  2427. yz = y * 8 + x;
  2428. src[xy] = (temp[yz-1] + 2*temp[yz] + temp[yz+1] + 8)>>4;
  2429. }
  2430. }
  2431. }
  2432. static inline int pix_abs16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2433. {
  2434. int s, i;
  2435. s = 0;
  2436. for(i=0;i<h;i++) {
  2437. s += abs(pix1[0] - pix2[0]);
  2438. s += abs(pix1[1] - pix2[1]);
  2439. s += abs(pix1[2] - pix2[2]);
  2440. s += abs(pix1[3] - pix2[3]);
  2441. s += abs(pix1[4] - pix2[4]);
  2442. s += abs(pix1[5] - pix2[5]);
  2443. s += abs(pix1[6] - pix2[6]);
  2444. s += abs(pix1[7] - pix2[7]);
  2445. s += abs(pix1[8] - pix2[8]);
  2446. s += abs(pix1[9] - pix2[9]);
  2447. s += abs(pix1[10] - pix2[10]);
  2448. s += abs(pix1[11] - pix2[11]);
  2449. s += abs(pix1[12] - pix2[12]);
  2450. s += abs(pix1[13] - pix2[13]);
  2451. s += abs(pix1[14] - pix2[14]);
  2452. s += abs(pix1[15] - pix2[15]);
  2453. pix1 += line_size;
  2454. pix2 += line_size;
  2455. }
  2456. return s;
  2457. }
  2458. static int pix_abs16_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2459. {
  2460. int s, i;
  2461. s = 0;
  2462. for(i=0;i<h;i++) {
  2463. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  2464. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  2465. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  2466. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  2467. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  2468. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  2469. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  2470. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  2471. s += abs(pix1[8] - avg2(pix2[8], pix2[9]));
  2472. s += abs(pix1[9] - avg2(pix2[9], pix2[10]));
  2473. s += abs(pix1[10] - avg2(pix2[10], pix2[11]));
  2474. s += abs(pix1[11] - avg2(pix2[11], pix2[12]));
  2475. s += abs(pix1[12] - avg2(pix2[12], pix2[13]));
  2476. s += abs(pix1[13] - avg2(pix2[13], pix2[14]));
  2477. s += abs(pix1[14] - avg2(pix2[14], pix2[15]));
  2478. s += abs(pix1[15] - avg2(pix2[15], pix2[16]));
  2479. pix1 += line_size;
  2480. pix2 += line_size;
  2481. }
  2482. return s;
  2483. }
  2484. static int pix_abs16_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2485. {
  2486. int s, i;
  2487. uint8_t *pix3 = pix2 + line_size;
  2488. s = 0;
  2489. for(i=0;i<h;i++) {
  2490. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  2491. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  2492. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  2493. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  2494. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  2495. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  2496. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  2497. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  2498. s += abs(pix1[8] - avg2(pix2[8], pix3[8]));
  2499. s += abs(pix1[9] - avg2(pix2[9], pix3[9]));
  2500. s += abs(pix1[10] - avg2(pix2[10], pix3[10]));
  2501. s += abs(pix1[11] - avg2(pix2[11], pix3[11]));
  2502. s += abs(pix1[12] - avg2(pix2[12], pix3[12]));
  2503. s += abs(pix1[13] - avg2(pix2[13], pix3[13]));
  2504. s += abs(pix1[14] - avg2(pix2[14], pix3[14]));
  2505. s += abs(pix1[15] - avg2(pix2[15], pix3[15]));
  2506. pix1 += line_size;
  2507. pix2 += line_size;
  2508. pix3 += line_size;
  2509. }
  2510. return s;
  2511. }
  2512. static int pix_abs16_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2513. {
  2514. int s, i;
  2515. uint8_t *pix3 = pix2 + line_size;
  2516. s = 0;
  2517. for(i=0;i<h;i++) {
  2518. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  2519. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  2520. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  2521. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  2522. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  2523. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  2524. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  2525. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  2526. s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9]));
  2527. s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10]));
  2528. s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11]));
  2529. s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12]));
  2530. s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13]));
  2531. s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14]));
  2532. s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15]));
  2533. s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16]));
  2534. pix1 += line_size;
  2535. pix2 += line_size;
  2536. pix3 += line_size;
  2537. }
  2538. return s;
  2539. }
  2540. static inline int pix_abs8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2541. {
  2542. int s, i;
  2543. s = 0;
  2544. for(i=0;i<h;i++) {
  2545. s += abs(pix1[0] - pix2[0]);
  2546. s += abs(pix1[1] - pix2[1]);
  2547. s += abs(pix1[2] - pix2[2]);
  2548. s += abs(pix1[3] - pix2[3]);
  2549. s += abs(pix1[4] - pix2[4]);
  2550. s += abs(pix1[5] - pix2[5]);
  2551. s += abs(pix1[6] - pix2[6]);
  2552. s += abs(pix1[7] - pix2[7]);
  2553. pix1 += line_size;
  2554. pix2 += line_size;
  2555. }
  2556. return s;
  2557. }
  2558. static int pix_abs8_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2559. {
  2560. int s, i;
  2561. s = 0;
  2562. for(i=0;i<h;i++) {
  2563. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  2564. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  2565. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  2566. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  2567. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  2568. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  2569. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  2570. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  2571. pix1 += line_size;
  2572. pix2 += line_size;
  2573. }
  2574. return s;
  2575. }
  2576. static int pix_abs8_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2577. {
  2578. int s, i;
  2579. uint8_t *pix3 = pix2 + line_size;
  2580. s = 0;
  2581. for(i=0;i<h;i++) {
  2582. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  2583. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  2584. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  2585. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  2586. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  2587. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  2588. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  2589. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  2590. pix1 += line_size;
  2591. pix2 += line_size;
  2592. pix3 += line_size;
  2593. }
  2594. return s;
  2595. }
  2596. static int pix_abs8_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2597. {
  2598. int s, i;
  2599. uint8_t *pix3 = pix2 + line_size;
  2600. s = 0;
  2601. for(i=0;i<h;i++) {
  2602. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  2603. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  2604. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  2605. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  2606. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  2607. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  2608. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  2609. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  2610. pix1 += line_size;
  2611. pix2 += line_size;
  2612. pix3 += line_size;
  2613. }
  2614. return s;
  2615. }
  2616. static int nsse16_c(MpegEncContext *c, uint8_t *s1, uint8_t *s2, int stride, int h){
  2617. int score1=0;
  2618. int score2=0;
  2619. int x,y;
  2620. for(y=0; y<h; y++){
  2621. for(x=0; x<16; x++){
  2622. score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
  2623. }
  2624. if(y+1<h){
  2625. for(x=0; x<15; x++){
  2626. score2+= ABS( s1[x ] - s1[x +stride]
  2627. - s1[x+1] + s1[x+1+stride])
  2628. -ABS( s2[x ] - s2[x +stride]
  2629. - s2[x+1] + s2[x+1+stride]);
  2630. }
  2631. }
  2632. s1+= stride;
  2633. s2+= stride;
  2634. }
  2635. if(c) return score1 + ABS(score2)*c->avctx->nsse_weight;
  2636. else return score1 + ABS(score2)*8;
  2637. }
  2638. static int nsse8_c(MpegEncContext *c, uint8_t *s1, uint8_t *s2, int stride, int h){
  2639. int score1=0;
  2640. int score2=0;
  2641. int x,y;
  2642. for(y=0; y<h; y++){
  2643. for(x=0; x<8; x++){
  2644. score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
  2645. }
  2646. if(y+1<h){
  2647. for(x=0; x<7; x++){
  2648. score2+= ABS( s1[x ] - s1[x +stride]
  2649. - s1[x+1] + s1[x+1+stride])
  2650. -ABS( s2[x ] - s2[x +stride]
  2651. - s2[x+1] + s2[x+1+stride]);
  2652. }
  2653. }
  2654. s1+= stride;
  2655. s2+= stride;
  2656. }
  2657. if(c) return score1 + ABS(score2)*c->avctx->nsse_weight;
  2658. else return score1 + ABS(score2)*8;
  2659. }
  2660. static int try_8x8basis_c(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){
  2661. int i;
  2662. unsigned int sum=0;
  2663. for(i=0; i<8*8; i++){
  2664. int b= rem[i] + ((basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT));
  2665. int w= weight[i];
  2666. b>>= RECON_SHIFT;
  2667. assert(-512<b && b<512);
  2668. sum += (w*b)*(w*b)>>4;
  2669. }
  2670. return sum>>2;
  2671. }
  2672. static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale){
  2673. int i;
  2674. for(i=0; i<8*8; i++){
  2675. rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT);
  2676. }
  2677. }
  2678. /**
  2679. * permutes an 8x8 block.
  2680. * @param block the block which will be permuted according to the given permutation vector
  2681. * @param permutation the permutation vector
  2682. * @param last the last non zero coefficient in scantable order, used to speed the permutation up
  2683. * @param scantable the used scantable, this is only used to speed the permutation up, the block is not
  2684. * (inverse) permutated to scantable order!
  2685. */
  2686. void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last)
  2687. {
  2688. int i;
  2689. DCTELEM temp[64];
  2690. if(last<=0) return;
  2691. //if(permutation[1]==1) return; //FIXME its ok but not clean and might fail for some perms
  2692. for(i=0; i<=last; i++){
  2693. const int j= scantable[i];
  2694. temp[j]= block[j];
  2695. block[j]=0;
  2696. }
  2697. for(i=0; i<=last; i++){
  2698. const int j= scantable[i];
  2699. const int perm_j= permutation[j];
  2700. block[perm_j]= temp[j];
  2701. }
  2702. }
  2703. static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){
  2704. return 0;
  2705. }
  2706. void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){
  2707. int i;
  2708. memset(cmp, 0, sizeof(void*)*5);
  2709. for(i=0; i<5; i++){
  2710. switch(type&0xFF){
  2711. case FF_CMP_SAD:
  2712. cmp[i]= c->sad[i];
  2713. break;
  2714. case FF_CMP_SATD:
  2715. cmp[i]= c->hadamard8_diff[i];
  2716. break;
  2717. case FF_CMP_SSE:
  2718. cmp[i]= c->sse[i];
  2719. break;
  2720. case FF_CMP_DCT:
  2721. cmp[i]= c->dct_sad[i];
  2722. break;
  2723. case FF_CMP_PSNR:
  2724. cmp[i]= c->quant_psnr[i];
  2725. break;
  2726. case FF_CMP_BIT:
  2727. cmp[i]= c->bit[i];
  2728. break;
  2729. case FF_CMP_RD:
  2730. cmp[i]= c->rd[i];
  2731. break;
  2732. case FF_CMP_VSAD:
  2733. cmp[i]= c->vsad[i];
  2734. break;
  2735. case FF_CMP_VSSE:
  2736. cmp[i]= c->vsse[i];
  2737. break;
  2738. case FF_CMP_ZERO:
  2739. cmp[i]= zero_cmp;
  2740. break;
  2741. case FF_CMP_NSSE:
  2742. cmp[i]= c->nsse[i];
  2743. break;
  2744. case FF_CMP_W53:
  2745. cmp[i]= c->w53[i];
  2746. break;
  2747. case FF_CMP_W97:
  2748. cmp[i]= c->w97[i];
  2749. break;
  2750. default:
  2751. av_log(NULL, AV_LOG_ERROR,"internal error in cmp function selection\n");
  2752. }
  2753. }
  2754. }
  2755. /**
  2756. * memset(blocks, 0, sizeof(DCTELEM)*6*64)
  2757. */
  2758. static void clear_blocks_c(DCTELEM *blocks)
  2759. {
  2760. memset(blocks, 0, sizeof(DCTELEM)*6*64);
  2761. }
  2762. static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){
  2763. int i;
  2764. for(i=0; i+7<w; i+=8){
  2765. dst[i+0] += src[i+0];
  2766. dst[i+1] += src[i+1];
  2767. dst[i+2] += src[i+2];
  2768. dst[i+3] += src[i+3];
  2769. dst[i+4] += src[i+4];
  2770. dst[i+5] += src[i+5];
  2771. dst[i+6] += src[i+6];
  2772. dst[i+7] += src[i+7];
  2773. }
  2774. for(; i<w; i++)
  2775. dst[i+0] += src[i+0];
  2776. }
  2777. static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
  2778. int i;
  2779. for(i=0; i+7<w; i+=8){
  2780. dst[i+0] = src1[i+0]-src2[i+0];
  2781. dst[i+1] = src1[i+1]-src2[i+1];
  2782. dst[i+2] = src1[i+2]-src2[i+2];
  2783. dst[i+3] = src1[i+3]-src2[i+3];
  2784. dst[i+4] = src1[i+4]-src2[i+4];
  2785. dst[i+5] = src1[i+5]-src2[i+5];
  2786. dst[i+6] = src1[i+6]-src2[i+6];
  2787. dst[i+7] = src1[i+7]-src2[i+7];
  2788. }
  2789. for(; i<w; i++)
  2790. dst[i+0] = src1[i+0]-src2[i+0];
  2791. }
  2792. static void sub_hfyu_median_prediction_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top){
  2793. int i;
  2794. uint8_t l, lt;
  2795. l= *left;
  2796. lt= *left_top;
  2797. for(i=0; i<w; i++){
  2798. const int pred= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF);
  2799. lt= src1[i];
  2800. l= src2[i];
  2801. dst[i]= l - pred;
  2802. }
  2803. *left= l;
  2804. *left_top= lt;
  2805. }
  2806. #define BUTTERFLY2(o1,o2,i1,i2) \
  2807. o1= (i1)+(i2);\
  2808. o2= (i1)-(i2);
  2809. #define BUTTERFLY1(x,y) \
  2810. {\
  2811. int a,b;\
  2812. a= x;\
  2813. b= y;\
  2814. x= a+b;\
  2815. y= a-b;\
  2816. }
  2817. #define BUTTERFLYA(x,y) (ABS((x)+(y)) + ABS((x)-(y)))
  2818. static int hadamard8_diff8x8_c(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){
  2819. int i;
  2820. int temp[64];
  2821. int sum=0;
  2822. assert(h==8);
  2823. for(i=0; i<8; i++){
  2824. //FIXME try pointer walks
  2825. BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0]-dst[stride*i+0],src[stride*i+1]-dst[stride*i+1]);
  2826. BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2]-dst[stride*i+2],src[stride*i+3]-dst[stride*i+3]);
  2827. BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4]-dst[stride*i+4],src[stride*i+5]-dst[stride*i+5]);
  2828. BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6]-dst[stride*i+6],src[stride*i+7]-dst[stride*i+7]);
  2829. BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
  2830. BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
  2831. BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
  2832. BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
  2833. BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
  2834. BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
  2835. BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
  2836. BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
  2837. }
  2838. for(i=0; i<8; i++){
  2839. BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
  2840. BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
  2841. BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
  2842. BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
  2843. BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
  2844. BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
  2845. BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
  2846. BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
  2847. sum +=
  2848. BUTTERFLYA(temp[8*0+i], temp[8*4+i])
  2849. +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
  2850. +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
  2851. +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
  2852. }
  2853. #if 0
  2854. static int maxi=0;
  2855. if(sum>maxi){
  2856. maxi=sum;
  2857. printf("MAX:%d\n", maxi);
  2858. }
  2859. #endif
  2860. return sum;
  2861. }
  2862. static int hadamard8_intra8x8_c(/*MpegEncContext*/ void *s, uint8_t *src, uint8_t *dummy, int stride, int h){
  2863. int i;
  2864. int temp[64];
  2865. int sum=0;
  2866. assert(h==8);
  2867. for(i=0; i<8; i++){
  2868. //FIXME try pointer walks
  2869. BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0],src[stride*i+1]);
  2870. BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2],src[stride*i+3]);
  2871. BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4],src[stride*i+5]);
  2872. BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6],src[stride*i+7]);
  2873. BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
  2874. BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
  2875. BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
  2876. BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
  2877. BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
  2878. BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
  2879. BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
  2880. BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
  2881. }
  2882. for(i=0; i<8; i++){
  2883. BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
  2884. BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
  2885. BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
  2886. BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
  2887. BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
  2888. BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
  2889. BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
  2890. BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
  2891. sum +=
  2892. BUTTERFLYA(temp[8*0+i], temp[8*4+i])
  2893. +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
  2894. +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
  2895. +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
  2896. }
  2897. sum -= ABS(temp[8*0] + temp[8*4]); // -mean
  2898. return sum;
  2899. }
  2900. static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  2901. MpegEncContext * const s= (MpegEncContext *)c;
  2902. uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64/8];
  2903. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  2904. int sum=0, i;
  2905. assert(h==8);
  2906. s->dsp.diff_pixels(temp, src1, src2, stride);
  2907. s->dsp.fdct(temp);
  2908. for(i=0; i<64; i++)
  2909. sum+= ABS(temp[i]);
  2910. return sum;
  2911. }
  2912. void simple_idct(DCTELEM *block); //FIXME
  2913. static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  2914. MpegEncContext * const s= (MpegEncContext *)c;
  2915. uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64*2/8];
  2916. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  2917. DCTELEM * const bak = ((DCTELEM*)aligned_temp)+64;
  2918. int sum=0, i;
  2919. assert(h==8);
  2920. s->mb_intra=0;
  2921. s->dsp.diff_pixels(temp, src1, src2, stride);
  2922. memcpy(bak, temp, 64*sizeof(DCTELEM));
  2923. s->block_last_index[0/*FIXME*/]= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  2924. s->dct_unquantize_inter(s, temp, 0, s->qscale);
  2925. simple_idct(temp); //FIXME
  2926. for(i=0; i<64; i++)
  2927. sum+= (temp[i]-bak[i])*(temp[i]-bak[i]);
  2928. return sum;
  2929. }
  2930. static int rd8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  2931. MpegEncContext * const s= (MpegEncContext *)c;
  2932. const uint8_t *scantable= s->intra_scantable.permutated;
  2933. uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64/8];
  2934. uint64_t __align8 aligned_bak[stride];
  2935. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  2936. uint8_t * const bak= (uint8_t*)aligned_bak;
  2937. int i, last, run, bits, level, distoration, start_i;
  2938. const int esc_length= s->ac_esc_length;
  2939. uint8_t * length;
  2940. uint8_t * last_length;
  2941. assert(h==8);
  2942. for(i=0; i<8; i++){
  2943. ((uint32_t*)(bak + i*stride))[0]= ((uint32_t*)(src2 + i*stride))[0];
  2944. ((uint32_t*)(bak + i*stride))[1]= ((uint32_t*)(src2 + i*stride))[1];
  2945. }
  2946. s->dsp.diff_pixels(temp, src1, src2, stride);
  2947. s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  2948. bits=0;
  2949. if (s->mb_intra) {
  2950. start_i = 1;
  2951. length = s->intra_ac_vlc_length;
  2952. last_length= s->intra_ac_vlc_last_length;
  2953. bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
  2954. } else {
  2955. start_i = 0;
  2956. length = s->inter_ac_vlc_length;
  2957. last_length= s->inter_ac_vlc_last_length;
  2958. }
  2959. if(last>=start_i){
  2960. run=0;
  2961. for(i=start_i; i<last; i++){
  2962. int j= scantable[i];
  2963. level= temp[j];
  2964. if(level){
  2965. level+=64;
  2966. if((level&(~127)) == 0){
  2967. bits+= length[UNI_AC_ENC_INDEX(run, level)];
  2968. }else
  2969. bits+= esc_length;
  2970. run=0;
  2971. }else
  2972. run++;
  2973. }
  2974. i= scantable[last];
  2975. level= temp[i] + 64;
  2976. assert(level - 64);
  2977. if((level&(~127)) == 0){
  2978. bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
  2979. }else
  2980. bits+= esc_length;
  2981. }
  2982. if(last>=0){
  2983. if(s->mb_intra)
  2984. s->dct_unquantize_intra(s, temp, 0, s->qscale);
  2985. else
  2986. s->dct_unquantize_inter(s, temp, 0, s->qscale);
  2987. }
  2988. s->dsp.idct_add(bak, stride, temp);
  2989. distoration= s->dsp.sse[1](NULL, bak, src1, stride, 8);
  2990. return distoration + ((bits*s->qscale*s->qscale*109 + 64)>>7);
  2991. }
  2992. static int bit8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  2993. MpegEncContext * const s= (MpegEncContext *)c;
  2994. const uint8_t *scantable= s->intra_scantable.permutated;
  2995. uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64/8];
  2996. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  2997. int i, last, run, bits, level, start_i;
  2998. const int esc_length= s->ac_esc_length;
  2999. uint8_t * length;
  3000. uint8_t * last_length;
  3001. assert(h==8);
  3002. s->dsp.diff_pixels(temp, src1, src2, stride);
  3003. s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  3004. bits=0;
  3005. if (s->mb_intra) {
  3006. start_i = 1;
  3007. length = s->intra_ac_vlc_length;
  3008. last_length= s->intra_ac_vlc_last_length;
  3009. bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
  3010. } else {
  3011. start_i = 0;
  3012. length = s->inter_ac_vlc_length;
  3013. last_length= s->inter_ac_vlc_last_length;
  3014. }
  3015. if(last>=start_i){
  3016. run=0;
  3017. for(i=start_i; i<last; i++){
  3018. int j= scantable[i];
  3019. level= temp[j];
  3020. if(level){
  3021. level+=64;
  3022. if((level&(~127)) == 0){
  3023. bits+= length[UNI_AC_ENC_INDEX(run, level)];
  3024. }else
  3025. bits+= esc_length;
  3026. run=0;
  3027. }else
  3028. run++;
  3029. }
  3030. i= scantable[last];
  3031. level= temp[i] + 64;
  3032. assert(level - 64);
  3033. if((level&(~127)) == 0){
  3034. bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
  3035. }else
  3036. bits+= esc_length;
  3037. }
  3038. return bits;
  3039. }
  3040. static int vsad_intra16_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){
  3041. int score=0;
  3042. int x,y;
  3043. for(y=1; y<h; y++){
  3044. for(x=0; x<16; x+=4){
  3045. score+= ABS(s[x ] - s[x +stride]) + ABS(s[x+1] - s[x+1+stride])
  3046. +ABS(s[x+2] - s[x+2+stride]) + ABS(s[x+3] - s[x+3+stride]);
  3047. }
  3048. s+= stride;
  3049. }
  3050. return score;
  3051. }
  3052. static int vsad16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
  3053. int score=0;
  3054. int x,y;
  3055. for(y=1; y<h; y++){
  3056. for(x=0; x<16; x++){
  3057. score+= ABS(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
  3058. }
  3059. s1+= stride;
  3060. s2+= stride;
  3061. }
  3062. return score;
  3063. }
  3064. #define SQ(a) ((a)*(a))
  3065. static int vsse_intra16_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){
  3066. int score=0;
  3067. int x,y;
  3068. for(y=1; y<h; y++){
  3069. for(x=0; x<16; x+=4){
  3070. score+= SQ(s[x ] - s[x +stride]) + SQ(s[x+1] - s[x+1+stride])
  3071. +SQ(s[x+2] - s[x+2+stride]) + SQ(s[x+3] - s[x+3+stride]);
  3072. }
  3073. s+= stride;
  3074. }
  3075. return score;
  3076. }
  3077. static int vsse16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
  3078. int score=0;
  3079. int x,y;
  3080. for(y=1; y<h; y++){
  3081. for(x=0; x<16; x++){
  3082. score+= SQ(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
  3083. }
  3084. s1+= stride;
  3085. s2+= stride;
  3086. }
  3087. return score;
  3088. }
  3089. WARPER8_16_SQ(hadamard8_diff8x8_c, hadamard8_diff16_c)
  3090. WARPER8_16_SQ(hadamard8_intra8x8_c, hadamard8_intra16_c)
  3091. WARPER8_16_SQ(dct_sad8x8_c, dct_sad16_c)
  3092. WARPER8_16_SQ(quant_psnr8x8_c, quant_psnr16_c)
  3093. WARPER8_16_SQ(rd8x8_c, rd16_c)
  3094. WARPER8_16_SQ(bit8x8_c, bit16_c)
  3095. /* XXX: those functions should be suppressed ASAP when all IDCTs are
  3096. converted */
  3097. static void ff_jref_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
  3098. {
  3099. j_rev_dct (block);
  3100. put_pixels_clamped_c(block, dest, line_size);
  3101. }
  3102. static void ff_jref_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
  3103. {
  3104. j_rev_dct (block);
  3105. add_pixels_clamped_c(block, dest, line_size);
  3106. }
  3107. static void ff_jref_idct4_put(uint8_t *dest, int line_size, DCTELEM *block)
  3108. {
  3109. j_rev_dct4 (block);
  3110. put_pixels_clamped4_c(block, dest, line_size);
  3111. }
  3112. static void ff_jref_idct4_add(uint8_t *dest, int line_size, DCTELEM *block)
  3113. {
  3114. j_rev_dct4 (block);
  3115. add_pixels_clamped4_c(block, dest, line_size);
  3116. }
  3117. static void ff_jref_idct2_put(uint8_t *dest, int line_size, DCTELEM *block)
  3118. {
  3119. j_rev_dct2 (block);
  3120. put_pixels_clamped2_c(block, dest, line_size);
  3121. }
  3122. static void ff_jref_idct2_add(uint8_t *dest, int line_size, DCTELEM *block)
  3123. {
  3124. j_rev_dct2 (block);
  3125. add_pixels_clamped2_c(block, dest, line_size);
  3126. }
  3127. static void ff_jref_idct1_put(uint8_t *dest, int line_size, DCTELEM *block)
  3128. {
  3129. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  3130. dest[0] = cm[(block[0] + 4)>>3];
  3131. }
  3132. static void ff_jref_idct1_add(uint8_t *dest, int line_size, DCTELEM *block)
  3133. {
  3134. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  3135. dest[0] = cm[dest[0] + ((block[0] + 4)>>3)];
  3136. }
  3137. /* init static data */
  3138. void dsputil_static_init(void)
  3139. {
  3140. int i;
  3141. for(i=0;i<256;i++) cropTbl[i + MAX_NEG_CROP] = i;
  3142. for(i=0;i<MAX_NEG_CROP;i++) {
  3143. cropTbl[i] = 0;
  3144. cropTbl[i + MAX_NEG_CROP + 256] = 255;
  3145. }
  3146. for(i=0;i<512;i++) {
  3147. squareTbl[i] = (i - 256) * (i - 256);
  3148. }
  3149. for(i=0; i<64; i++) inv_zigzag_direct16[ff_zigzag_direct[i]]= i+1;
  3150. }
  3151. void dsputil_init(DSPContext* c, AVCodecContext *avctx)
  3152. {
  3153. int i;
  3154. #ifdef CONFIG_ENCODERS
  3155. if(avctx->dct_algo==FF_DCT_FASTINT) {
  3156. c->fdct = fdct_ifast;
  3157. c->fdct248 = fdct_ifast248;
  3158. }
  3159. else if(avctx->dct_algo==FF_DCT_FAAN) {
  3160. c->fdct = ff_faandct;
  3161. c->fdct248 = ff_faandct248;
  3162. }
  3163. else {
  3164. c->fdct = ff_jpeg_fdct_islow; //slow/accurate/default
  3165. c->fdct248 = ff_fdct248_islow;
  3166. }
  3167. #endif //CONFIG_ENCODERS
  3168. if(avctx->lowres==1){
  3169. if(avctx->idct_algo==FF_IDCT_INT || avctx->idct_algo==FF_IDCT_AUTO){
  3170. c->idct_put= ff_jref_idct4_put;
  3171. c->idct_add= ff_jref_idct4_add;
  3172. }else{
  3173. c->idct_put= ff_h264_lowres_idct_put_c;
  3174. c->idct_add= ff_h264_lowres_idct_add_c;
  3175. }
  3176. c->idct = j_rev_dct4;
  3177. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3178. }else if(avctx->lowres==2){
  3179. c->idct_put= ff_jref_idct2_put;
  3180. c->idct_add= ff_jref_idct2_add;
  3181. c->idct = j_rev_dct2;
  3182. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3183. }else if(avctx->lowres==3){
  3184. c->idct_put= ff_jref_idct1_put;
  3185. c->idct_add= ff_jref_idct1_add;
  3186. c->idct = j_rev_dct1;
  3187. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3188. }else{
  3189. if(avctx->idct_algo==FF_IDCT_INT){
  3190. c->idct_put= ff_jref_idct_put;
  3191. c->idct_add= ff_jref_idct_add;
  3192. c->idct = j_rev_dct;
  3193. c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
  3194. }else{ //accurate/default
  3195. c->idct_put= simple_idct_put;
  3196. c->idct_add= simple_idct_add;
  3197. c->idct = simple_idct;
  3198. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3199. }
  3200. }
  3201. c->h264_idct_add= ff_h264_idct_add_c;
  3202. /* VP3 DSP support */
  3203. c->vp3_dsp_init = vp3_dsp_init_c;
  3204. c->vp3_idct = vp3_idct_c;
  3205. c->get_pixels = get_pixels_c;
  3206. c->diff_pixels = diff_pixels_c;
  3207. c->put_pixels_clamped = put_pixels_clamped_c;
  3208. c->put_signed_pixels_clamped = put_signed_pixels_clamped_c;
  3209. c->add_pixels_clamped = add_pixels_clamped_c;
  3210. c->gmc1 = gmc1_c;
  3211. c->gmc = gmc_c;
  3212. c->clear_blocks = clear_blocks_c;
  3213. c->pix_sum = pix_sum_c;
  3214. c->pix_norm1 = pix_norm1_c;
  3215. /* TODO [0] 16 [1] 8 */
  3216. c->pix_abs[0][0] = pix_abs16_c;
  3217. c->pix_abs[0][1] = pix_abs16_x2_c;
  3218. c->pix_abs[0][2] = pix_abs16_y2_c;
  3219. c->pix_abs[0][3] = pix_abs16_xy2_c;
  3220. c->pix_abs[1][0] = pix_abs8_c;
  3221. c->pix_abs[1][1] = pix_abs8_x2_c;
  3222. c->pix_abs[1][2] = pix_abs8_y2_c;
  3223. c->pix_abs[1][3] = pix_abs8_xy2_c;
  3224. #define dspfunc(PFX, IDX, NUM) \
  3225. c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## NUM ## _c; \
  3226. c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## NUM ## _x2_c; \
  3227. c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## NUM ## _y2_c; \
  3228. c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## NUM ## _xy2_c
  3229. dspfunc(put, 0, 16);
  3230. dspfunc(put_no_rnd, 0, 16);
  3231. dspfunc(put, 1, 8);
  3232. dspfunc(put_no_rnd, 1, 8);
  3233. dspfunc(put, 2, 4);
  3234. dspfunc(put, 3, 2);
  3235. dspfunc(avg, 0, 16);
  3236. dspfunc(avg_no_rnd, 0, 16);
  3237. dspfunc(avg, 1, 8);
  3238. dspfunc(avg_no_rnd, 1, 8);
  3239. dspfunc(avg, 2, 4);
  3240. dspfunc(avg, 3, 2);
  3241. #undef dspfunc
  3242. c->put_no_rnd_pixels_l2[0]= put_no_rnd_pixels16_l2_c;
  3243. c->put_no_rnd_pixels_l2[1]= put_no_rnd_pixels8_l2_c;
  3244. c->put_tpel_pixels_tab[ 0] = put_tpel_pixels_mc00_c;
  3245. c->put_tpel_pixels_tab[ 1] = put_tpel_pixels_mc10_c;
  3246. c->put_tpel_pixels_tab[ 2] = put_tpel_pixels_mc20_c;
  3247. c->put_tpel_pixels_tab[ 4] = put_tpel_pixels_mc01_c;
  3248. c->put_tpel_pixels_tab[ 5] = put_tpel_pixels_mc11_c;
  3249. c->put_tpel_pixels_tab[ 6] = put_tpel_pixels_mc21_c;
  3250. c->put_tpel_pixels_tab[ 8] = put_tpel_pixels_mc02_c;
  3251. c->put_tpel_pixels_tab[ 9] = put_tpel_pixels_mc12_c;
  3252. c->put_tpel_pixels_tab[10] = put_tpel_pixels_mc22_c;
  3253. c->avg_tpel_pixels_tab[ 0] = avg_tpel_pixels_mc00_c;
  3254. c->avg_tpel_pixels_tab[ 1] = avg_tpel_pixels_mc10_c;
  3255. c->avg_tpel_pixels_tab[ 2] = avg_tpel_pixels_mc20_c;
  3256. c->avg_tpel_pixels_tab[ 4] = avg_tpel_pixels_mc01_c;
  3257. c->avg_tpel_pixels_tab[ 5] = avg_tpel_pixels_mc11_c;
  3258. c->avg_tpel_pixels_tab[ 6] = avg_tpel_pixels_mc21_c;
  3259. c->avg_tpel_pixels_tab[ 8] = avg_tpel_pixels_mc02_c;
  3260. c->avg_tpel_pixels_tab[ 9] = avg_tpel_pixels_mc12_c;
  3261. c->avg_tpel_pixels_tab[10] = avg_tpel_pixels_mc22_c;
  3262. #define dspfunc(PFX, IDX, NUM) \
  3263. c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \
  3264. c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \
  3265. c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \
  3266. c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \
  3267. c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \
  3268. c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \
  3269. c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \
  3270. c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \
  3271. c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \
  3272. c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \
  3273. c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \
  3274. c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \
  3275. c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \
  3276. c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \
  3277. c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \
  3278. c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
  3279. dspfunc(put_qpel, 0, 16);
  3280. dspfunc(put_no_rnd_qpel, 0, 16);
  3281. dspfunc(avg_qpel, 0, 16);
  3282. /* dspfunc(avg_no_rnd_qpel, 0, 16); */
  3283. dspfunc(put_qpel, 1, 8);
  3284. dspfunc(put_no_rnd_qpel, 1, 8);
  3285. dspfunc(avg_qpel, 1, 8);
  3286. /* dspfunc(avg_no_rnd_qpel, 1, 8); */
  3287. dspfunc(put_h264_qpel, 0, 16);
  3288. dspfunc(put_h264_qpel, 1, 8);
  3289. dspfunc(put_h264_qpel, 2, 4);
  3290. dspfunc(avg_h264_qpel, 0, 16);
  3291. dspfunc(avg_h264_qpel, 1, 8);
  3292. dspfunc(avg_h264_qpel, 2, 4);
  3293. #undef dspfunc
  3294. c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_c;
  3295. c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_c;
  3296. c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_c;
  3297. c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_c;
  3298. c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_c;
  3299. c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_c;
  3300. c->put_mspel_pixels_tab[0]= put_mspel8_mc00_c;
  3301. c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
  3302. c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c;
  3303. c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c;
  3304. c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c;
  3305. c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c;
  3306. c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c;
  3307. c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c;
  3308. #define SET_CMP_FUNC(name) \
  3309. c->name[0]= name ## 16_c;\
  3310. c->name[1]= name ## 8x8_c;
  3311. SET_CMP_FUNC(hadamard8_diff)
  3312. c->hadamard8_diff[4]= hadamard8_intra16_c;
  3313. SET_CMP_FUNC(dct_sad)
  3314. c->sad[0]= pix_abs16_c;
  3315. c->sad[1]= pix_abs8_c;
  3316. c->sse[0]= sse16_c;
  3317. c->sse[1]= sse8_c;
  3318. c->sse[2]= sse4_c;
  3319. SET_CMP_FUNC(quant_psnr)
  3320. SET_CMP_FUNC(rd)
  3321. SET_CMP_FUNC(bit)
  3322. c->vsad[0]= vsad16_c;
  3323. c->vsad[4]= vsad_intra16_c;
  3324. c->vsse[0]= vsse16_c;
  3325. c->vsse[4]= vsse_intra16_c;
  3326. c->nsse[0]= nsse16_c;
  3327. c->nsse[1]= nsse8_c;
  3328. c->w53[0]= w53_16_c;
  3329. c->w53[1]= w53_8_c;
  3330. c->w97[0]= w97_16_c;
  3331. c->w97[1]= w97_8_c;
  3332. c->add_bytes= add_bytes_c;
  3333. c->diff_bytes= diff_bytes_c;
  3334. c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c;
  3335. c->bswap_buf= bswap_buf;
  3336. c->h263_h_loop_filter= h263_h_loop_filter_c;
  3337. c->h263_v_loop_filter= h263_v_loop_filter_c;
  3338. c->h261_loop_filter= h261_loop_filter_c;
  3339. c->try_8x8basis= try_8x8basis_c;
  3340. c->add_8x8basis= add_8x8basis_c;
  3341. #ifdef HAVE_MMX
  3342. dsputil_init_mmx(c, avctx);
  3343. #endif
  3344. #ifdef ARCH_ARMV4L
  3345. dsputil_init_armv4l(c, avctx);
  3346. #endif
  3347. #ifdef HAVE_MLIB
  3348. dsputil_init_mlib(c, avctx);
  3349. #endif
  3350. #ifdef ARCH_SPARC
  3351. dsputil_init_vis(c,avctx);
  3352. #endif
  3353. #ifdef ARCH_ALPHA
  3354. dsputil_init_alpha(c, avctx);
  3355. #endif
  3356. #ifdef ARCH_POWERPC
  3357. dsputil_init_ppc(c, avctx);
  3358. #endif
  3359. #ifdef HAVE_MMI
  3360. dsputil_init_mmi(c, avctx);
  3361. #endif
  3362. #ifdef ARCH_SH4
  3363. dsputil_init_sh4(c,avctx);
  3364. #endif
  3365. switch(c->idct_permutation_type){
  3366. case FF_NO_IDCT_PERM:
  3367. for(i=0; i<64; i++)
  3368. c->idct_permutation[i]= i;
  3369. break;
  3370. case FF_LIBMPEG2_IDCT_PERM:
  3371. for(i=0; i<64; i++)
  3372. c->idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
  3373. break;
  3374. case FF_SIMPLE_IDCT_PERM:
  3375. for(i=0; i<64; i++)
  3376. c->idct_permutation[i]= simple_mmx_permutation[i];
  3377. break;
  3378. case FF_TRANSPOSE_IDCT_PERM:
  3379. for(i=0; i<64; i++)
  3380. c->idct_permutation[i]= ((i&7)<<3) | (i>>3);
  3381. break;
  3382. default:
  3383. av_log(avctx, AV_LOG_ERROR, "Internal error, IDCT permutation not set\n");
  3384. }
  3385. }