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.

3432 lines
124KB

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