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.

3283 lines
120KB

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