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.

1829 lines
68KB

  1. /*
  2. * DSP utils
  3. * Copyright (c) 2000, 2001 Fabrice Bellard.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
  20. */
  21. #include "avcodec.h"
  22. #include "dsputil.h"
  23. #include "mpegvideo.h"
  24. int ff_bit_exact=0;
  25. UINT8 cropTbl[256 + 2 * MAX_NEG_CROP];
  26. UINT32 squareTbl[512];
  27. const UINT8 ff_zigzag_direct[64] = {
  28. 0, 1, 8, 16, 9, 2, 3, 10,
  29. 17, 24, 32, 25, 18, 11, 4, 5,
  30. 12, 19, 26, 33, 40, 48, 41, 34,
  31. 27, 20, 13, 6, 7, 14, 21, 28,
  32. 35, 42, 49, 56, 57, 50, 43, 36,
  33. 29, 22, 15, 23, 30, 37, 44, 51,
  34. 58, 59, 52, 45, 38, 31, 39, 46,
  35. 53, 60, 61, 54, 47, 55, 62, 63
  36. };
  37. /* not permutated inverse zigzag_direct + 1 for MMX quantizer */
  38. UINT16 __align8 inv_zigzag_direct16[64];
  39. const UINT8 ff_alternate_horizontal_scan[64] = {
  40. 0, 1, 2, 3, 8, 9, 16, 17,
  41. 10, 11, 4, 5, 6, 7, 15, 14,
  42. 13, 12, 19, 18, 24, 25, 32, 33,
  43. 26, 27, 20, 21, 22, 23, 28, 29,
  44. 30, 31, 34, 35, 40, 41, 48, 49,
  45. 42, 43, 36, 37, 38, 39, 44, 45,
  46. 46, 47, 50, 51, 56, 57, 58, 59,
  47. 52, 53, 54, 55, 60, 61, 62, 63,
  48. };
  49. const UINT8 ff_alternate_vertical_scan[64] = {
  50. 0, 8, 16, 24, 1, 9, 2, 10,
  51. 17, 25, 32, 40, 48, 56, 57, 49,
  52. 41, 33, 26, 18, 3, 11, 4, 12,
  53. 19, 27, 34, 42, 50, 58, 35, 43,
  54. 51, 59, 20, 28, 5, 13, 6, 14,
  55. 21, 29, 36, 44, 52, 60, 37, 45,
  56. 53, 61, 22, 30, 7, 15, 23, 31,
  57. 38, 46, 54, 62, 39, 47, 55, 63,
  58. };
  59. /* a*inverse[b]>>32 == a/b for all 0<=a<=65536 && 2<=b<=255 */
  60. const UINT32 inverse[256]={
  61. 0, 4294967295U,2147483648U,1431655766, 1073741824, 858993460, 715827883, 613566757,
  62. 536870912, 477218589, 429496730, 390451573, 357913942, 330382100, 306783379, 286331154,
  63. 268435456, 252645136, 238609295, 226050911, 214748365, 204522253, 195225787, 186737709,
  64. 178956971, 171798692, 165191050, 159072863, 153391690, 148102321, 143165577, 138547333,
  65. 134217728, 130150525, 126322568, 122713352, 119304648, 116080198, 113025456, 110127367,
  66. 107374183, 104755300, 102261127, 99882961, 97612894, 95443718, 93368855, 91382283,
  67. 89478486, 87652394, 85899346, 84215046, 82595525, 81037119, 79536432, 78090315,
  68. 76695845, 75350304, 74051161, 72796056, 71582789, 70409300, 69273667, 68174085,
  69. 67108864, 66076420, 65075263, 64103990, 63161284, 62245903, 61356676, 60492498,
  70. 59652324, 58835169, 58040099, 57266231, 56512728, 55778797, 55063684, 54366675,
  71. 53687092, 53024288, 52377650, 51746594, 51130564, 50529028, 49941481, 49367441,
  72. 48806447, 48258060, 47721859, 47197443, 46684428, 46182445, 45691142, 45210183,
  73. 44739243, 44278014, 43826197, 43383509, 42949673, 42524429, 42107523, 41698712,
  74. 41297763, 40904451, 40518560, 40139882, 39768216, 39403370, 39045158, 38693400,
  75. 38347923, 38008561, 37675152, 37347542, 37025581, 36709123, 36398028, 36092163,
  76. 35791395, 35495598, 35204650, 34918434, 34636834, 34359739, 34087043, 33818641,
  77. 33554432, 33294321, 33038210, 32786010, 32537632, 32292988, 32051995, 31814573,
  78. 31580642, 31350127, 31122952, 30899046, 30678338, 30460761, 30246249, 30034737,
  79. 29826162, 29620465, 29417585, 29217465, 29020050, 28825284, 28633116, 28443493,
  80. 28256364, 28071682, 27889399, 27709467, 27531842, 27356480, 27183338, 27012373,
  81. 26843546, 26676816, 26512144, 26349493, 26188825, 26030105, 25873297, 25718368,
  82. 25565282, 25414008, 25264514, 25116768, 24970741, 24826401, 24683721, 24542671,
  83. 24403224, 24265352, 24129030, 23994231, 23860930, 23729102, 23598722, 23469767,
  84. 23342214, 23216040, 23091223, 22967740, 22845571, 22724695, 22605092, 22486740,
  85. 22369622, 22253717, 22139007, 22025474, 21913099, 21801865, 21691755, 21582751,
  86. 21474837, 21367997, 21262215, 21157475, 21053762, 20951060, 20849356, 20748635,
  87. 20648882, 20550083, 20452226, 20355296, 20259280, 20164166, 20069941, 19976593,
  88. 19884108, 19792477, 19701685, 19611723, 19522579, 19434242, 19346700, 19259944,
  89. 19173962, 19088744, 19004281, 18920561, 18837576, 18755316, 18673771, 18592933,
  90. 18512791, 18433337, 18354562, 18276457, 18199014, 18122225, 18046082, 17970575,
  91. 17895698, 17821442, 17747799, 17674763, 17602325, 17530479, 17459217, 17388532,
  92. 17318417, 17248865, 17179870, 17111424, 17043522, 16976156, 16909321, 16843010,
  93. };
  94. static int pix_sum_c(UINT8 * pix, int line_size)
  95. {
  96. int s, i, j;
  97. s = 0;
  98. for (i = 0; i < 16; i++) {
  99. for (j = 0; j < 16; j += 8) {
  100. s += pix[0];
  101. s += pix[1];
  102. s += pix[2];
  103. s += pix[3];
  104. s += pix[4];
  105. s += pix[5];
  106. s += pix[6];
  107. s += pix[7];
  108. pix += 8;
  109. }
  110. pix += line_size - 16;
  111. }
  112. return s;
  113. }
  114. static int pix_norm1_c(UINT8 * pix, int line_size)
  115. {
  116. int s, i, j;
  117. UINT32 *sq = squareTbl + 256;
  118. s = 0;
  119. for (i = 0; i < 16; i++) {
  120. for (j = 0; j < 16; j += 8) {
  121. s += sq[pix[0]];
  122. s += sq[pix[1]];
  123. s += sq[pix[2]];
  124. s += sq[pix[3]];
  125. s += sq[pix[4]];
  126. s += sq[pix[5]];
  127. s += sq[pix[6]];
  128. s += sq[pix[7]];
  129. pix += 8;
  130. }
  131. pix += line_size - 16;
  132. }
  133. return s;
  134. }
  135. static int sse8_c(void *v, UINT8 * pix1, UINT8 * pix2, int line_size)
  136. {
  137. int s, i;
  138. UINT32 *sq = squareTbl + 256;
  139. s = 0;
  140. for (i = 0; i < 8; i++) {
  141. s += sq[pix1[0] - pix2[0]];
  142. s += sq[pix1[1] - pix2[1]];
  143. s += sq[pix1[2] - pix2[2]];
  144. s += sq[pix1[3] - pix2[3]];
  145. s += sq[pix1[4] - pix2[4]];
  146. s += sq[pix1[5] - pix2[5]];
  147. s += sq[pix1[6] - pix2[6]];
  148. s += sq[pix1[7] - pix2[7]];
  149. pix1 += line_size;
  150. pix2 += line_size;
  151. }
  152. return s;
  153. }
  154. static int sse16_c(void *v, UINT8 * pix1, UINT8 * pix2, int line_size)
  155. {
  156. int s, i, j;
  157. UINT32 *sq = squareTbl + 256;
  158. s = 0;
  159. for (i = 0; i < 16; i++) {
  160. for (j = 0; j < 16; j += 8) {
  161. s += sq[pix1[0] - pix2[0]];
  162. s += sq[pix1[1] - pix2[1]];
  163. s += sq[pix1[2] - pix2[2]];
  164. s += sq[pix1[3] - pix2[3]];
  165. s += sq[pix1[4] - pix2[4]];
  166. s += sq[pix1[5] - pix2[5]];
  167. s += sq[pix1[6] - pix2[6]];
  168. s += sq[pix1[7] - pix2[7]];
  169. pix1 += 8;
  170. pix2 += 8;
  171. }
  172. pix1 += line_size - 16;
  173. pix2 += line_size - 16;
  174. }
  175. return s;
  176. }
  177. static void get_pixels_c(DCTELEM *restrict block, const UINT8 *pixels, int line_size)
  178. {
  179. int i;
  180. /* read the pixels */
  181. for(i=0;i<8;i++) {
  182. block[0] = pixels[0];
  183. block[1] = pixels[1];
  184. block[2] = pixels[2];
  185. block[3] = pixels[3];
  186. block[4] = pixels[4];
  187. block[5] = pixels[5];
  188. block[6] = pixels[6];
  189. block[7] = pixels[7];
  190. pixels += line_size;
  191. block += 8;
  192. }
  193. }
  194. static void diff_pixels_c(DCTELEM *restrict block, const UINT8 *s1,
  195. const UINT8 *s2, int stride){
  196. int i;
  197. /* read the pixels */
  198. for(i=0;i<8;i++) {
  199. block[0] = s1[0] - s2[0];
  200. block[1] = s1[1] - s2[1];
  201. block[2] = s1[2] - s2[2];
  202. block[3] = s1[3] - s2[3];
  203. block[4] = s1[4] - s2[4];
  204. block[5] = s1[5] - s2[5];
  205. block[6] = s1[6] - s2[6];
  206. block[7] = s1[7] - s2[7];
  207. s1 += stride;
  208. s2 += stride;
  209. block += 8;
  210. }
  211. }
  212. static void put_pixels_clamped_c(const DCTELEM *block, UINT8 *restrict pixels,
  213. int line_size)
  214. {
  215. int i;
  216. UINT8 *cm = cropTbl + MAX_NEG_CROP;
  217. /* read the pixels */
  218. for(i=0;i<8;i++) {
  219. pixels[0] = cm[block[0]];
  220. pixels[1] = cm[block[1]];
  221. pixels[2] = cm[block[2]];
  222. pixels[3] = cm[block[3]];
  223. pixels[4] = cm[block[4]];
  224. pixels[5] = cm[block[5]];
  225. pixels[6] = cm[block[6]];
  226. pixels[7] = cm[block[7]];
  227. pixels += line_size;
  228. block += 8;
  229. }
  230. }
  231. static void add_pixels_clamped_c(const DCTELEM *block, UINT8 *restrict pixels,
  232. int line_size)
  233. {
  234. int i;
  235. UINT8 *cm = cropTbl + MAX_NEG_CROP;
  236. /* read the pixels */
  237. for(i=0;i<8;i++) {
  238. pixels[0] = cm[pixels[0] + block[0]];
  239. pixels[1] = cm[pixels[1] + block[1]];
  240. pixels[2] = cm[pixels[2] + block[2]];
  241. pixels[3] = cm[pixels[3] + block[3]];
  242. pixels[4] = cm[pixels[4] + block[4]];
  243. pixels[5] = cm[pixels[5] + block[5]];
  244. pixels[6] = cm[pixels[6] + block[6]];
  245. pixels[7] = cm[pixels[7] + block[7]];
  246. pixels += line_size;
  247. block += 8;
  248. }
  249. }
  250. #if 0
  251. #define PIXOP2(OPNAME, OP) \
  252. static void OPNAME ## _pixels(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  253. {\
  254. int i;\
  255. for(i=0; i<h; i++){\
  256. OP(*((uint64_t*)block), LD64(pixels));\
  257. pixels+=line_size;\
  258. block +=line_size;\
  259. }\
  260. }\
  261. \
  262. static void OPNAME ## _no_rnd_pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  263. {\
  264. int i;\
  265. for(i=0; i<h; i++){\
  266. const uint64_t a= LD64(pixels );\
  267. const uint64_t b= LD64(pixels+1);\
  268. OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  269. pixels+=line_size;\
  270. block +=line_size;\
  271. }\
  272. }\
  273. \
  274. static void OPNAME ## _pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  275. {\
  276. int i;\
  277. for(i=0; i<h; i++){\
  278. const uint64_t a= LD64(pixels );\
  279. const uint64_t b= LD64(pixels+1);\
  280. OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  281. pixels+=line_size;\
  282. block +=line_size;\
  283. }\
  284. }\
  285. \
  286. static void OPNAME ## _no_rnd_pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  287. {\
  288. int i;\
  289. for(i=0; i<h; i++){\
  290. const uint64_t a= LD64(pixels );\
  291. const uint64_t b= LD64(pixels+line_size);\
  292. OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  293. pixels+=line_size;\
  294. block +=line_size;\
  295. }\
  296. }\
  297. \
  298. static void OPNAME ## _pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  299. {\
  300. int i;\
  301. for(i=0; i<h; i++){\
  302. const uint64_t a= LD64(pixels );\
  303. const uint64_t b= LD64(pixels+line_size);\
  304. OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  305. pixels+=line_size;\
  306. block +=line_size;\
  307. }\
  308. }\
  309. \
  310. static void OPNAME ## _pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  311. {\
  312. int i;\
  313. const uint64_t a= LD64(pixels );\
  314. const uint64_t b= LD64(pixels+1);\
  315. uint64_t l0= (a&0x0303030303030303ULL)\
  316. + (b&0x0303030303030303ULL)\
  317. + 0x0202020202020202ULL;\
  318. uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  319. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  320. uint64_t l1,h1;\
  321. \
  322. pixels+=line_size;\
  323. for(i=0; i<h; i+=2){\
  324. uint64_t a= LD64(pixels );\
  325. uint64_t b= LD64(pixels+1);\
  326. l1= (a&0x0303030303030303ULL)\
  327. + (b&0x0303030303030303ULL);\
  328. h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  329. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  330. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  331. pixels+=line_size;\
  332. block +=line_size;\
  333. a= LD64(pixels );\
  334. b= LD64(pixels+1);\
  335. l0= (a&0x0303030303030303ULL)\
  336. + (b&0x0303030303030303ULL)\
  337. + 0x0202020202020202ULL;\
  338. h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  339. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  340. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  341. pixels+=line_size;\
  342. block +=line_size;\
  343. }\
  344. }\
  345. \
  346. static void OPNAME ## _no_rnd_pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  347. {\
  348. int i;\
  349. const uint64_t a= LD64(pixels );\
  350. const uint64_t b= LD64(pixels+1);\
  351. uint64_t l0= (a&0x0303030303030303ULL)\
  352. + (b&0x0303030303030303ULL)\
  353. + 0x0101010101010101ULL;\
  354. uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  355. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  356. uint64_t l1,h1;\
  357. \
  358. pixels+=line_size;\
  359. for(i=0; i<h; i+=2){\
  360. uint64_t a= LD64(pixels );\
  361. uint64_t b= LD64(pixels+1);\
  362. l1= (a&0x0303030303030303ULL)\
  363. + (b&0x0303030303030303ULL);\
  364. h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  365. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  366. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  367. pixels+=line_size;\
  368. block +=line_size;\
  369. a= LD64(pixels );\
  370. b= LD64(pixels+1);\
  371. l0= (a&0x0303030303030303ULL)\
  372. + (b&0x0303030303030303ULL)\
  373. + 0x0101010101010101ULL;\
  374. h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  375. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  376. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  377. pixels+=line_size;\
  378. block +=line_size;\
  379. }\
  380. }\
  381. \
  382. CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels_c , 8)\
  383. CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels_x2_c , 8)\
  384. CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels_y2_c , 8)\
  385. CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels_xy2_c, 8)\
  386. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels_x2_c , 8)\
  387. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels_y2_c , 8)\
  388. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels_xy2_c, 8)
  389. #define op_avg(a, b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEFEFEFEFEULL)>>1) )
  390. #else // 64 bit variant
  391. #define PIXOP2(OPNAME, OP) \
  392. static void OPNAME ## _pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  393. int i;\
  394. for(i=0; i<h; i++){\
  395. OP(*((uint32_t*)(block )), LD32(pixels ));\
  396. OP(*((uint32_t*)(block+4)), LD32(pixels+4));\
  397. pixels+=line_size;\
  398. block +=line_size;\
  399. }\
  400. }\
  401. static inline void OPNAME ## _no_rnd_pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  402. OPNAME ## _pixels8_c(block, pixels, line_size, h);\
  403. }\
  404. \
  405. static inline void OPNAME ## _no_rnd_pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  406. int src_stride1, int src_stride2, int h){\
  407. int i;\
  408. for(i=0; i<h; i++){\
  409. uint32_t a,b;\
  410. a= LD32(&src1[i*src_stride1 ]);\
  411. b= LD32(&src2[i*src_stride2 ]);\
  412. OP(*((uint32_t*)&dst[i*dst_stride ]), (a&b) + (((a^b)&0xFEFEFEFEUL)>>1));\
  413. a= LD32(&src1[i*src_stride1+4]);\
  414. b= LD32(&src2[i*src_stride2+4]);\
  415. OP(*((uint32_t*)&dst[i*dst_stride+4]), (a&b) + (((a^b)&0xFEFEFEFEUL)>>1));\
  416. }\
  417. }\
  418. \
  419. static inline void OPNAME ## _pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  420. int src_stride1, int src_stride2, int h){\
  421. int i;\
  422. for(i=0; i<h; i++){\
  423. uint32_t a,b;\
  424. a= LD32(&src1[i*src_stride1 ]);\
  425. b= LD32(&src2[i*src_stride2 ]);\
  426. OP(*((uint32_t*)&dst[i*dst_stride ]), (a|b) - (((a^b)&0xFEFEFEFEUL)>>1));\
  427. a= LD32(&src1[i*src_stride1+4]);\
  428. b= LD32(&src2[i*src_stride2+4]);\
  429. OP(*((uint32_t*)&dst[i*dst_stride+4]), (a|b) - (((a^b)&0xFEFEFEFEUL)>>1));\
  430. }\
  431. }\
  432. \
  433. static inline void OPNAME ## _pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  434. int src_stride1, int src_stride2, int h){\
  435. OPNAME ## _pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
  436. OPNAME ## _pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
  437. }\
  438. \
  439. static inline void OPNAME ## _no_rnd_pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  440. int src_stride1, int src_stride2, int h){\
  441. OPNAME ## _no_rnd_pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
  442. OPNAME ## _no_rnd_pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
  443. }\
  444. \
  445. static inline void OPNAME ## _no_rnd_pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  446. OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
  447. }\
  448. \
  449. static inline void OPNAME ## _pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  450. OPNAME ## _pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
  451. }\
  452. \
  453. static inline void OPNAME ## _no_rnd_pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  454. OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
  455. }\
  456. \
  457. static inline void OPNAME ## _pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  458. OPNAME ## _pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
  459. }\
  460. \
  461. static inline void OPNAME ## _pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
  462. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  463. int i;\
  464. for(i=0; i<h; i++){\
  465. uint32_t a, b, c, d, l0, l1, h0, h1;\
  466. a= LD32(&src1[i*src_stride1]);\
  467. b= LD32(&src2[i*src_stride2]);\
  468. c= LD32(&src3[i*src_stride3]);\
  469. d= LD32(&src4[i*src_stride4]);\
  470. l0= (a&0x03030303UL)\
  471. + (b&0x03030303UL)\
  472. + 0x02020202UL;\
  473. h0= ((a&0xFCFCFCFCUL)>>2)\
  474. + ((b&0xFCFCFCFCUL)>>2);\
  475. l1= (c&0x03030303UL)\
  476. + (d&0x03030303UL);\
  477. h1= ((c&0xFCFCFCFCUL)>>2)\
  478. + ((d&0xFCFCFCFCUL)>>2);\
  479. OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  480. a= LD32(&src1[i*src_stride1+4]);\
  481. b= LD32(&src2[i*src_stride2+4]);\
  482. c= LD32(&src3[i*src_stride3+4]);\
  483. d= LD32(&src4[i*src_stride4+4]);\
  484. l0= (a&0x03030303UL)\
  485. + (b&0x03030303UL)\
  486. + 0x02020202UL;\
  487. h0= ((a&0xFCFCFCFCUL)>>2)\
  488. + ((b&0xFCFCFCFCUL)>>2);\
  489. l1= (c&0x03030303UL)\
  490. + (d&0x03030303UL);\
  491. h1= ((c&0xFCFCFCFCUL)>>2)\
  492. + ((d&0xFCFCFCFCUL)>>2);\
  493. OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  494. }\
  495. }\
  496. static inline void OPNAME ## _no_rnd_pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
  497. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  498. int i;\
  499. for(i=0; i<h; i++){\
  500. uint32_t a, b, c, d, l0, l1, h0, h1;\
  501. a= LD32(&src1[i*src_stride1]);\
  502. b= LD32(&src2[i*src_stride2]);\
  503. c= LD32(&src3[i*src_stride3]);\
  504. d= LD32(&src4[i*src_stride4]);\
  505. l0= (a&0x03030303UL)\
  506. + (b&0x03030303UL)\
  507. + 0x01010101UL;\
  508. h0= ((a&0xFCFCFCFCUL)>>2)\
  509. + ((b&0xFCFCFCFCUL)>>2);\
  510. l1= (c&0x03030303UL)\
  511. + (d&0x03030303UL);\
  512. h1= ((c&0xFCFCFCFCUL)>>2)\
  513. + ((d&0xFCFCFCFCUL)>>2);\
  514. OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  515. a= LD32(&src1[i*src_stride1+4]);\
  516. b= LD32(&src2[i*src_stride2+4]);\
  517. c= LD32(&src3[i*src_stride3+4]);\
  518. d= LD32(&src4[i*src_stride4+4]);\
  519. l0= (a&0x03030303UL)\
  520. + (b&0x03030303UL)\
  521. + 0x01010101UL;\
  522. h0= ((a&0xFCFCFCFCUL)>>2)\
  523. + ((b&0xFCFCFCFCUL)>>2);\
  524. l1= (c&0x03030303UL)\
  525. + (d&0x03030303UL);\
  526. h1= ((c&0xFCFCFCFCUL)>>2)\
  527. + ((d&0xFCFCFCFCUL)>>2);\
  528. OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  529. }\
  530. }\
  531. static inline void OPNAME ## _pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
  532. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  533. OPNAME ## _pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  534. OPNAME ## _pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  535. }\
  536. static inline void OPNAME ## _no_rnd_pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
  537. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  538. OPNAME ## _no_rnd_pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  539. 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);\
  540. }\
  541. \
  542. static inline void OPNAME ## _pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  543. {\
  544. int j;\
  545. for(j=0; j<2; j++){\
  546. int i;\
  547. const uint32_t a= LD32(pixels );\
  548. const uint32_t b= LD32(pixels+1);\
  549. uint32_t l0= (a&0x03030303UL)\
  550. + (b&0x03030303UL)\
  551. + 0x02020202UL;\
  552. uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
  553. + ((b&0xFCFCFCFCUL)>>2);\
  554. uint32_t l1,h1;\
  555. \
  556. pixels+=line_size;\
  557. for(i=0; i<h; i+=2){\
  558. uint32_t a= LD32(pixels );\
  559. uint32_t b= LD32(pixels+1);\
  560. l1= (a&0x03030303UL)\
  561. + (b&0x03030303UL);\
  562. h1= ((a&0xFCFCFCFCUL)>>2)\
  563. + ((b&0xFCFCFCFCUL)>>2);\
  564. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  565. pixels+=line_size;\
  566. block +=line_size;\
  567. a= LD32(pixels );\
  568. b= LD32(pixels+1);\
  569. l0= (a&0x03030303UL)\
  570. + (b&0x03030303UL)\
  571. + 0x02020202UL;\
  572. h0= ((a&0xFCFCFCFCUL)>>2)\
  573. + ((b&0xFCFCFCFCUL)>>2);\
  574. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  575. pixels+=line_size;\
  576. block +=line_size;\
  577. }\
  578. pixels+=4-line_size*(h+1);\
  579. block +=4-line_size*h;\
  580. }\
  581. }\
  582. \
  583. static inline void OPNAME ## _no_rnd_pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  584. {\
  585. int j;\
  586. for(j=0; j<2; j++){\
  587. int i;\
  588. const uint32_t a= LD32(pixels );\
  589. const uint32_t b= LD32(pixels+1);\
  590. uint32_t l0= (a&0x03030303UL)\
  591. + (b&0x03030303UL)\
  592. + 0x01010101UL;\
  593. uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
  594. + ((b&0xFCFCFCFCUL)>>2);\
  595. uint32_t l1,h1;\
  596. \
  597. pixels+=line_size;\
  598. for(i=0; i<h; i+=2){\
  599. uint32_t a= LD32(pixels );\
  600. uint32_t b= LD32(pixels+1);\
  601. l1= (a&0x03030303UL)\
  602. + (b&0x03030303UL);\
  603. h1= ((a&0xFCFCFCFCUL)>>2)\
  604. + ((b&0xFCFCFCFCUL)>>2);\
  605. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  606. pixels+=line_size;\
  607. block +=line_size;\
  608. a= LD32(pixels );\
  609. b= LD32(pixels+1);\
  610. l0= (a&0x03030303UL)\
  611. + (b&0x03030303UL)\
  612. + 0x01010101UL;\
  613. h0= ((a&0xFCFCFCFCUL)>>2)\
  614. + ((b&0xFCFCFCFCUL)>>2);\
  615. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  616. pixels+=line_size;\
  617. block +=line_size;\
  618. }\
  619. pixels+=4-line_size*(h+1);\
  620. block +=4-line_size*h;\
  621. }\
  622. }\
  623. \
  624. CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels8_c , 8)\
  625. CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels8_x2_c , 8)\
  626. CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels8_y2_c , 8)\
  627. CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels8_xy2_c, 8)\
  628. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_c , OPNAME ## _pixels8_c , 8)\
  629. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels8_x2_c , 8)\
  630. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels8_y2_c , 8)\
  631. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels8_xy2_c, 8)\
  632. #define op_avg(a, b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEUL)>>1) )
  633. #endif
  634. #define op_put(a, b) a = b
  635. PIXOP2(avg, op_avg)
  636. PIXOP2(put, op_put)
  637. #undef op_avg
  638. #undef op_put
  639. #define avg2(a,b) ((a+b+1)>>1)
  640. #define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
  641. static void gmc1_c(UINT8 *dst, UINT8 *src, int stride, int h, int x16, int y16, int rounder)
  642. {
  643. const int A=(16-x16)*(16-y16);
  644. const int B=( x16)*(16-y16);
  645. const int C=(16-x16)*( y16);
  646. const int D=( x16)*( y16);
  647. int i;
  648. for(i=0; i<h; i++)
  649. {
  650. dst[0]= (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + rounder)>>8;
  651. dst[1]= (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + rounder)>>8;
  652. dst[2]= (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + rounder)>>8;
  653. dst[3]= (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + rounder)>>8;
  654. dst[4]= (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + rounder)>>8;
  655. dst[5]= (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + rounder)>>8;
  656. dst[6]= (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + rounder)>>8;
  657. dst[7]= (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + rounder)>>8;
  658. dst+= stride;
  659. src+= stride;
  660. }
  661. }
  662. static void gmc_c(UINT8 *dst, UINT8 *src, int stride, int h, int ox, int oy,
  663. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
  664. {
  665. int y, vx, vy;
  666. const int s= 1<<shift;
  667. width--;
  668. height--;
  669. for(y=0; y<h; y++){
  670. int x;
  671. vx= ox;
  672. vy= oy;
  673. for(x=0; x<8; x++){ //XXX FIXME optimize
  674. int src_x, src_y, frac_x, frac_y, index;
  675. src_x= vx>>16;
  676. src_y= vy>>16;
  677. frac_x= src_x&(s-1);
  678. frac_y= src_y&(s-1);
  679. src_x>>=shift;
  680. src_y>>=shift;
  681. if((unsigned)src_x < width){
  682. if((unsigned)src_y < height){
  683. index= src_x + src_y*stride;
  684. dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
  685. + src[index +1]* frac_x )*(s-frac_y)
  686. + ( src[index+stride ]*(s-frac_x)
  687. + src[index+stride+1]* frac_x )* frac_y
  688. + r)>>(shift*2);
  689. }else{
  690. index= src_x + clip(src_y, 0, height)*stride;
  691. dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
  692. + src[index +1]* frac_x )*s
  693. + r)>>(shift*2);
  694. }
  695. }else{
  696. if((unsigned)src_y < height){
  697. index= clip(src_x, 0, width) + src_y*stride;
  698. dst[y*stride + x]= ( ( src[index ]*(s-frac_y)
  699. + src[index+stride ]* frac_y )*s
  700. + r)>>(shift*2);
  701. }else{
  702. index= clip(src_x, 0, width) + clip(src_y, 0, height)*stride;
  703. dst[y*stride + x]= src[index ];
  704. }
  705. }
  706. vx+= dxx;
  707. vy+= dyx;
  708. }
  709. ox += dxy;
  710. oy += dyy;
  711. }
  712. }
  713. static inline void copy_block17(UINT8 *dst, UINT8 *src, int dstStride, int srcStride, int h)
  714. {
  715. int i;
  716. for(i=0; i<h; i++)
  717. {
  718. ST32(dst , LD32(src ));
  719. ST32(dst+4 , LD32(src+4 ));
  720. ST32(dst+8 , LD32(src+8 ));
  721. ST32(dst+12, LD32(src+12));
  722. dst[16]= src[16];
  723. dst+=dstStride;
  724. src+=srcStride;
  725. }
  726. }
  727. static inline void copy_block9(UINT8 *dst, UINT8 *src, int dstStride, int srcStride, int h)
  728. {
  729. int i;
  730. for(i=0; i<h; i++)
  731. {
  732. ST32(dst , LD32(src ));
  733. ST32(dst+4 , LD32(src+4 ));
  734. dst[8]= src[8];
  735. dst+=dstStride;
  736. src+=srcStride;
  737. }
  738. }
  739. #define QPEL_MC(r, OPNAME, RND, OP) \
  740. static void OPNAME ## mpeg4_qpel8_h_lowpass(UINT8 *dst, UINT8 *src, int dstStride, int srcStride, int h){\
  741. UINT8 *cm = cropTbl + MAX_NEG_CROP;\
  742. int i;\
  743. for(i=0; i<h; i++)\
  744. {\
  745. OP(dst[0], (src[0]+src[1])*20 - (src[0]+src[2])*6 + (src[1]+src[3])*3 - (src[2]+src[4]));\
  746. OP(dst[1], (src[1]+src[2])*20 - (src[0]+src[3])*6 + (src[0]+src[4])*3 - (src[1]+src[5]));\
  747. OP(dst[2], (src[2]+src[3])*20 - (src[1]+src[4])*6 + (src[0]+src[5])*3 - (src[0]+src[6]));\
  748. OP(dst[3], (src[3]+src[4])*20 - (src[2]+src[5])*6 + (src[1]+src[6])*3 - (src[0]+src[7]));\
  749. OP(dst[4], (src[4]+src[5])*20 - (src[3]+src[6])*6 + (src[2]+src[7])*3 - (src[1]+src[8]));\
  750. OP(dst[5], (src[5]+src[6])*20 - (src[4]+src[7])*6 + (src[3]+src[8])*3 - (src[2]+src[8]));\
  751. OP(dst[6], (src[6]+src[7])*20 - (src[5]+src[8])*6 + (src[4]+src[8])*3 - (src[3]+src[7]));\
  752. OP(dst[7], (src[7]+src[8])*20 - (src[6]+src[8])*6 + (src[5]+src[7])*3 - (src[4]+src[6]));\
  753. dst+=dstStride;\
  754. src+=srcStride;\
  755. }\
  756. }\
  757. \
  758. static void OPNAME ## mpeg4_qpel8_v_lowpass(UINT8 *dst, UINT8 *src, int dstStride, int srcStride, int w){\
  759. UINT8 *cm = cropTbl + MAX_NEG_CROP;\
  760. int i;\
  761. for(i=0; i<w; i++)\
  762. {\
  763. const int src0= src[0*srcStride];\
  764. const int src1= src[1*srcStride];\
  765. const int src2= src[2*srcStride];\
  766. const int src3= src[3*srcStride];\
  767. const int src4= src[4*srcStride];\
  768. const int src5= src[5*srcStride];\
  769. const int src6= src[6*srcStride];\
  770. const int src7= src[7*srcStride];\
  771. const int src8= src[8*srcStride];\
  772. OP(dst[0*dstStride], (src0+src1)*20 - (src0+src2)*6 + (src1+src3)*3 - (src2+src4));\
  773. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*6 + (src0+src4)*3 - (src1+src5));\
  774. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*6 + (src0+src5)*3 - (src0+src6));\
  775. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*6 + (src1+src6)*3 - (src0+src7));\
  776. OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*6 + (src2+src7)*3 - (src1+src8));\
  777. OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*6 + (src3+src8)*3 - (src2+src8));\
  778. OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*6 + (src4+src8)*3 - (src3+src7));\
  779. OP(dst[7*dstStride], (src7+src8)*20 - (src6+src8)*6 + (src5+src7)*3 - (src4+src6));\
  780. dst++;\
  781. src++;\
  782. }\
  783. }\
  784. \
  785. static void OPNAME ## mpeg4_qpel16_h_lowpass(UINT8 *dst, UINT8 *src, int dstStride, int srcStride, int h){\
  786. UINT8 *cm = cropTbl + MAX_NEG_CROP;\
  787. int i;\
  788. for(i=0; i<h; i++)\
  789. {\
  790. OP(dst[ 0], (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]));\
  791. OP(dst[ 1], (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]));\
  792. OP(dst[ 2], (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]));\
  793. OP(dst[ 3], (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]));\
  794. OP(dst[ 4], (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]));\
  795. OP(dst[ 5], (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]));\
  796. OP(dst[ 6], (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]));\
  797. OP(dst[ 7], (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]));\
  798. OP(dst[ 8], (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]));\
  799. OP(dst[ 9], (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]));\
  800. OP(dst[10], (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]));\
  801. OP(dst[11], (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]));\
  802. OP(dst[12], (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]));\
  803. OP(dst[13], (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]));\
  804. OP(dst[14], (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]));\
  805. OP(dst[15], (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]));\
  806. dst+=dstStride;\
  807. src+=srcStride;\
  808. }\
  809. }\
  810. \
  811. static void OPNAME ## mpeg4_qpel16_v_lowpass(UINT8 *dst, UINT8 *src, int dstStride, int srcStride, int w){\
  812. UINT8 *cm = cropTbl + MAX_NEG_CROP;\
  813. int i;\
  814. for(i=0; i<w; i++)\
  815. {\
  816. const int src0= src[0*srcStride];\
  817. const int src1= src[1*srcStride];\
  818. const int src2= src[2*srcStride];\
  819. const int src3= src[3*srcStride];\
  820. const int src4= src[4*srcStride];\
  821. const int src5= src[5*srcStride];\
  822. const int src6= src[6*srcStride];\
  823. const int src7= src[7*srcStride];\
  824. const int src8= src[8*srcStride];\
  825. const int src9= src[9*srcStride];\
  826. const int src10= src[10*srcStride];\
  827. const int src11= src[11*srcStride];\
  828. const int src12= src[12*srcStride];\
  829. const int src13= src[13*srcStride];\
  830. const int src14= src[14*srcStride];\
  831. const int src15= src[15*srcStride];\
  832. const int src16= src[16*srcStride];\
  833. OP(dst[ 0*dstStride], (src0 +src1 )*20 - (src0 +src2 )*6 + (src1 +src3 )*3 - (src2 +src4 ));\
  834. OP(dst[ 1*dstStride], (src1 +src2 )*20 - (src0 +src3 )*6 + (src0 +src4 )*3 - (src1 +src5 ));\
  835. OP(dst[ 2*dstStride], (src2 +src3 )*20 - (src1 +src4 )*6 + (src0 +src5 )*3 - (src0 +src6 ));\
  836. OP(dst[ 3*dstStride], (src3 +src4 )*20 - (src2 +src5 )*6 + (src1 +src6 )*3 - (src0 +src7 ));\
  837. OP(dst[ 4*dstStride], (src4 +src5 )*20 - (src3 +src6 )*6 + (src2 +src7 )*3 - (src1 +src8 ));\
  838. OP(dst[ 5*dstStride], (src5 +src6 )*20 - (src4 +src7 )*6 + (src3 +src8 )*3 - (src2 +src9 ));\
  839. OP(dst[ 6*dstStride], (src6 +src7 )*20 - (src5 +src8 )*6 + (src4 +src9 )*3 - (src3 +src10));\
  840. OP(dst[ 7*dstStride], (src7 +src8 )*20 - (src6 +src9 )*6 + (src5 +src10)*3 - (src4 +src11));\
  841. OP(dst[ 8*dstStride], (src8 +src9 )*20 - (src7 +src10)*6 + (src6 +src11)*3 - (src5 +src12));\
  842. OP(dst[ 9*dstStride], (src9 +src10)*20 - (src8 +src11)*6 + (src7 +src12)*3 - (src6 +src13));\
  843. OP(dst[10*dstStride], (src10+src11)*20 - (src9 +src12)*6 + (src8 +src13)*3 - (src7 +src14));\
  844. OP(dst[11*dstStride], (src11+src12)*20 - (src10+src13)*6 + (src9 +src14)*3 - (src8 +src15));\
  845. OP(dst[12*dstStride], (src12+src13)*20 - (src11+src14)*6 + (src10+src15)*3 - (src9 +src16));\
  846. OP(dst[13*dstStride], (src13+src14)*20 - (src12+src15)*6 + (src11+src16)*3 - (src10+src16));\
  847. OP(dst[14*dstStride], (src14+src15)*20 - (src13+src16)*6 + (src12+src16)*3 - (src11+src15));\
  848. OP(dst[15*dstStride], (src15+src16)*20 - (src14+src16)*6 + (src13+src15)*3 - (src12+src14));\
  849. dst++;\
  850. src++;\
  851. }\
  852. }\
  853. \
  854. static void OPNAME ## qpel8_mc00_c (UINT8 *dst, UINT8 *src, int stride){\
  855. OPNAME ## pixels8_c(dst, src, stride, 8);\
  856. }\
  857. \
  858. static void OPNAME ## qpel8_mc10_c(UINT8 *dst, UINT8 *src, int stride){\
  859. UINT8 half[64];\
  860. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  861. OPNAME ## pixels8_l2(dst, src, half, stride, stride, 8, 8);\
  862. }\
  863. \
  864. static void OPNAME ## qpel8_mc20_c(UINT8 *dst, UINT8 *src, int stride){\
  865. OPNAME ## mpeg4_qpel8_h_lowpass(dst, src, stride, stride, 8);\
  866. }\
  867. \
  868. static void OPNAME ## qpel8_mc30_c(UINT8 *dst, UINT8 *src, int stride){\
  869. UINT8 half[64];\
  870. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  871. OPNAME ## pixels8_l2(dst, src+1, half, stride, stride, 8, 8);\
  872. }\
  873. \
  874. static void OPNAME ## qpel8_mc01_c(UINT8 *dst, UINT8 *src, int stride){\
  875. UINT8 full[16*9];\
  876. UINT8 half[64];\
  877. copy_block9(full, src, 16, stride, 9);\
  878. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16, 8);\
  879. OPNAME ## pixels8_l2(dst, full, half, stride, 16, 8, 8);\
  880. }\
  881. \
  882. static void OPNAME ## qpel8_mc02_c(UINT8 *dst, UINT8 *src, int stride){\
  883. UINT8 full[16*9];\
  884. copy_block9(full, src, 16, stride, 9);\
  885. OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16, 8);\
  886. }\
  887. \
  888. static void OPNAME ## qpel8_mc03_c(UINT8 *dst, UINT8 *src, int stride){\
  889. UINT8 full[16*9];\
  890. UINT8 half[64];\
  891. copy_block9(full, src, 16, stride, 9);\
  892. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16, 8);\
  893. OPNAME ## pixels8_l2(dst, full+16, half, stride, 16, 8, 8);\
  894. }\
  895. static void OPNAME ## qpel8_mc11_c(UINT8 *dst, UINT8 *src, int stride){\
  896. UINT8 full[16*9];\
  897. UINT8 halfH[72];\
  898. UINT8 halfV[64];\
  899. UINT8 halfHV[64];\
  900. copy_block9(full, src, 16, stride, 9);\
  901. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  902. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16, 8);\
  903. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
  904. OPNAME ## pixels8_l4(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  905. }\
  906. static void OPNAME ## qpel8_mc31_c(UINT8 *dst, UINT8 *src, int stride){\
  907. UINT8 full[16*9];\
  908. UINT8 halfH[72];\
  909. UINT8 halfV[64];\
  910. UINT8 halfHV[64];\
  911. copy_block9(full, src, 16, stride, 9);\
  912. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  913. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16, 8);\
  914. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
  915. OPNAME ## pixels8_l4(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  916. }\
  917. static void OPNAME ## qpel8_mc13_c(UINT8 *dst, UINT8 *src, int stride){\
  918. UINT8 full[16*9];\
  919. UINT8 halfH[72];\
  920. UINT8 halfV[64];\
  921. UINT8 halfHV[64];\
  922. copy_block9(full, src, 16, stride, 9);\
  923. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  924. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16, 8);\
  925. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
  926. OPNAME ## pixels8_l4(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  927. }\
  928. static void OPNAME ## qpel8_mc33_c(UINT8 *dst, UINT8 *src, int stride){\
  929. UINT8 full[16*9];\
  930. UINT8 halfH[72];\
  931. UINT8 halfV[64];\
  932. UINT8 halfHV[64];\
  933. copy_block9(full, src, 16, stride, 9);\
  934. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full , 8, 16, 9);\
  935. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16, 8);\
  936. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
  937. OPNAME ## pixels8_l4(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  938. }\
  939. static void OPNAME ## qpel8_mc21_c(UINT8 *dst, UINT8 *src, int stride){\
  940. UINT8 halfH[72];\
  941. UINT8 halfHV[64];\
  942. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  943. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
  944. OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
  945. }\
  946. static void OPNAME ## qpel8_mc23_c(UINT8 *dst, UINT8 *src, int stride){\
  947. UINT8 halfH[72];\
  948. UINT8 halfHV[64];\
  949. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  950. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
  951. OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  952. }\
  953. static void OPNAME ## qpel8_mc12_c(UINT8 *dst, UINT8 *src, int stride){\
  954. UINT8 full[16*9];\
  955. UINT8 halfH[72];\
  956. UINT8 halfV[64];\
  957. UINT8 halfHV[64];\
  958. copy_block9(full, src, 16, stride, 9);\
  959. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  960. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16, 8);\
  961. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
  962. OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
  963. }\
  964. static void OPNAME ## qpel8_mc32_c(UINT8 *dst, UINT8 *src, int stride){\
  965. UINT8 full[16*9];\
  966. UINT8 halfH[72];\
  967. UINT8 halfV[64];\
  968. UINT8 halfHV[64];\
  969. copy_block9(full, src, 16, stride, 9);\
  970. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  971. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16, 8);\
  972. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
  973. OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
  974. }\
  975. static void OPNAME ## qpel8_mc22_c(UINT8 *dst, UINT8 *src, int stride){\
  976. UINT8 halfH[72];\
  977. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  978. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8, 8);\
  979. }\
  980. static void OPNAME ## qpel16_mc00_c (UINT8 *dst, UINT8 *src, int stride){\
  981. OPNAME ## pixels16_c(dst, src, stride, 16);\
  982. }\
  983. \
  984. static void OPNAME ## qpel16_mc10_c(UINT8 *dst, UINT8 *src, int stride){\
  985. UINT8 half[256];\
  986. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  987. OPNAME ## pixels16_l2(dst, src, half, stride, stride, 16, 16);\
  988. }\
  989. \
  990. static void OPNAME ## qpel16_mc20_c(UINT8 *dst, UINT8 *src, int stride){\
  991. OPNAME ## mpeg4_qpel16_h_lowpass(dst, src, stride, stride, 16);\
  992. }\
  993. \
  994. static void OPNAME ## qpel16_mc30_c(UINT8 *dst, UINT8 *src, int stride){\
  995. UINT8 half[256];\
  996. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  997. OPNAME ## pixels16_l2(dst, src+1, half, stride, stride, 16, 16);\
  998. }\
  999. \
  1000. static void OPNAME ## qpel16_mc01_c(UINT8 *dst, UINT8 *src, int stride){\
  1001. UINT8 full[24*17];\
  1002. UINT8 half[256];\
  1003. copy_block17(full, src, 24, stride, 17);\
  1004. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24, 16);\
  1005. OPNAME ## pixels16_l2(dst, full, half, stride, 24, 16, 16);\
  1006. }\
  1007. \
  1008. static void OPNAME ## qpel16_mc02_c(UINT8 *dst, UINT8 *src, int stride){\
  1009. UINT8 full[24*17];\
  1010. copy_block17(full, src, 24, stride, 17);\
  1011. OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24, 16);\
  1012. }\
  1013. \
  1014. static void OPNAME ## qpel16_mc03_c(UINT8 *dst, UINT8 *src, int stride){\
  1015. UINT8 full[24*17];\
  1016. UINT8 half[256];\
  1017. copy_block17(full, src, 24, stride, 17);\
  1018. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24, 16);\
  1019. OPNAME ## pixels16_l2(dst, full+24, half, stride, 24, 16, 16);\
  1020. }\
  1021. static void OPNAME ## qpel16_mc11_c(UINT8 *dst, UINT8 *src, int stride){\
  1022. UINT8 full[24*17];\
  1023. UINT8 halfH[272];\
  1024. UINT8 halfV[256];\
  1025. UINT8 halfHV[256];\
  1026. copy_block17(full, src, 24, stride, 17);\
  1027. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1028. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24, 16);\
  1029. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16, 16);\
  1030. OPNAME ## pixels16_l4(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1031. }\
  1032. static void OPNAME ## qpel16_mc31_c(UINT8 *dst, UINT8 *src, int stride){\
  1033. UINT8 full[24*17];\
  1034. UINT8 halfH[272];\
  1035. UINT8 halfV[256];\
  1036. UINT8 halfHV[256];\
  1037. copy_block17(full, src, 24, stride, 17);\
  1038. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1039. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24, 16);\
  1040. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16, 16);\
  1041. OPNAME ## pixels16_l4(dst, full+1, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1042. }\
  1043. static void OPNAME ## qpel16_mc13_c(UINT8 *dst, UINT8 *src, int stride){\
  1044. UINT8 full[24*17];\
  1045. UINT8 halfH[272];\
  1046. UINT8 halfV[256];\
  1047. UINT8 halfHV[256];\
  1048. copy_block17(full, src, 24, stride, 17);\
  1049. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1050. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24, 16);\
  1051. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16, 16);\
  1052. OPNAME ## pixels16_l4(dst, full+24, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1053. }\
  1054. static void OPNAME ## qpel16_mc33_c(UINT8 *dst, UINT8 *src, int stride){\
  1055. UINT8 full[24*17];\
  1056. UINT8 halfH[272];\
  1057. UINT8 halfV[256];\
  1058. UINT8 halfHV[256];\
  1059. copy_block17(full, src, 24, stride, 17);\
  1060. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full , 16, 24, 17);\
  1061. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24, 16);\
  1062. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16, 16);\
  1063. OPNAME ## pixels16_l4(dst, full+25, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1064. }\
  1065. static void OPNAME ## qpel16_mc21_c(UINT8 *dst, UINT8 *src, int stride){\
  1066. UINT8 halfH[272];\
  1067. UINT8 halfHV[256];\
  1068. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1069. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16, 16);\
  1070. OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
  1071. }\
  1072. static void OPNAME ## qpel16_mc23_c(UINT8 *dst, UINT8 *src, int stride){\
  1073. UINT8 halfH[272];\
  1074. UINT8 halfHV[256];\
  1075. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1076. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16, 16);\
  1077. OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1078. }\
  1079. static void OPNAME ## qpel16_mc12_c(UINT8 *dst, UINT8 *src, int stride){\
  1080. UINT8 full[24*17];\
  1081. UINT8 halfH[272];\
  1082. UINT8 halfV[256];\
  1083. UINT8 halfHV[256];\
  1084. copy_block17(full, src, 24, stride, 17);\
  1085. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1086. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24, 16);\
  1087. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16, 16);\
  1088. OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
  1089. }\
  1090. static void OPNAME ## qpel16_mc32_c(UINT8 *dst, UINT8 *src, int stride){\
  1091. UINT8 full[24*17];\
  1092. UINT8 halfH[272];\
  1093. UINT8 halfV[256];\
  1094. UINT8 halfHV[256];\
  1095. copy_block17(full, src, 24, stride, 17);\
  1096. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1097. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24, 16);\
  1098. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16, 16);\
  1099. OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
  1100. }\
  1101. static void OPNAME ## qpel16_mc22_c(UINT8 *dst, UINT8 *src, int stride){\
  1102. UINT8 halfH[272];\
  1103. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1104. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16, 16);\
  1105. }
  1106. #define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
  1107. #define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1)
  1108. #define op_put(a, b) a = cm[((b) + 16)>>5]
  1109. #define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5]
  1110. QPEL_MC(0, put_ , _ , op_put)
  1111. QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd)
  1112. QPEL_MC(0, avg_ , _ , op_avg)
  1113. //QPEL_MC(1, avg_no_rnd , _ , op_avg)
  1114. #undef op_avg
  1115. #undef op_avg_no_rnd
  1116. #undef op_put
  1117. #undef op_put_no_rnd
  1118. static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){
  1119. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  1120. int i;
  1121. for(i=0; i<h; i++){
  1122. dst[0]= cm[(9*(src[0] + src[1]) - (src[-1] + src[2]) + 8)>>4];
  1123. dst[1]= cm[(9*(src[1] + src[2]) - (src[ 0] + src[3]) + 8)>>4];
  1124. dst[2]= cm[(9*(src[2] + src[3]) - (src[ 1] + src[4]) + 8)>>4];
  1125. dst[3]= cm[(9*(src[3] + src[4]) - (src[ 2] + src[5]) + 8)>>4];
  1126. dst[4]= cm[(9*(src[4] + src[5]) - (src[ 3] + src[6]) + 8)>>4];
  1127. dst[5]= cm[(9*(src[5] + src[6]) - (src[ 4] + src[7]) + 8)>>4];
  1128. dst[6]= cm[(9*(src[6] + src[7]) - (src[ 5] + src[8]) + 8)>>4];
  1129. dst[7]= cm[(9*(src[7] + src[8]) - (src[ 6] + src[9]) + 8)>>4];
  1130. dst+=dstStride;
  1131. src+=srcStride;
  1132. }
  1133. }
  1134. static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){
  1135. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  1136. int i;
  1137. for(i=0; i<w; i++){
  1138. const int src_1= src[ -srcStride];
  1139. const int src0 = src[0 ];
  1140. const int src1 = src[ srcStride];
  1141. const int src2 = src[2*srcStride];
  1142. const int src3 = src[3*srcStride];
  1143. const int src4 = src[4*srcStride];
  1144. const int src5 = src[5*srcStride];
  1145. const int src6 = src[6*srcStride];
  1146. const int src7 = src[7*srcStride];
  1147. const int src8 = src[8*srcStride];
  1148. const int src9 = src[9*srcStride];
  1149. dst[0*dstStride]= cm[(9*(src0 + src1) - (src_1 + src2) + 8)>>4];
  1150. dst[1*dstStride]= cm[(9*(src1 + src2) - (src0 + src3) + 8)>>4];
  1151. dst[2*dstStride]= cm[(9*(src2 + src3) - (src1 + src4) + 8)>>4];
  1152. dst[3*dstStride]= cm[(9*(src3 + src4) - (src2 + src5) + 8)>>4];
  1153. dst[4*dstStride]= cm[(9*(src4 + src5) - (src3 + src6) + 8)>>4];
  1154. dst[5*dstStride]= cm[(9*(src5 + src6) - (src4 + src7) + 8)>>4];
  1155. dst[6*dstStride]= cm[(9*(src6 + src7) - (src5 + src8) + 8)>>4];
  1156. dst[7*dstStride]= cm[(9*(src7 + src8) - (src6 + src9) + 8)>>4];
  1157. src++;
  1158. dst++;
  1159. }
  1160. }
  1161. static void put_mspel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){
  1162. put_pixels8_c(dst, src, stride, 8);
  1163. }
  1164. static void put_mspel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){
  1165. uint8_t half[64];
  1166. wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
  1167. put_pixels8_l2(dst, src, half, stride, stride, 8, 8);
  1168. }
  1169. static void put_mspel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){
  1170. wmv2_mspel8_h_lowpass(dst, src, stride, stride, 8);
  1171. }
  1172. static void put_mspel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){
  1173. uint8_t half[64];
  1174. wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
  1175. put_pixels8_l2(dst, src+1, half, stride, stride, 8, 8);
  1176. }
  1177. static void put_mspel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){
  1178. wmv2_mspel8_v_lowpass(dst, src, stride, stride, 8);
  1179. }
  1180. static void put_mspel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){
  1181. uint8_t halfH[88];
  1182. uint8_t halfV[64];
  1183. uint8_t halfHV[64];
  1184. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  1185. wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8);
  1186. wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
  1187. put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
  1188. }
  1189. static void put_mspel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){
  1190. uint8_t halfH[88];
  1191. uint8_t halfV[64];
  1192. uint8_t halfHV[64];
  1193. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  1194. wmv2_mspel8_v_lowpass(halfV, src+1, 8, stride, 8);
  1195. wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
  1196. put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
  1197. }
  1198. static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){
  1199. uint8_t halfH[88];
  1200. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  1201. wmv2_mspel8_v_lowpass(dst, halfH+8, stride, 8, 8);
  1202. }
  1203. static inline int pix_abs16x16_c(UINT8 *pix1, UINT8 *pix2, int line_size)
  1204. {
  1205. int s, i;
  1206. s = 0;
  1207. for(i=0;i<16;i++) {
  1208. s += abs(pix1[0] - pix2[0]);
  1209. s += abs(pix1[1] - pix2[1]);
  1210. s += abs(pix1[2] - pix2[2]);
  1211. s += abs(pix1[3] - pix2[3]);
  1212. s += abs(pix1[4] - pix2[4]);
  1213. s += abs(pix1[5] - pix2[5]);
  1214. s += abs(pix1[6] - pix2[6]);
  1215. s += abs(pix1[7] - pix2[7]);
  1216. s += abs(pix1[8] - pix2[8]);
  1217. s += abs(pix1[9] - pix2[9]);
  1218. s += abs(pix1[10] - pix2[10]);
  1219. s += abs(pix1[11] - pix2[11]);
  1220. s += abs(pix1[12] - pix2[12]);
  1221. s += abs(pix1[13] - pix2[13]);
  1222. s += abs(pix1[14] - pix2[14]);
  1223. s += abs(pix1[15] - pix2[15]);
  1224. pix1 += line_size;
  1225. pix2 += line_size;
  1226. }
  1227. return s;
  1228. }
  1229. static int pix_abs16x16_x2_c(UINT8 *pix1, UINT8 *pix2, int line_size)
  1230. {
  1231. int s, i;
  1232. s = 0;
  1233. for(i=0;i<16;i++) {
  1234. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  1235. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  1236. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  1237. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  1238. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  1239. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  1240. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  1241. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  1242. s += abs(pix1[8] - avg2(pix2[8], pix2[9]));
  1243. s += abs(pix1[9] - avg2(pix2[9], pix2[10]));
  1244. s += abs(pix1[10] - avg2(pix2[10], pix2[11]));
  1245. s += abs(pix1[11] - avg2(pix2[11], pix2[12]));
  1246. s += abs(pix1[12] - avg2(pix2[12], pix2[13]));
  1247. s += abs(pix1[13] - avg2(pix2[13], pix2[14]));
  1248. s += abs(pix1[14] - avg2(pix2[14], pix2[15]));
  1249. s += abs(pix1[15] - avg2(pix2[15], pix2[16]));
  1250. pix1 += line_size;
  1251. pix2 += line_size;
  1252. }
  1253. return s;
  1254. }
  1255. static int pix_abs16x16_y2_c(UINT8 *pix1, UINT8 *pix2, int line_size)
  1256. {
  1257. int s, i;
  1258. UINT8 *pix3 = pix2 + line_size;
  1259. s = 0;
  1260. for(i=0;i<16;i++) {
  1261. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  1262. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  1263. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  1264. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  1265. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  1266. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  1267. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  1268. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  1269. s += abs(pix1[8] - avg2(pix2[8], pix3[8]));
  1270. s += abs(pix1[9] - avg2(pix2[9], pix3[9]));
  1271. s += abs(pix1[10] - avg2(pix2[10], pix3[10]));
  1272. s += abs(pix1[11] - avg2(pix2[11], pix3[11]));
  1273. s += abs(pix1[12] - avg2(pix2[12], pix3[12]));
  1274. s += abs(pix1[13] - avg2(pix2[13], pix3[13]));
  1275. s += abs(pix1[14] - avg2(pix2[14], pix3[14]));
  1276. s += abs(pix1[15] - avg2(pix2[15], pix3[15]));
  1277. pix1 += line_size;
  1278. pix2 += line_size;
  1279. pix3 += line_size;
  1280. }
  1281. return s;
  1282. }
  1283. static int pix_abs16x16_xy2_c(UINT8 *pix1, UINT8 *pix2, int line_size)
  1284. {
  1285. int s, i;
  1286. UINT8 *pix3 = pix2 + line_size;
  1287. s = 0;
  1288. for(i=0;i<16;i++) {
  1289. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  1290. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  1291. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  1292. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  1293. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  1294. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  1295. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  1296. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  1297. s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9]));
  1298. s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10]));
  1299. s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11]));
  1300. s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12]));
  1301. s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13]));
  1302. s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14]));
  1303. s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15]));
  1304. s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16]));
  1305. pix1 += line_size;
  1306. pix2 += line_size;
  1307. pix3 += line_size;
  1308. }
  1309. return s;
  1310. }
  1311. static inline int pix_abs8x8_c(UINT8 *pix1, UINT8 *pix2, int line_size)
  1312. {
  1313. int s, i;
  1314. s = 0;
  1315. for(i=0;i<8;i++) {
  1316. s += abs(pix1[0] - pix2[0]);
  1317. s += abs(pix1[1] - pix2[1]);
  1318. s += abs(pix1[2] - pix2[2]);
  1319. s += abs(pix1[3] - pix2[3]);
  1320. s += abs(pix1[4] - pix2[4]);
  1321. s += abs(pix1[5] - pix2[5]);
  1322. s += abs(pix1[6] - pix2[6]);
  1323. s += abs(pix1[7] - pix2[7]);
  1324. pix1 += line_size;
  1325. pix2 += line_size;
  1326. }
  1327. return s;
  1328. }
  1329. static int pix_abs8x8_x2_c(UINT8 *pix1, UINT8 *pix2, int line_size)
  1330. {
  1331. int s, i;
  1332. s = 0;
  1333. for(i=0;i<8;i++) {
  1334. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  1335. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  1336. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  1337. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  1338. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  1339. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  1340. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  1341. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  1342. pix1 += line_size;
  1343. pix2 += line_size;
  1344. }
  1345. return s;
  1346. }
  1347. static int pix_abs8x8_y2_c(UINT8 *pix1, UINT8 *pix2, int line_size)
  1348. {
  1349. int s, i;
  1350. UINT8 *pix3 = pix2 + line_size;
  1351. s = 0;
  1352. for(i=0;i<8;i++) {
  1353. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  1354. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  1355. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  1356. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  1357. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  1358. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  1359. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  1360. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  1361. pix1 += line_size;
  1362. pix2 += line_size;
  1363. pix3 += line_size;
  1364. }
  1365. return s;
  1366. }
  1367. static int pix_abs8x8_xy2_c(UINT8 *pix1, UINT8 *pix2, int line_size)
  1368. {
  1369. int s, i;
  1370. UINT8 *pix3 = pix2 + line_size;
  1371. s = 0;
  1372. for(i=0;i<8;i++) {
  1373. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  1374. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  1375. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  1376. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  1377. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  1378. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  1379. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  1380. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  1381. pix1 += line_size;
  1382. pix2 += line_size;
  1383. pix3 += line_size;
  1384. }
  1385. return s;
  1386. }
  1387. static int sad16x16_c(void *s, uint8_t *a, uint8_t *b, int stride){
  1388. return pix_abs16x16_c(a,b,stride);
  1389. }
  1390. static int sad8x8_c(void *s, uint8_t *a, uint8_t *b, int stride){
  1391. return pix_abs8x8_c(a,b,stride);
  1392. }
  1393. void ff_block_permute(DCTELEM *block, UINT8 *permutation, const UINT8 *scantable, int last)
  1394. {
  1395. int i;
  1396. DCTELEM temp[64];
  1397. if(last<=0) return;
  1398. //if(permutation[1]==1) return; //FIXME its ok but not clean and might fail for some perms
  1399. for(i=0; i<=last; i++){
  1400. const int j= scantable[i];
  1401. temp[j]= block[j];
  1402. block[j]=0;
  1403. }
  1404. for(i=0; i<=last; i++){
  1405. const int j= scantable[i];
  1406. const int perm_j= permutation[j];
  1407. block[perm_j]= temp[j];
  1408. }
  1409. }
  1410. static void clear_blocks_c(DCTELEM *blocks)
  1411. {
  1412. memset(blocks, 0, sizeof(DCTELEM)*6*64);
  1413. }
  1414. static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){
  1415. int i;
  1416. for(i=0; i+7<w; i++){
  1417. dst[i+0] += src[i+0];
  1418. dst[i+1] += src[i+1];
  1419. dst[i+2] += src[i+2];
  1420. dst[i+3] += src[i+3];
  1421. dst[i+4] += src[i+4];
  1422. dst[i+5] += src[i+5];
  1423. dst[i+6] += src[i+6];
  1424. dst[i+7] += src[i+7];
  1425. }
  1426. for(; i<w; i++)
  1427. dst[i+0] += src[i+0];
  1428. }
  1429. static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
  1430. int i;
  1431. for(i=0; i+7<w; i++){
  1432. dst[i+0] = src1[i+0]-src2[i+0];
  1433. dst[i+1] = src1[i+1]-src2[i+1];
  1434. dst[i+2] = src1[i+2]-src2[i+2];
  1435. dst[i+3] = src1[i+3]-src2[i+3];
  1436. dst[i+4] = src1[i+4]-src2[i+4];
  1437. dst[i+5] = src1[i+5]-src2[i+5];
  1438. dst[i+6] = src1[i+6]-src2[i+6];
  1439. dst[i+7] = src1[i+7]-src2[i+7];
  1440. }
  1441. for(; i<w; i++)
  1442. dst[i+0] = src1[i+0]-src2[i+0];
  1443. }
  1444. #define BUTTERFLY2(o1,o2,i1,i2) \
  1445. o1= (i1)+(i2);\
  1446. o2= (i1)-(i2);
  1447. #define BUTTERFLY1(x,y) \
  1448. {\
  1449. int a,b;\
  1450. a= x;\
  1451. b= y;\
  1452. x= a+b;\
  1453. y= a-b;\
  1454. }
  1455. #define BUTTERFLYA(x,y) (ABS((x)+(y)) + ABS((x)-(y)))
  1456. static int hadamard8_diff_c(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride){
  1457. int i;
  1458. int temp[64];
  1459. int sum=0;
  1460. for(i=0; i<8; i++){
  1461. //FIXME try pointer walks
  1462. 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]);
  1463. 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]);
  1464. 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]);
  1465. 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]);
  1466. BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
  1467. BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
  1468. BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
  1469. BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
  1470. BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
  1471. BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
  1472. BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
  1473. BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
  1474. }
  1475. for(i=0; i<8; i++){
  1476. BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
  1477. BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
  1478. BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
  1479. BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
  1480. BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
  1481. BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
  1482. BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
  1483. BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
  1484. sum +=
  1485. BUTTERFLYA(temp[8*0+i], temp[8*4+i])
  1486. +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
  1487. +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
  1488. +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
  1489. }
  1490. #if 0
  1491. static int maxi=0;
  1492. if(sum>maxi){
  1493. maxi=sum;
  1494. printf("MAX:%d\n", maxi);
  1495. }
  1496. #endif
  1497. return sum;
  1498. }
  1499. static int hadamard8_abs_c(uint8_t *src, int stride, int mean){
  1500. int i;
  1501. int temp[64];
  1502. int sum=0;
  1503. //FIXME OOOPS ignore 0 term instead of mean mess
  1504. for(i=0; i<8; i++){
  1505. //FIXME try pointer walks
  1506. BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0]-mean,src[stride*i+1]-mean);
  1507. BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2]-mean,src[stride*i+3]-mean);
  1508. BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4]-mean,src[stride*i+5]-mean);
  1509. BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6]-mean,src[stride*i+7]-mean);
  1510. BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
  1511. BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
  1512. BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
  1513. BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
  1514. BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
  1515. BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
  1516. BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
  1517. BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
  1518. }
  1519. for(i=0; i<8; i++){
  1520. BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
  1521. BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
  1522. BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
  1523. BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
  1524. BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
  1525. BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
  1526. BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
  1527. BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
  1528. sum +=
  1529. BUTTERFLYA(temp[8*0+i], temp[8*4+i])
  1530. +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
  1531. +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
  1532. +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
  1533. }
  1534. return sum;
  1535. }
  1536. static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride){
  1537. MpegEncContext * const s= (MpegEncContext *)c;
  1538. DCTELEM temp[64];
  1539. int sum=0, i;
  1540. s->dsp.diff_pixels(temp, src1, src2, stride);
  1541. s->fdct(temp);
  1542. for(i=0; i<64; i++)
  1543. sum+= ABS(temp[i]);
  1544. return sum;
  1545. }
  1546. void simple_idct(INT16 *block); //FIXME
  1547. static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride){
  1548. MpegEncContext * const s= (MpegEncContext *)c;
  1549. DCTELEM temp[64], bak[64];
  1550. int sum=0, i;
  1551. s->mb_intra=0;
  1552. s->dsp.diff_pixels(temp, src1, src2, stride);
  1553. memcpy(bak, temp, 64*sizeof(DCTELEM));
  1554. s->dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  1555. s->dct_unquantize(s, temp, 0, s->qscale);
  1556. simple_idct(temp); //FIXME
  1557. for(i=0; i<64; i++)
  1558. sum+= (temp[i]-bak[i])*(temp[i]-bak[i]);
  1559. return sum;
  1560. }
  1561. WARPER88_1616(hadamard8_diff_c, hadamard8_diff16_c)
  1562. WARPER88_1616(dct_sad8x8_c, dct_sad16x16_c)
  1563. WARPER88_1616(quant_psnr8x8_c, quant_psnr16x16_c)
  1564. void dsputil_init(DSPContext* c, unsigned mask)
  1565. {
  1566. static int init_done = 0;
  1567. int i;
  1568. if (!init_done) {
  1569. for(i=0;i<256;i++) cropTbl[i + MAX_NEG_CROP] = i;
  1570. for(i=0;i<MAX_NEG_CROP;i++) {
  1571. cropTbl[i] = 0;
  1572. cropTbl[i + MAX_NEG_CROP + 256] = 255;
  1573. }
  1574. for(i=0;i<512;i++) {
  1575. squareTbl[i] = (i - 256) * (i - 256);
  1576. }
  1577. for(i=0; i<64; i++) inv_zigzag_direct16[ff_zigzag_direct[i]]= i+1;
  1578. init_done = 1;
  1579. }
  1580. c->get_pixels = get_pixels_c;
  1581. c->diff_pixels = diff_pixels_c;
  1582. c->put_pixels_clamped = put_pixels_clamped_c;
  1583. c->add_pixels_clamped = add_pixels_clamped_c;
  1584. c->gmc1 = gmc1_c;
  1585. c->gmc = gmc_c;
  1586. c->clear_blocks = clear_blocks_c;
  1587. c->pix_sum = pix_sum_c;
  1588. c->pix_norm1 = pix_norm1_c;
  1589. c->sse[0]= sse16_c;
  1590. c->sse[1]= sse8_c;
  1591. /* TODO [0] 16 [1] 8 */
  1592. c->pix_abs16x16 = pix_abs16x16_c;
  1593. c->pix_abs16x16_x2 = pix_abs16x16_x2_c;
  1594. c->pix_abs16x16_y2 = pix_abs16x16_y2_c;
  1595. c->pix_abs16x16_xy2 = pix_abs16x16_xy2_c;
  1596. c->pix_abs8x8 = pix_abs8x8_c;
  1597. c->pix_abs8x8_x2 = pix_abs8x8_x2_c;
  1598. c->pix_abs8x8_y2 = pix_abs8x8_y2_c;
  1599. c->pix_abs8x8_xy2 = pix_abs8x8_xy2_c;
  1600. #define dspfunc(PFX, IDX, NUM) \
  1601. c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## NUM ## _c; \
  1602. c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## NUM ## _x2_c; \
  1603. c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## NUM ## _y2_c; \
  1604. c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## NUM ## _xy2_c
  1605. dspfunc(put, 0, 16);
  1606. dspfunc(put_no_rnd, 0, 16);
  1607. dspfunc(put, 1, 8);
  1608. dspfunc(put_no_rnd, 1, 8);
  1609. dspfunc(avg, 0, 16);
  1610. dspfunc(avg_no_rnd, 0, 16);
  1611. dspfunc(avg, 1, 8);
  1612. dspfunc(avg_no_rnd, 1, 8);
  1613. #undef dspfunc
  1614. #define dspfunc(PFX, IDX, NUM) \
  1615. c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \
  1616. c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \
  1617. c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \
  1618. c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \
  1619. c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \
  1620. c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \
  1621. c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \
  1622. c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \
  1623. c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \
  1624. c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \
  1625. c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \
  1626. c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \
  1627. c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \
  1628. c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \
  1629. c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \
  1630. c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
  1631. dspfunc(put_qpel, 0, 16);
  1632. dspfunc(put_no_rnd_qpel, 0, 16);
  1633. dspfunc(avg_qpel, 0, 16);
  1634. /* dspfunc(avg_no_rnd_qpel, 0, 16); */
  1635. dspfunc(put_qpel, 1, 8);
  1636. dspfunc(put_no_rnd_qpel, 1, 8);
  1637. dspfunc(avg_qpel, 1, 8);
  1638. /* dspfunc(avg_no_rnd_qpel, 1, 8); */
  1639. #undef dspfunc
  1640. c->put_mspel_pixels_tab[0]= put_mspel8_mc00_c;
  1641. c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
  1642. c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c;
  1643. c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c;
  1644. c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c;
  1645. c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c;
  1646. c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c;
  1647. c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c;
  1648. c->hadamard8_diff[0]= hadamard8_diff16_c;
  1649. c->hadamard8_diff[1]= hadamard8_diff_c;
  1650. c->hadamard8_abs = hadamard8_abs_c;
  1651. c->dct_sad[0]= dct_sad16x16_c;
  1652. c->dct_sad[1]= dct_sad8x8_c;
  1653. c->sad[0]= sad16x16_c;
  1654. c->sad[1]= sad8x8_c;
  1655. c->quant_psnr[0]= quant_psnr16x16_c;
  1656. c->quant_psnr[1]= quant_psnr8x8_c;
  1657. c->add_bytes= add_bytes_c;
  1658. c->diff_bytes= diff_bytes_c;
  1659. #ifdef HAVE_MMX
  1660. dsputil_init_mmx(c, mask);
  1661. if (ff_bit_exact)
  1662. {
  1663. /* FIXME - AVCodec context should have flag for bitexact match */
  1664. /* fprintf(stderr, "\n\n\nff_bit_exact %d\n\n\n\n", ff_bit_exact); */
  1665. dsputil_set_bit_exact_mmx(c, mask);
  1666. }
  1667. #endif
  1668. #ifdef ARCH_ARMV4L
  1669. dsputil_init_armv4l(c, mask);
  1670. #endif
  1671. #ifdef HAVE_MLIB
  1672. dsputil_init_mlib(c, mask);
  1673. #endif
  1674. #ifdef ARCH_ALPHA
  1675. dsputil_init_alpha(c, mask);
  1676. #endif
  1677. #ifdef ARCH_POWERPC
  1678. dsputil_init_ppc(c, mask);
  1679. #endif
  1680. #ifdef HAVE_MMI
  1681. dsputil_init_mmi(c, mask);
  1682. #endif
  1683. }
  1684. /* remove any non bit exact operation (testing purpose) */
  1685. void avcodec_set_bit_exact(void)
  1686. {
  1687. ff_bit_exact=1;
  1688. #ifdef HAVE_MMX
  1689. // FIXME - better set_bit_exact
  1690. // dsputil_set_bit_exact_mmx();
  1691. #endif
  1692. }