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.

3166 lines
117KB

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