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.

3324 lines
121KB

  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 put_no_rnd_pixels16_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){
  840. put_no_rnd_pixels16_l2(dst, a, b, stride, stride, stride, h);
  841. }
  842. static void put_no_rnd_pixels8_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){
  843. put_no_rnd_pixels8_l2(dst, a, b, stride, stride, stride, h);
  844. }
  845. static void gmc1_c(uint8_t *dst, uint8_t *src, int stride, int h, int x16, int y16, int rounder)
  846. {
  847. const int A=(16-x16)*(16-y16);
  848. const int B=( x16)*(16-y16);
  849. const int C=(16-x16)*( y16);
  850. const int D=( x16)*( y16);
  851. int i;
  852. for(i=0; i<h; i++)
  853. {
  854. dst[0]= (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + rounder)>>8;
  855. dst[1]= (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + rounder)>>8;
  856. dst[2]= (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + rounder)>>8;
  857. dst[3]= (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + rounder)>>8;
  858. dst[4]= (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + rounder)>>8;
  859. dst[5]= (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + rounder)>>8;
  860. dst[6]= (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + rounder)>>8;
  861. dst[7]= (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + rounder)>>8;
  862. dst+= stride;
  863. src+= stride;
  864. }
  865. }
  866. static void gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
  867. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
  868. {
  869. int y, vx, vy;
  870. const int s= 1<<shift;
  871. width--;
  872. height--;
  873. for(y=0; y<h; y++){
  874. int x;
  875. vx= ox;
  876. vy= oy;
  877. for(x=0; x<8; x++){ //XXX FIXME optimize
  878. int src_x, src_y, frac_x, frac_y, index;
  879. src_x= vx>>16;
  880. src_y= vy>>16;
  881. frac_x= src_x&(s-1);
  882. frac_y= src_y&(s-1);
  883. src_x>>=shift;
  884. src_y>>=shift;
  885. if((unsigned)src_x < width){
  886. if((unsigned)src_y < height){
  887. index= src_x + src_y*stride;
  888. dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
  889. + src[index +1]* frac_x )*(s-frac_y)
  890. + ( src[index+stride ]*(s-frac_x)
  891. + src[index+stride+1]* frac_x )* frac_y
  892. + r)>>(shift*2);
  893. }else{
  894. index= src_x + clip(src_y, 0, height)*stride;
  895. dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
  896. + src[index +1]* frac_x )*s
  897. + r)>>(shift*2);
  898. }
  899. }else{
  900. if((unsigned)src_y < height){
  901. index= clip(src_x, 0, width) + src_y*stride;
  902. dst[y*stride + x]= ( ( src[index ]*(s-frac_y)
  903. + src[index+stride ]* frac_y )*s
  904. + r)>>(shift*2);
  905. }else{
  906. index= clip(src_x, 0, width) + clip(src_y, 0, height)*stride;
  907. dst[y*stride + x]= src[index ];
  908. }
  909. }
  910. vx+= dxx;
  911. vy+= dyx;
  912. }
  913. ox += dxy;
  914. oy += dyy;
  915. }
  916. }
  917. static inline void put_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  918. switch(width){
  919. case 2: put_pixels2_c (dst, src, stride, height); break;
  920. case 4: put_pixels4_c (dst, src, stride, height); break;
  921. case 8: put_pixels8_c (dst, src, stride, height); break;
  922. case 16:put_pixels16_c(dst, src, stride, height); break;
  923. }
  924. }
  925. static inline void put_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  926. int i,j;
  927. for (i=0; i < height; i++) {
  928. for (j=0; j < width; j++) {
  929. dst[j] = (683*(2*src[j] + src[j+1] + 1)) >> 11;
  930. }
  931. src += stride;
  932. dst += stride;
  933. }
  934. }
  935. static inline void put_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  936. int i,j;
  937. for (i=0; i < height; i++) {
  938. for (j=0; j < width; j++) {
  939. dst[j] = (683*(src[j] + 2*src[j+1] + 1)) >> 11;
  940. }
  941. src += stride;
  942. dst += stride;
  943. }
  944. }
  945. static inline void put_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  946. int i,j;
  947. for (i=0; i < height; i++) {
  948. for (j=0; j < width; j++) {
  949. dst[j] = (683*(2*src[j] + src[j+stride] + 1)) >> 11;
  950. }
  951. src += stride;
  952. dst += stride;
  953. }
  954. }
  955. static inline void put_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  956. int i,j;
  957. for (i=0; i < height; i++) {
  958. for (j=0; j < width; j++) {
  959. dst[j] = (2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15;
  960. }
  961. src += stride;
  962. dst += stride;
  963. }
  964. }
  965. static inline void put_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  966. int i,j;
  967. for (i=0; i < height; i++) {
  968. for (j=0; j < width; j++) {
  969. dst[j] = (2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
  970. }
  971. src += stride;
  972. dst += stride;
  973. }
  974. }
  975. static inline void put_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  976. int i,j;
  977. for (i=0; i < height; i++) {
  978. for (j=0; j < width; j++) {
  979. dst[j] = (683*(src[j] + 2*src[j+stride] + 1)) >> 11;
  980. }
  981. src += stride;
  982. dst += stride;
  983. }
  984. }
  985. static inline void put_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  986. int i,j;
  987. for (i=0; i < height; i++) {
  988. for (j=0; j < width; j++) {
  989. dst[j] = (2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
  990. }
  991. src += stride;
  992. dst += stride;
  993. }
  994. }
  995. static inline void put_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  996. int i,j;
  997. for (i=0; i < height; i++) {
  998. for (j=0; j < width; j++) {
  999. dst[j] = (2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15;
  1000. }
  1001. src += stride;
  1002. dst += stride;
  1003. }
  1004. }
  1005. static inline void avg_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1006. switch(width){
  1007. case 2: avg_pixels2_c (dst, src, stride, height); break;
  1008. case 4: avg_pixels4_c (dst, src, stride, height); break;
  1009. case 8: avg_pixels8_c (dst, src, stride, height); break;
  1010. case 16:avg_pixels16_c(dst, src, stride, height); break;
  1011. }
  1012. }
  1013. static inline void avg_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1014. int i,j;
  1015. for (i=0; i < height; i++) {
  1016. for (j=0; j < width; j++) {
  1017. dst[j] = (dst[j] + ((683*(2*src[j] + src[j+1] + 1)) >> 11) + 1) >> 1;
  1018. }
  1019. src += stride;
  1020. dst += stride;
  1021. }
  1022. }
  1023. static inline void avg_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1024. int i,j;
  1025. for (i=0; i < height; i++) {
  1026. for (j=0; j < width; j++) {
  1027. dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+1] + 1)) >> 11) + 1) >> 1;
  1028. }
  1029. src += stride;
  1030. dst += stride;
  1031. }
  1032. }
  1033. static inline void avg_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1034. int i,j;
  1035. for (i=0; i < height; i++) {
  1036. for (j=0; j < width; j++) {
  1037. dst[j] = (dst[j] + ((683*(2*src[j] + src[j+stride] + 1)) >> 11) + 1) >> 1;
  1038. }
  1039. src += stride;
  1040. dst += stride;
  1041. }
  1042. }
  1043. static inline void avg_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1044. int i,j;
  1045. for (i=0; i < height; i++) {
  1046. for (j=0; j < width; j++) {
  1047. 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;
  1048. }
  1049. src += stride;
  1050. dst += stride;
  1051. }
  1052. }
  1053. static inline void avg_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1054. int i,j;
  1055. for (i=0; i < height; i++) {
  1056. for (j=0; j < width; j++) {
  1057. 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;
  1058. }
  1059. src += stride;
  1060. dst += stride;
  1061. }
  1062. }
  1063. static inline void avg_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1064. int i,j;
  1065. for (i=0; i < height; i++) {
  1066. for (j=0; j < width; j++) {
  1067. dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+stride] + 1)) >> 11) + 1) >> 1;
  1068. }
  1069. src += stride;
  1070. dst += stride;
  1071. }
  1072. }
  1073. static inline void avg_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1074. int i,j;
  1075. for (i=0; i < height; i++) {
  1076. for (j=0; j < width; j++) {
  1077. 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;
  1078. }
  1079. src += stride;
  1080. dst += stride;
  1081. }
  1082. }
  1083. static inline void avg_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1084. int i,j;
  1085. for (i=0; i < height; i++) {
  1086. for (j=0; j < width; j++) {
  1087. 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;
  1088. }
  1089. src += stride;
  1090. dst += stride;
  1091. }
  1092. }
  1093. #if 0
  1094. #define TPEL_WIDTH(width)\
  1095. static void put_tpel_pixels ## width ## _mc00_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1096. void put_tpel_pixels_mc00_c(dst, src, stride, width, height);}\
  1097. static void put_tpel_pixels ## width ## _mc10_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1098. void put_tpel_pixels_mc10_c(dst, src, stride, width, height);}\
  1099. static void put_tpel_pixels ## width ## _mc20_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1100. void put_tpel_pixels_mc20_c(dst, src, stride, width, height);}\
  1101. static void put_tpel_pixels ## width ## _mc01_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1102. void put_tpel_pixels_mc01_c(dst, src, stride, width, height);}\
  1103. static void put_tpel_pixels ## width ## _mc11_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1104. void put_tpel_pixels_mc11_c(dst, src, stride, width, height);}\
  1105. static void put_tpel_pixels ## width ## _mc21_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1106. void put_tpel_pixels_mc21_c(dst, src, stride, width, height);}\
  1107. static void put_tpel_pixels ## width ## _mc02_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1108. void put_tpel_pixels_mc02_c(dst, src, stride, width, height);}\
  1109. static void put_tpel_pixels ## width ## _mc12_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1110. void put_tpel_pixels_mc12_c(dst, src, stride, width, height);}\
  1111. static void put_tpel_pixels ## width ## _mc22_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1112. void put_tpel_pixels_mc22_c(dst, src, stride, width, height);}
  1113. #endif
  1114. #define H264_CHROMA_MC(OPNAME, OP)\
  1115. 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){\
  1116. const int A=(8-x)*(8-y);\
  1117. const int B=( x)*(8-y);\
  1118. const int C=(8-x)*( y);\
  1119. const int D=( x)*( y);\
  1120. int i;\
  1121. \
  1122. assert(x<8 && y<8 && x>=0 && y>=0);\
  1123. \
  1124. for(i=0; i<h; i++)\
  1125. {\
  1126. OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
  1127. OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
  1128. dst+= stride;\
  1129. src+= stride;\
  1130. }\
  1131. }\
  1132. \
  1133. 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){\
  1134. const int A=(8-x)*(8-y);\
  1135. const int B=( x)*(8-y);\
  1136. const int C=(8-x)*( y);\
  1137. const int D=( x)*( y);\
  1138. int i;\
  1139. \
  1140. assert(x<8 && y<8 && x>=0 && y>=0);\
  1141. \
  1142. for(i=0; i<h; i++)\
  1143. {\
  1144. OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
  1145. OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
  1146. OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
  1147. OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
  1148. dst+= stride;\
  1149. src+= stride;\
  1150. }\
  1151. }\
  1152. \
  1153. 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){\
  1154. const int A=(8-x)*(8-y);\
  1155. const int B=( x)*(8-y);\
  1156. const int C=(8-x)*( y);\
  1157. const int D=( x)*( y);\
  1158. int i;\
  1159. \
  1160. assert(x<8 && y<8 && x>=0 && y>=0);\
  1161. \
  1162. for(i=0; i<h; i++)\
  1163. {\
  1164. OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
  1165. OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
  1166. OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
  1167. OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
  1168. OP(dst[4], (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5]));\
  1169. OP(dst[5], (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6]));\
  1170. OP(dst[6], (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7]));\
  1171. OP(dst[7], (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8]));\
  1172. dst+= stride;\
  1173. src+= stride;\
  1174. }\
  1175. }
  1176. #define op_avg(a, b) a = (((a)+(((b) + 32)>>6)+1)>>1)
  1177. #define op_put(a, b) a = (((b) + 32)>>6)
  1178. H264_CHROMA_MC(put_ , op_put)
  1179. H264_CHROMA_MC(avg_ , op_avg)
  1180. #undef op_avg
  1181. #undef op_put
  1182. static inline void copy_block4(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  1183. {
  1184. int i;
  1185. for(i=0; i<h; i++)
  1186. {
  1187. ST32(dst , LD32(src ));
  1188. dst+=dstStride;
  1189. src+=srcStride;
  1190. }
  1191. }
  1192. static inline void copy_block8(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  1193. {
  1194. int i;
  1195. for(i=0; i<h; i++)
  1196. {
  1197. ST32(dst , LD32(src ));
  1198. ST32(dst+4 , LD32(src+4 ));
  1199. dst+=dstStride;
  1200. src+=srcStride;
  1201. }
  1202. }
  1203. static inline void copy_block16(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  1204. {
  1205. int i;
  1206. for(i=0; i<h; i++)
  1207. {
  1208. ST32(dst , LD32(src ));
  1209. ST32(dst+4 , LD32(src+4 ));
  1210. ST32(dst+8 , LD32(src+8 ));
  1211. ST32(dst+12, LD32(src+12));
  1212. dst+=dstStride;
  1213. src+=srcStride;
  1214. }
  1215. }
  1216. static inline void copy_block17(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  1217. {
  1218. int i;
  1219. for(i=0; i<h; i++)
  1220. {
  1221. ST32(dst , LD32(src ));
  1222. ST32(dst+4 , LD32(src+4 ));
  1223. ST32(dst+8 , LD32(src+8 ));
  1224. ST32(dst+12, LD32(src+12));
  1225. dst[16]= src[16];
  1226. dst+=dstStride;
  1227. src+=srcStride;
  1228. }
  1229. }
  1230. static inline void copy_block9(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  1231. {
  1232. int i;
  1233. for(i=0; i<h; i++)
  1234. {
  1235. ST32(dst , LD32(src ));
  1236. ST32(dst+4 , LD32(src+4 ));
  1237. dst[8]= src[8];
  1238. dst+=dstStride;
  1239. src+=srcStride;
  1240. }
  1241. }
  1242. #define QPEL_MC(r, OPNAME, RND, OP) \
  1243. static void OPNAME ## mpeg4_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  1244. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1245. int i;\
  1246. for(i=0; i<h; i++)\
  1247. {\
  1248. OP(dst[0], (src[0]+src[1])*20 - (src[0]+src[2])*6 + (src[1]+src[3])*3 - (src[2]+src[4]));\
  1249. OP(dst[1], (src[1]+src[2])*20 - (src[0]+src[3])*6 + (src[0]+src[4])*3 - (src[1]+src[5]));\
  1250. OP(dst[2], (src[2]+src[3])*20 - (src[1]+src[4])*6 + (src[0]+src[5])*3 - (src[0]+src[6]));\
  1251. OP(dst[3], (src[3]+src[4])*20 - (src[2]+src[5])*6 + (src[1]+src[6])*3 - (src[0]+src[7]));\
  1252. OP(dst[4], (src[4]+src[5])*20 - (src[3]+src[6])*6 + (src[2]+src[7])*3 - (src[1]+src[8]));\
  1253. OP(dst[5], (src[5]+src[6])*20 - (src[4]+src[7])*6 + (src[3]+src[8])*3 - (src[2]+src[8]));\
  1254. OP(dst[6], (src[6]+src[7])*20 - (src[5]+src[8])*6 + (src[4]+src[8])*3 - (src[3]+src[7]));\
  1255. OP(dst[7], (src[7]+src[8])*20 - (src[6]+src[8])*6 + (src[5]+src[7])*3 - (src[4]+src[6]));\
  1256. dst+=dstStride;\
  1257. src+=srcStride;\
  1258. }\
  1259. }\
  1260. \
  1261. static void OPNAME ## mpeg4_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1262. const int w=8;\
  1263. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1264. int i;\
  1265. for(i=0; i<w; i++)\
  1266. {\
  1267. const int src0= src[0*srcStride];\
  1268. const int src1= src[1*srcStride];\
  1269. const int src2= src[2*srcStride];\
  1270. const int src3= src[3*srcStride];\
  1271. const int src4= src[4*srcStride];\
  1272. const int src5= src[5*srcStride];\
  1273. const int src6= src[6*srcStride];\
  1274. const int src7= src[7*srcStride];\
  1275. const int src8= src[8*srcStride];\
  1276. OP(dst[0*dstStride], (src0+src1)*20 - (src0+src2)*6 + (src1+src3)*3 - (src2+src4));\
  1277. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*6 + (src0+src4)*3 - (src1+src5));\
  1278. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*6 + (src0+src5)*3 - (src0+src6));\
  1279. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*6 + (src1+src6)*3 - (src0+src7));\
  1280. OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*6 + (src2+src7)*3 - (src1+src8));\
  1281. OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*6 + (src3+src8)*3 - (src2+src8));\
  1282. OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*6 + (src4+src8)*3 - (src3+src7));\
  1283. OP(dst[7*dstStride], (src7+src8)*20 - (src6+src8)*6 + (src5+src7)*3 - (src4+src6));\
  1284. dst++;\
  1285. src++;\
  1286. }\
  1287. }\
  1288. \
  1289. static void OPNAME ## mpeg4_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  1290. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1291. int i;\
  1292. \
  1293. for(i=0; i<h; i++)\
  1294. {\
  1295. OP(dst[ 0], (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]));\
  1296. OP(dst[ 1], (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]));\
  1297. OP(dst[ 2], (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]));\
  1298. OP(dst[ 3], (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]));\
  1299. OP(dst[ 4], (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]));\
  1300. OP(dst[ 5], (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]));\
  1301. OP(dst[ 6], (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]));\
  1302. OP(dst[ 7], (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]));\
  1303. OP(dst[ 8], (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]));\
  1304. OP(dst[ 9], (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]));\
  1305. OP(dst[10], (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]));\
  1306. OP(dst[11], (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]));\
  1307. OP(dst[12], (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]));\
  1308. OP(dst[13], (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]));\
  1309. OP(dst[14], (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]));\
  1310. OP(dst[15], (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]));\
  1311. dst+=dstStride;\
  1312. src+=srcStride;\
  1313. }\
  1314. }\
  1315. \
  1316. static void OPNAME ## mpeg4_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1317. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1318. int i;\
  1319. const int w=16;\
  1320. for(i=0; i<w; i++)\
  1321. {\
  1322. const int src0= src[0*srcStride];\
  1323. const int src1= src[1*srcStride];\
  1324. const int src2= src[2*srcStride];\
  1325. const int src3= src[3*srcStride];\
  1326. const int src4= src[4*srcStride];\
  1327. const int src5= src[5*srcStride];\
  1328. const int src6= src[6*srcStride];\
  1329. const int src7= src[7*srcStride];\
  1330. const int src8= src[8*srcStride];\
  1331. const int src9= src[9*srcStride];\
  1332. const int src10= src[10*srcStride];\
  1333. const int src11= src[11*srcStride];\
  1334. const int src12= src[12*srcStride];\
  1335. const int src13= src[13*srcStride];\
  1336. const int src14= src[14*srcStride];\
  1337. const int src15= src[15*srcStride];\
  1338. const int src16= src[16*srcStride];\
  1339. OP(dst[ 0*dstStride], (src0 +src1 )*20 - (src0 +src2 )*6 + (src1 +src3 )*3 - (src2 +src4 ));\
  1340. OP(dst[ 1*dstStride], (src1 +src2 )*20 - (src0 +src3 )*6 + (src0 +src4 )*3 - (src1 +src5 ));\
  1341. OP(dst[ 2*dstStride], (src2 +src3 )*20 - (src1 +src4 )*6 + (src0 +src5 )*3 - (src0 +src6 ));\
  1342. OP(dst[ 3*dstStride], (src3 +src4 )*20 - (src2 +src5 )*6 + (src1 +src6 )*3 - (src0 +src7 ));\
  1343. OP(dst[ 4*dstStride], (src4 +src5 )*20 - (src3 +src6 )*6 + (src2 +src7 )*3 - (src1 +src8 ));\
  1344. OP(dst[ 5*dstStride], (src5 +src6 )*20 - (src4 +src7 )*6 + (src3 +src8 )*3 - (src2 +src9 ));\
  1345. OP(dst[ 6*dstStride], (src6 +src7 )*20 - (src5 +src8 )*6 + (src4 +src9 )*3 - (src3 +src10));\
  1346. OP(dst[ 7*dstStride], (src7 +src8 )*20 - (src6 +src9 )*6 + (src5 +src10)*3 - (src4 +src11));\
  1347. OP(dst[ 8*dstStride], (src8 +src9 )*20 - (src7 +src10)*6 + (src6 +src11)*3 - (src5 +src12));\
  1348. OP(dst[ 9*dstStride], (src9 +src10)*20 - (src8 +src11)*6 + (src7 +src12)*3 - (src6 +src13));\
  1349. OP(dst[10*dstStride], (src10+src11)*20 - (src9 +src12)*6 + (src8 +src13)*3 - (src7 +src14));\
  1350. OP(dst[11*dstStride], (src11+src12)*20 - (src10+src13)*6 + (src9 +src14)*3 - (src8 +src15));\
  1351. OP(dst[12*dstStride], (src12+src13)*20 - (src11+src14)*6 + (src10+src15)*3 - (src9 +src16));\
  1352. OP(dst[13*dstStride], (src13+src14)*20 - (src12+src15)*6 + (src11+src16)*3 - (src10+src16));\
  1353. OP(dst[14*dstStride], (src14+src15)*20 - (src13+src16)*6 + (src12+src16)*3 - (src11+src15));\
  1354. OP(dst[15*dstStride], (src15+src16)*20 - (src14+src16)*6 + (src13+src15)*3 - (src12+src14));\
  1355. dst++;\
  1356. src++;\
  1357. }\
  1358. }\
  1359. \
  1360. static void OPNAME ## qpel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
  1361. OPNAME ## pixels8_c(dst, src, stride, 8);\
  1362. }\
  1363. \
  1364. static void OPNAME ## qpel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  1365. uint8_t half[64];\
  1366. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  1367. OPNAME ## pixels8_l2(dst, src, half, stride, stride, 8, 8);\
  1368. }\
  1369. \
  1370. static void OPNAME ## qpel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  1371. OPNAME ## mpeg4_qpel8_h_lowpass(dst, src, stride, stride, 8);\
  1372. }\
  1373. \
  1374. static void OPNAME ## qpel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  1375. uint8_t half[64];\
  1376. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  1377. OPNAME ## pixels8_l2(dst, src+1, half, stride, stride, 8, 8);\
  1378. }\
  1379. \
  1380. static void OPNAME ## qpel8_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  1381. uint8_t full[16*9];\
  1382. uint8_t half[64];\
  1383. copy_block9(full, src, 16, stride, 9);\
  1384. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
  1385. OPNAME ## pixels8_l2(dst, full, half, stride, 16, 8, 8);\
  1386. }\
  1387. \
  1388. static void OPNAME ## qpel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  1389. uint8_t full[16*9];\
  1390. copy_block9(full, src, 16, stride, 9);\
  1391. OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);\
  1392. }\
  1393. \
  1394. static void OPNAME ## qpel8_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  1395. uint8_t full[16*9];\
  1396. uint8_t half[64];\
  1397. copy_block9(full, src, 16, stride, 9);\
  1398. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
  1399. OPNAME ## pixels8_l2(dst, full+16, half, stride, 16, 8, 8);\
  1400. }\
  1401. void ff_ ## OPNAME ## qpel8_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1402. uint8_t full[16*9];\
  1403. uint8_t halfH[72];\
  1404. uint8_t halfV[64];\
  1405. uint8_t halfHV[64];\
  1406. copy_block9(full, src, 16, stride, 9);\
  1407. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1408. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  1409. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1410. OPNAME ## pixels8_l4(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1411. }\
  1412. static void OPNAME ## qpel8_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  1413. uint8_t full[16*9];\
  1414. uint8_t halfH[72];\
  1415. uint8_t halfHV[64];\
  1416. copy_block9(full, src, 16, stride, 9);\
  1417. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1418. put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
  1419. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1420. OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
  1421. }\
  1422. void ff_ ## OPNAME ## qpel8_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1423. uint8_t full[16*9];\
  1424. uint8_t halfH[72];\
  1425. uint8_t halfV[64];\
  1426. uint8_t halfHV[64];\
  1427. copy_block9(full, src, 16, stride, 9);\
  1428. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1429. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  1430. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1431. OPNAME ## pixels8_l4(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1432. }\
  1433. static void OPNAME ## qpel8_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  1434. uint8_t full[16*9];\
  1435. uint8_t halfH[72];\
  1436. uint8_t halfHV[64];\
  1437. copy_block9(full, src, 16, stride, 9);\
  1438. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1439. put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
  1440. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1441. OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
  1442. }\
  1443. void ff_ ## OPNAME ## qpel8_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1444. uint8_t full[16*9];\
  1445. uint8_t halfH[72];\
  1446. uint8_t halfV[64];\
  1447. uint8_t halfHV[64];\
  1448. copy_block9(full, src, 16, stride, 9);\
  1449. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1450. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  1451. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1452. OPNAME ## pixels8_l4(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1453. }\
  1454. static void OPNAME ## qpel8_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  1455. uint8_t full[16*9];\
  1456. uint8_t halfH[72];\
  1457. uint8_t halfHV[64];\
  1458. copy_block9(full, src, 16, stride, 9);\
  1459. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1460. put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
  1461. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1462. OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  1463. }\
  1464. void ff_ ## OPNAME ## qpel8_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1465. uint8_t full[16*9];\
  1466. uint8_t halfH[72];\
  1467. uint8_t halfV[64];\
  1468. uint8_t halfHV[64];\
  1469. copy_block9(full, src, 16, stride, 9);\
  1470. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full , 8, 16, 9);\
  1471. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  1472. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1473. OPNAME ## pixels8_l4(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1474. }\
  1475. static void OPNAME ## qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  1476. uint8_t full[16*9];\
  1477. uint8_t halfH[72];\
  1478. uint8_t halfHV[64];\
  1479. copy_block9(full, src, 16, stride, 9);\
  1480. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1481. put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
  1482. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1483. OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  1484. }\
  1485. static void OPNAME ## qpel8_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  1486. uint8_t halfH[72];\
  1487. uint8_t halfHV[64];\
  1488. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1489. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1490. OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
  1491. }\
  1492. static void OPNAME ## qpel8_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  1493. uint8_t halfH[72];\
  1494. uint8_t halfHV[64];\
  1495. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1496. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1497. OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  1498. }\
  1499. void ff_ ## OPNAME ## qpel8_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1500. uint8_t full[16*9];\
  1501. uint8_t halfH[72];\
  1502. uint8_t halfV[64];\
  1503. uint8_t halfHV[64];\
  1504. copy_block9(full, src, 16, stride, 9);\
  1505. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1506. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  1507. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1508. OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
  1509. }\
  1510. static void OPNAME ## qpel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  1511. uint8_t full[16*9];\
  1512. uint8_t halfH[72];\
  1513. copy_block9(full, src, 16, stride, 9);\
  1514. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1515. put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
  1516. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1517. }\
  1518. void ff_ ## OPNAME ## qpel8_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1519. uint8_t full[16*9];\
  1520. uint8_t halfH[72];\
  1521. uint8_t halfV[64];\
  1522. uint8_t halfHV[64];\
  1523. copy_block9(full, src, 16, stride, 9);\
  1524. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1525. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  1526. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1527. OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
  1528. }\
  1529. static void OPNAME ## qpel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  1530. uint8_t full[16*9];\
  1531. uint8_t halfH[72];\
  1532. copy_block9(full, src, 16, stride, 9);\
  1533. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1534. put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
  1535. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1536. }\
  1537. static void OPNAME ## qpel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  1538. uint8_t halfH[72];\
  1539. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1540. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1541. }\
  1542. static void OPNAME ## qpel16_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
  1543. OPNAME ## pixels16_c(dst, src, stride, 16);\
  1544. }\
  1545. \
  1546. static void OPNAME ## qpel16_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  1547. uint8_t half[256];\
  1548. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  1549. OPNAME ## pixels16_l2(dst, src, half, stride, stride, 16, 16);\
  1550. }\
  1551. \
  1552. static void OPNAME ## qpel16_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  1553. OPNAME ## mpeg4_qpel16_h_lowpass(dst, src, stride, stride, 16);\
  1554. }\
  1555. \
  1556. static void OPNAME ## qpel16_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  1557. uint8_t half[256];\
  1558. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  1559. OPNAME ## pixels16_l2(dst, src+1, half, stride, stride, 16, 16);\
  1560. }\
  1561. \
  1562. static void OPNAME ## qpel16_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  1563. uint8_t full[24*17];\
  1564. uint8_t half[256];\
  1565. copy_block17(full, src, 24, stride, 17);\
  1566. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
  1567. OPNAME ## pixels16_l2(dst, full, half, stride, 24, 16, 16);\
  1568. }\
  1569. \
  1570. static void OPNAME ## qpel16_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  1571. uint8_t full[24*17];\
  1572. copy_block17(full, src, 24, stride, 17);\
  1573. OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);\
  1574. }\
  1575. \
  1576. static void OPNAME ## qpel16_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  1577. uint8_t full[24*17];\
  1578. uint8_t half[256];\
  1579. copy_block17(full, src, 24, stride, 17);\
  1580. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
  1581. OPNAME ## pixels16_l2(dst, full+24, half, stride, 24, 16, 16);\
  1582. }\
  1583. void ff_ ## OPNAME ## qpel16_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1584. uint8_t full[24*17];\
  1585. uint8_t halfH[272];\
  1586. uint8_t halfV[256];\
  1587. uint8_t halfHV[256];\
  1588. copy_block17(full, src, 24, stride, 17);\
  1589. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1590. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1591. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1592. OPNAME ## pixels16_l4(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1593. }\
  1594. static void OPNAME ## qpel16_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  1595. uint8_t full[24*17];\
  1596. uint8_t halfH[272];\
  1597. uint8_t halfHV[256];\
  1598. copy_block17(full, src, 24, stride, 17);\
  1599. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1600. put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
  1601. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1602. OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
  1603. }\
  1604. void ff_ ## OPNAME ## qpel16_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1605. uint8_t full[24*17];\
  1606. uint8_t halfH[272];\
  1607. uint8_t halfV[256];\
  1608. uint8_t halfHV[256];\
  1609. copy_block17(full, src, 24, stride, 17);\
  1610. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1611. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1612. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1613. OPNAME ## pixels16_l4(dst, full+1, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1614. }\
  1615. static void OPNAME ## qpel16_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  1616. uint8_t full[24*17];\
  1617. uint8_t halfH[272];\
  1618. uint8_t halfHV[256];\
  1619. copy_block17(full, src, 24, stride, 17);\
  1620. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1621. put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
  1622. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1623. OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
  1624. }\
  1625. void ff_ ## OPNAME ## qpel16_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1626. uint8_t full[24*17];\
  1627. uint8_t halfH[272];\
  1628. uint8_t halfV[256];\
  1629. uint8_t halfHV[256];\
  1630. copy_block17(full, src, 24, stride, 17);\
  1631. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1632. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1633. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1634. OPNAME ## pixels16_l4(dst, full+24, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1635. }\
  1636. static void OPNAME ## qpel16_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  1637. uint8_t full[24*17];\
  1638. uint8_t halfH[272];\
  1639. uint8_t halfHV[256];\
  1640. copy_block17(full, src, 24, stride, 17);\
  1641. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1642. put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
  1643. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1644. OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1645. }\
  1646. void ff_ ## OPNAME ## qpel16_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1647. uint8_t full[24*17];\
  1648. uint8_t halfH[272];\
  1649. uint8_t halfV[256];\
  1650. uint8_t halfHV[256];\
  1651. copy_block17(full, src, 24, stride, 17);\
  1652. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full , 16, 24, 17);\
  1653. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1654. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1655. OPNAME ## pixels16_l4(dst, full+25, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1656. }\
  1657. static void OPNAME ## qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  1658. uint8_t full[24*17];\
  1659. uint8_t halfH[272];\
  1660. uint8_t halfHV[256];\
  1661. copy_block17(full, src, 24, stride, 17);\
  1662. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1663. put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
  1664. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1665. OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1666. }\
  1667. static void OPNAME ## qpel16_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  1668. uint8_t halfH[272];\
  1669. uint8_t halfHV[256];\
  1670. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1671. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1672. OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
  1673. }\
  1674. static void OPNAME ## qpel16_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  1675. uint8_t halfH[272];\
  1676. uint8_t halfHV[256];\
  1677. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1678. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1679. OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1680. }\
  1681. void ff_ ## OPNAME ## qpel16_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1682. uint8_t full[24*17];\
  1683. uint8_t halfH[272];\
  1684. uint8_t halfV[256];\
  1685. uint8_t halfHV[256];\
  1686. copy_block17(full, src, 24, stride, 17);\
  1687. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1688. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1689. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1690. OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
  1691. }\
  1692. static void OPNAME ## qpel16_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  1693. uint8_t full[24*17];\
  1694. uint8_t halfH[272];\
  1695. copy_block17(full, src, 24, stride, 17);\
  1696. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1697. put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
  1698. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1699. }\
  1700. void ff_ ## OPNAME ## qpel16_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1701. uint8_t full[24*17];\
  1702. uint8_t halfH[272];\
  1703. uint8_t halfV[256];\
  1704. uint8_t halfHV[256];\
  1705. copy_block17(full, src, 24, stride, 17);\
  1706. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1707. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1708. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1709. OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
  1710. }\
  1711. static void OPNAME ## qpel16_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  1712. uint8_t full[24*17];\
  1713. uint8_t halfH[272];\
  1714. copy_block17(full, src, 24, stride, 17);\
  1715. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1716. put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
  1717. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1718. }\
  1719. static void OPNAME ## qpel16_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  1720. uint8_t halfH[272];\
  1721. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1722. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1723. }
  1724. #define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
  1725. #define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1)
  1726. #define op_put(a, b) a = cm[((b) + 16)>>5]
  1727. #define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5]
  1728. QPEL_MC(0, put_ , _ , op_put)
  1729. QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd)
  1730. QPEL_MC(0, avg_ , _ , op_avg)
  1731. //QPEL_MC(1, avg_no_rnd , _ , op_avg)
  1732. #undef op_avg
  1733. #undef op_avg_no_rnd
  1734. #undef op_put
  1735. #undef op_put_no_rnd
  1736. #if 1
  1737. #define H264_LOWPASS(OPNAME, OP, OP2) \
  1738. static void OPNAME ## h264_qpel4_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1739. const int h=4;\
  1740. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1741. int i;\
  1742. for(i=0; i<h; i++)\
  1743. {\
  1744. OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
  1745. OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
  1746. OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]));\
  1747. OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]));\
  1748. dst+=dstStride;\
  1749. src+=srcStride;\
  1750. }\
  1751. }\
  1752. \
  1753. static void OPNAME ## h264_qpel4_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1754. const int w=4;\
  1755. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1756. int i;\
  1757. for(i=0; i<w; i++)\
  1758. {\
  1759. const int srcB= src[-2*srcStride];\
  1760. const int srcA= src[-1*srcStride];\
  1761. const int src0= src[0 *srcStride];\
  1762. const int src1= src[1 *srcStride];\
  1763. const int src2= src[2 *srcStride];\
  1764. const int src3= src[3 *srcStride];\
  1765. const int src4= src[4 *srcStride];\
  1766. const int src5= src[5 *srcStride];\
  1767. const int src6= src[6 *srcStride];\
  1768. OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
  1769. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
  1770. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
  1771. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
  1772. dst++;\
  1773. src++;\
  1774. }\
  1775. }\
  1776. \
  1777. static void OPNAME ## h264_qpel4_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  1778. const int h=4;\
  1779. const int w=4;\
  1780. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1781. int i;\
  1782. src -= 2*srcStride;\
  1783. for(i=0; i<h+5; i++)\
  1784. {\
  1785. tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
  1786. tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
  1787. tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]);\
  1788. tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]);\
  1789. tmp+=tmpStride;\
  1790. src+=srcStride;\
  1791. }\
  1792. tmp -= tmpStride*(h+5-2);\
  1793. for(i=0; i<w; i++)\
  1794. {\
  1795. const int tmpB= tmp[-2*tmpStride];\
  1796. const int tmpA= tmp[-1*tmpStride];\
  1797. const int tmp0= tmp[0 *tmpStride];\
  1798. const int tmp1= tmp[1 *tmpStride];\
  1799. const int tmp2= tmp[2 *tmpStride];\
  1800. const int tmp3= tmp[3 *tmpStride];\
  1801. const int tmp4= tmp[4 *tmpStride];\
  1802. const int tmp5= tmp[5 *tmpStride];\
  1803. const int tmp6= tmp[6 *tmpStride];\
  1804. OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
  1805. OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
  1806. OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
  1807. OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
  1808. dst++;\
  1809. tmp++;\
  1810. }\
  1811. }\
  1812. \
  1813. static void OPNAME ## h264_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1814. const int h=8;\
  1815. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1816. int i;\
  1817. for(i=0; i<h; i++)\
  1818. {\
  1819. OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]));\
  1820. OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]));\
  1821. OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]));\
  1822. OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]));\
  1823. OP(dst[4], (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]));\
  1824. OP(dst[5], (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]));\
  1825. OP(dst[6], (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]));\
  1826. OP(dst[7], (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]));\
  1827. dst+=dstStride;\
  1828. src+=srcStride;\
  1829. }\
  1830. }\
  1831. \
  1832. static void OPNAME ## h264_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1833. const int w=8;\
  1834. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1835. int i;\
  1836. for(i=0; i<w; i++)\
  1837. {\
  1838. const int srcB= src[-2*srcStride];\
  1839. const int srcA= src[-1*srcStride];\
  1840. const int src0= src[0 *srcStride];\
  1841. const int src1= src[1 *srcStride];\
  1842. const int src2= src[2 *srcStride];\
  1843. const int src3= src[3 *srcStride];\
  1844. const int src4= src[4 *srcStride];\
  1845. const int src5= src[5 *srcStride];\
  1846. const int src6= src[6 *srcStride];\
  1847. const int src7= src[7 *srcStride];\
  1848. const int src8= src[8 *srcStride];\
  1849. const int src9= src[9 *srcStride];\
  1850. const int src10=src[10*srcStride];\
  1851. OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
  1852. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
  1853. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
  1854. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
  1855. OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*5 + (src2+src7));\
  1856. OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*5 + (src3+src8));\
  1857. OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*5 + (src4+src9));\
  1858. OP(dst[7*dstStride], (src7+src8)*20 - (src6+src9)*5 + (src5+src10));\
  1859. dst++;\
  1860. src++;\
  1861. }\
  1862. }\
  1863. \
  1864. static void OPNAME ## h264_qpel8_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  1865. const int h=8;\
  1866. const int w=8;\
  1867. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1868. int i;\
  1869. src -= 2*srcStride;\
  1870. for(i=0; i<h+5; i++)\
  1871. {\
  1872. tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]);\
  1873. tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]);\
  1874. tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]);\
  1875. tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]);\
  1876. tmp[4]= (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]);\
  1877. tmp[5]= (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]);\
  1878. tmp[6]= (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]);\
  1879. tmp[7]= (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]);\
  1880. tmp+=tmpStride;\
  1881. src+=srcStride;\
  1882. }\
  1883. tmp -= tmpStride*(h+5-2);\
  1884. for(i=0; i<w; i++)\
  1885. {\
  1886. const int tmpB= tmp[-2*tmpStride];\
  1887. const int tmpA= tmp[-1*tmpStride];\
  1888. const int tmp0= tmp[0 *tmpStride];\
  1889. const int tmp1= tmp[1 *tmpStride];\
  1890. const int tmp2= tmp[2 *tmpStride];\
  1891. const int tmp3= tmp[3 *tmpStride];\
  1892. const int tmp4= tmp[4 *tmpStride];\
  1893. const int tmp5= tmp[5 *tmpStride];\
  1894. const int tmp6= tmp[6 *tmpStride];\
  1895. const int tmp7= tmp[7 *tmpStride];\
  1896. const int tmp8= tmp[8 *tmpStride];\
  1897. const int tmp9= tmp[9 *tmpStride];\
  1898. const int tmp10=tmp[10*tmpStride];\
  1899. OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
  1900. OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
  1901. OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
  1902. OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
  1903. OP2(dst[4*dstStride], (tmp4+tmp5)*20 - (tmp3+tmp6)*5 + (tmp2+tmp7));\
  1904. OP2(dst[5*dstStride], (tmp5+tmp6)*20 - (tmp4+tmp7)*5 + (tmp3+tmp8));\
  1905. OP2(dst[6*dstStride], (tmp6+tmp7)*20 - (tmp5+tmp8)*5 + (tmp4+tmp9));\
  1906. OP2(dst[7*dstStride], (tmp7+tmp8)*20 - (tmp6+tmp9)*5 + (tmp5+tmp10));\
  1907. dst++;\
  1908. tmp++;\
  1909. }\
  1910. }\
  1911. \
  1912. static void OPNAME ## h264_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1913. OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
  1914. OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
  1915. src += 8*srcStride;\
  1916. dst += 8*dstStride;\
  1917. OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
  1918. OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
  1919. }\
  1920. \
  1921. static void OPNAME ## h264_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1922. OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
  1923. OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
  1924. src += 8*srcStride;\
  1925. dst += 8*dstStride;\
  1926. OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
  1927. OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
  1928. }\
  1929. \
  1930. static void OPNAME ## h264_qpel16_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  1931. OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
  1932. OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
  1933. src += 8*srcStride;\
  1934. tmp += 8*tmpStride;\
  1935. dst += 8*dstStride;\
  1936. OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
  1937. OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
  1938. }\
  1939. #define H264_MC(OPNAME, SIZE) \
  1940. static void OPNAME ## h264_qpel ## SIZE ## _mc00_c (uint8_t *dst, uint8_t *src, int stride){\
  1941. OPNAME ## pixels ## SIZE ## _c(dst, src, stride, SIZE);\
  1942. }\
  1943. \
  1944. static void OPNAME ## h264_qpel ## SIZE ## _mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  1945. uint8_t half[SIZE*SIZE];\
  1946. put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
  1947. OPNAME ## pixels ## SIZE ## _l2(dst, src, half, stride, stride, SIZE, SIZE);\
  1948. }\
  1949. \
  1950. static void OPNAME ## h264_qpel ## SIZE ## _mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  1951. OPNAME ## h264_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride);\
  1952. }\
  1953. \
  1954. static void OPNAME ## h264_qpel ## SIZE ## _mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  1955. uint8_t half[SIZE*SIZE];\
  1956. put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
  1957. OPNAME ## pixels ## SIZE ## _l2(dst, src+1, half, stride, stride, SIZE, SIZE);\
  1958. }\
  1959. \
  1960. static void OPNAME ## h264_qpel ## SIZE ## _mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  1961. uint8_t full[SIZE*(SIZE+5)];\
  1962. uint8_t * const full_mid= full + SIZE*2;\
  1963. uint8_t half[SIZE*SIZE];\
  1964. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  1965. put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
  1966. OPNAME ## pixels ## SIZE ## _l2(dst, full_mid, half, stride, SIZE, SIZE, SIZE);\
  1967. }\
  1968. \
  1969. static void OPNAME ## h264_qpel ## SIZE ## _mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  1970. uint8_t full[SIZE*(SIZE+5)];\
  1971. uint8_t * const full_mid= full + SIZE*2;\
  1972. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  1973. OPNAME ## h264_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE);\
  1974. }\
  1975. \
  1976. static void OPNAME ## h264_qpel ## SIZE ## _mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  1977. uint8_t full[SIZE*(SIZE+5)];\
  1978. uint8_t * const full_mid= full + SIZE*2;\
  1979. uint8_t half[SIZE*SIZE];\
  1980. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  1981. put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
  1982. OPNAME ## pixels ## SIZE ## _l2(dst, full_mid+SIZE, half, stride, SIZE, SIZE, SIZE);\
  1983. }\
  1984. \
  1985. static void OPNAME ## h264_qpel ## SIZE ## _mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  1986. uint8_t full[SIZE*(SIZE+5)];\
  1987. uint8_t * const full_mid= full + SIZE*2;\
  1988. uint8_t halfH[SIZE*SIZE];\
  1989. uint8_t halfV[SIZE*SIZE];\
  1990. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
  1991. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  1992. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  1993. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  1994. }\
  1995. \
  1996. static void OPNAME ## h264_qpel ## SIZE ## _mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  1997. uint8_t full[SIZE*(SIZE+5)];\
  1998. uint8_t * const full_mid= full + SIZE*2;\
  1999. uint8_t halfH[SIZE*SIZE];\
  2000. uint8_t halfV[SIZE*SIZE];\
  2001. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
  2002. copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
  2003. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2004. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2005. }\
  2006. \
  2007. static void OPNAME ## h264_qpel ## SIZE ## _mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  2008. uint8_t full[SIZE*(SIZE+5)];\
  2009. uint8_t * const full_mid= full + SIZE*2;\
  2010. uint8_t halfH[SIZE*SIZE];\
  2011. uint8_t halfV[SIZE*SIZE];\
  2012. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
  2013. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2014. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2015. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2016. }\
  2017. \
  2018. static void OPNAME ## h264_qpel ## SIZE ## _mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  2019. uint8_t full[SIZE*(SIZE+5)];\
  2020. uint8_t * const full_mid= full + SIZE*2;\
  2021. uint8_t halfH[SIZE*SIZE];\
  2022. uint8_t halfV[SIZE*SIZE];\
  2023. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
  2024. copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
  2025. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2026. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2027. }\
  2028. \
  2029. static void OPNAME ## h264_qpel ## SIZE ## _mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  2030. int16_t tmp[SIZE*(SIZE+5)];\
  2031. OPNAME ## h264_qpel ## SIZE ## _hv_lowpass(dst, tmp, src, stride, SIZE, stride);\
  2032. }\
  2033. \
  2034. static void OPNAME ## h264_qpel ## SIZE ## _mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  2035. int16_t tmp[SIZE*(SIZE+5)];\
  2036. uint8_t halfH[SIZE*SIZE];\
  2037. uint8_t halfHV[SIZE*SIZE];\
  2038. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
  2039. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2040. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
  2041. }\
  2042. \
  2043. static void OPNAME ## h264_qpel ## SIZE ## _mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  2044. int16_t tmp[SIZE*(SIZE+5)];\
  2045. uint8_t halfH[SIZE*SIZE];\
  2046. uint8_t halfHV[SIZE*SIZE];\
  2047. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
  2048. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2049. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
  2050. }\
  2051. \
  2052. static void OPNAME ## h264_qpel ## SIZE ## _mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  2053. uint8_t full[SIZE*(SIZE+5)];\
  2054. uint8_t * const full_mid= full + SIZE*2;\
  2055. int16_t tmp[SIZE*(SIZE+5)];\
  2056. uint8_t halfV[SIZE*SIZE];\
  2057. uint8_t halfHV[SIZE*SIZE];\
  2058. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2059. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2060. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2061. OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
  2062. }\
  2063. \
  2064. static void OPNAME ## h264_qpel ## SIZE ## _mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  2065. uint8_t full[SIZE*(SIZE+5)];\
  2066. uint8_t * const full_mid= full + SIZE*2;\
  2067. int16_t tmp[SIZE*(SIZE+5)];\
  2068. uint8_t halfV[SIZE*SIZE];\
  2069. uint8_t halfHV[SIZE*SIZE];\
  2070. copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
  2071. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2072. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2073. OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
  2074. }\
  2075. #define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
  2076. //#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7)
  2077. #define op_put(a, b) a = cm[((b) + 16)>>5]
  2078. #define op2_avg(a, b) a = (((a)+cm[((b) + 512)>>10]+1)>>1)
  2079. #define op2_put(a, b) a = cm[((b) + 512)>>10]
  2080. H264_LOWPASS(put_ , op_put, op2_put)
  2081. H264_LOWPASS(avg_ , op_avg, op2_avg)
  2082. H264_MC(put_, 4)
  2083. H264_MC(put_, 8)
  2084. H264_MC(put_, 16)
  2085. H264_MC(avg_, 4)
  2086. H264_MC(avg_, 8)
  2087. H264_MC(avg_, 16)
  2088. #undef op_avg
  2089. #undef op_put
  2090. #undef op2_avg
  2091. #undef op2_put
  2092. #endif
  2093. static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){
  2094. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  2095. int i;
  2096. for(i=0; i<h; i++){
  2097. dst[0]= cm[(9*(src[0] + src[1]) - (src[-1] + src[2]) + 8)>>4];
  2098. dst[1]= cm[(9*(src[1] + src[2]) - (src[ 0] + src[3]) + 8)>>4];
  2099. dst[2]= cm[(9*(src[2] + src[3]) - (src[ 1] + src[4]) + 8)>>4];
  2100. dst[3]= cm[(9*(src[3] + src[4]) - (src[ 2] + src[5]) + 8)>>4];
  2101. dst[4]= cm[(9*(src[4] + src[5]) - (src[ 3] + src[6]) + 8)>>4];
  2102. dst[5]= cm[(9*(src[5] + src[6]) - (src[ 4] + src[7]) + 8)>>4];
  2103. dst[6]= cm[(9*(src[6] + src[7]) - (src[ 5] + src[8]) + 8)>>4];
  2104. dst[7]= cm[(9*(src[7] + src[8]) - (src[ 6] + src[9]) + 8)>>4];
  2105. dst+=dstStride;
  2106. src+=srcStride;
  2107. }
  2108. }
  2109. static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){
  2110. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  2111. int i;
  2112. for(i=0; i<w; i++){
  2113. const int src_1= src[ -srcStride];
  2114. const int src0 = src[0 ];
  2115. const int src1 = src[ srcStride];
  2116. const int src2 = src[2*srcStride];
  2117. const int src3 = src[3*srcStride];
  2118. const int src4 = src[4*srcStride];
  2119. const int src5 = src[5*srcStride];
  2120. const int src6 = src[6*srcStride];
  2121. const int src7 = src[7*srcStride];
  2122. const int src8 = src[8*srcStride];
  2123. const int src9 = src[9*srcStride];
  2124. dst[0*dstStride]= cm[(9*(src0 + src1) - (src_1 + src2) + 8)>>4];
  2125. dst[1*dstStride]= cm[(9*(src1 + src2) - (src0 + src3) + 8)>>4];
  2126. dst[2*dstStride]= cm[(9*(src2 + src3) - (src1 + src4) + 8)>>4];
  2127. dst[3*dstStride]= cm[(9*(src3 + src4) - (src2 + src5) + 8)>>4];
  2128. dst[4*dstStride]= cm[(9*(src4 + src5) - (src3 + src6) + 8)>>4];
  2129. dst[5*dstStride]= cm[(9*(src5 + src6) - (src4 + src7) + 8)>>4];
  2130. dst[6*dstStride]= cm[(9*(src6 + src7) - (src5 + src8) + 8)>>4];
  2131. dst[7*dstStride]= cm[(9*(src7 + src8) - (src6 + src9) + 8)>>4];
  2132. src++;
  2133. dst++;
  2134. }
  2135. }
  2136. static void put_mspel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){
  2137. put_pixels8_c(dst, src, stride, 8);
  2138. }
  2139. static void put_mspel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){
  2140. uint8_t half[64];
  2141. wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
  2142. put_pixels8_l2(dst, src, half, stride, stride, 8, 8);
  2143. }
  2144. static void put_mspel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){
  2145. wmv2_mspel8_h_lowpass(dst, src, stride, stride, 8);
  2146. }
  2147. static void put_mspel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){
  2148. uint8_t half[64];
  2149. wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
  2150. put_pixels8_l2(dst, src+1, half, stride, stride, 8, 8);
  2151. }
  2152. static void put_mspel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){
  2153. wmv2_mspel8_v_lowpass(dst, src, stride, stride, 8);
  2154. }
  2155. static void put_mspel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){
  2156. uint8_t halfH[88];
  2157. uint8_t halfV[64];
  2158. uint8_t halfHV[64];
  2159. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  2160. wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8);
  2161. wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
  2162. put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
  2163. }
  2164. static void put_mspel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){
  2165. uint8_t halfH[88];
  2166. uint8_t halfV[64];
  2167. uint8_t halfHV[64];
  2168. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  2169. wmv2_mspel8_v_lowpass(halfV, src+1, 8, stride, 8);
  2170. wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
  2171. put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
  2172. }
  2173. static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){
  2174. uint8_t halfH[88];
  2175. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  2176. wmv2_mspel8_v_lowpass(dst, halfH+8, stride, 8, 8);
  2177. }
  2178. static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale){
  2179. int x;
  2180. const int strength= ff_h263_loop_filter_strength[qscale];
  2181. for(x=0; x<8; x++){
  2182. int d1, d2, ad1;
  2183. int p0= src[x-2*stride];
  2184. int p1= src[x-1*stride];
  2185. int p2= src[x+0*stride];
  2186. int p3= src[x+1*stride];
  2187. int d = (p0 - p3 + 4*(p2 - p1)) / 8;
  2188. if (d<-2*strength) d1= 0;
  2189. else if(d<- strength) d1=-2*strength - d;
  2190. else if(d< strength) d1= d;
  2191. else if(d< 2*strength) d1= 2*strength - d;
  2192. else d1= 0;
  2193. p1 += d1;
  2194. p2 -= d1;
  2195. if(p1&256) p1= ~(p1>>31);
  2196. if(p2&256) p2= ~(p2>>31);
  2197. src[x-1*stride] = p1;
  2198. src[x+0*stride] = p2;
  2199. ad1= ABS(d1)>>1;
  2200. d2= clip((p0-p3)/4, -ad1, ad1);
  2201. src[x-2*stride] = p0 - d2;
  2202. src[x+ stride] = p3 + d2;
  2203. }
  2204. }
  2205. static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale){
  2206. int y;
  2207. const int strength= ff_h263_loop_filter_strength[qscale];
  2208. for(y=0; y<8; y++){
  2209. int d1, d2, ad1;
  2210. int p0= src[y*stride-2];
  2211. int p1= src[y*stride-1];
  2212. int p2= src[y*stride+0];
  2213. int p3= src[y*stride+1];
  2214. int d = (p0 - p3 + 4*(p2 - p1)) / 8;
  2215. if (d<-2*strength) d1= 0;
  2216. else if(d<- strength) d1=-2*strength - d;
  2217. else if(d< strength) d1= d;
  2218. else if(d< 2*strength) d1= 2*strength - d;
  2219. else d1= 0;
  2220. p1 += d1;
  2221. p2 -= d1;
  2222. if(p1&256) p1= ~(p1>>31);
  2223. if(p2&256) p2= ~(p2>>31);
  2224. src[y*stride-1] = p1;
  2225. src[y*stride+0] = p2;
  2226. ad1= ABS(d1)>>1;
  2227. d2= clip((p0-p3)/4, -ad1, ad1);
  2228. src[y*stride-2] = p0 - d2;
  2229. src[y*stride+1] = p3 + d2;
  2230. }
  2231. }
  2232. static inline int pix_abs16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2233. {
  2234. int s, i;
  2235. s = 0;
  2236. for(i=0;i<h;i++) {
  2237. s += abs(pix1[0] - pix2[0]);
  2238. s += abs(pix1[1] - pix2[1]);
  2239. s += abs(pix1[2] - pix2[2]);
  2240. s += abs(pix1[3] - pix2[3]);
  2241. s += abs(pix1[4] - pix2[4]);
  2242. s += abs(pix1[5] - pix2[5]);
  2243. s += abs(pix1[6] - pix2[6]);
  2244. s += abs(pix1[7] - pix2[7]);
  2245. s += abs(pix1[8] - pix2[8]);
  2246. s += abs(pix1[9] - pix2[9]);
  2247. s += abs(pix1[10] - pix2[10]);
  2248. s += abs(pix1[11] - pix2[11]);
  2249. s += abs(pix1[12] - pix2[12]);
  2250. s += abs(pix1[13] - pix2[13]);
  2251. s += abs(pix1[14] - pix2[14]);
  2252. s += abs(pix1[15] - pix2[15]);
  2253. pix1 += line_size;
  2254. pix2 += line_size;
  2255. }
  2256. return s;
  2257. }
  2258. static int pix_abs16_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2259. {
  2260. int s, i;
  2261. s = 0;
  2262. for(i=0;i<h;i++) {
  2263. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  2264. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  2265. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  2266. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  2267. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  2268. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  2269. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  2270. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  2271. s += abs(pix1[8] - avg2(pix2[8], pix2[9]));
  2272. s += abs(pix1[9] - avg2(pix2[9], pix2[10]));
  2273. s += abs(pix1[10] - avg2(pix2[10], pix2[11]));
  2274. s += abs(pix1[11] - avg2(pix2[11], pix2[12]));
  2275. s += abs(pix1[12] - avg2(pix2[12], pix2[13]));
  2276. s += abs(pix1[13] - avg2(pix2[13], pix2[14]));
  2277. s += abs(pix1[14] - avg2(pix2[14], pix2[15]));
  2278. s += abs(pix1[15] - avg2(pix2[15], pix2[16]));
  2279. pix1 += line_size;
  2280. pix2 += line_size;
  2281. }
  2282. return s;
  2283. }
  2284. static int pix_abs16_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2285. {
  2286. int s, i;
  2287. uint8_t *pix3 = pix2 + line_size;
  2288. s = 0;
  2289. for(i=0;i<h;i++) {
  2290. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  2291. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  2292. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  2293. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  2294. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  2295. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  2296. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  2297. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  2298. s += abs(pix1[8] - avg2(pix2[8], pix3[8]));
  2299. s += abs(pix1[9] - avg2(pix2[9], pix3[9]));
  2300. s += abs(pix1[10] - avg2(pix2[10], pix3[10]));
  2301. s += abs(pix1[11] - avg2(pix2[11], pix3[11]));
  2302. s += abs(pix1[12] - avg2(pix2[12], pix3[12]));
  2303. s += abs(pix1[13] - avg2(pix2[13], pix3[13]));
  2304. s += abs(pix1[14] - avg2(pix2[14], pix3[14]));
  2305. s += abs(pix1[15] - avg2(pix2[15], pix3[15]));
  2306. pix1 += line_size;
  2307. pix2 += line_size;
  2308. pix3 += line_size;
  2309. }
  2310. return s;
  2311. }
  2312. static int pix_abs16_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2313. {
  2314. int s, i;
  2315. uint8_t *pix3 = pix2 + line_size;
  2316. s = 0;
  2317. for(i=0;i<h;i++) {
  2318. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  2319. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  2320. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  2321. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  2322. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  2323. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  2324. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  2325. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  2326. s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9]));
  2327. s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10]));
  2328. s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11]));
  2329. s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12]));
  2330. s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13]));
  2331. s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14]));
  2332. s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15]));
  2333. s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16]));
  2334. pix1 += line_size;
  2335. pix2 += line_size;
  2336. pix3 += line_size;
  2337. }
  2338. return s;
  2339. }
  2340. static inline int pix_abs8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2341. {
  2342. int s, i;
  2343. s = 0;
  2344. for(i=0;i<h;i++) {
  2345. s += abs(pix1[0] - pix2[0]);
  2346. s += abs(pix1[1] - pix2[1]);
  2347. s += abs(pix1[2] - pix2[2]);
  2348. s += abs(pix1[3] - pix2[3]);
  2349. s += abs(pix1[4] - pix2[4]);
  2350. s += abs(pix1[5] - pix2[5]);
  2351. s += abs(pix1[6] - pix2[6]);
  2352. s += abs(pix1[7] - pix2[7]);
  2353. pix1 += line_size;
  2354. pix2 += line_size;
  2355. }
  2356. return s;
  2357. }
  2358. static int pix_abs8_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2359. {
  2360. int s, i;
  2361. s = 0;
  2362. for(i=0;i<h;i++) {
  2363. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  2364. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  2365. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  2366. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  2367. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  2368. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  2369. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  2370. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  2371. pix1 += line_size;
  2372. pix2 += line_size;
  2373. }
  2374. return s;
  2375. }
  2376. static int pix_abs8_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2377. {
  2378. int s, i;
  2379. uint8_t *pix3 = pix2 + line_size;
  2380. s = 0;
  2381. for(i=0;i<h;i++) {
  2382. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  2383. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  2384. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  2385. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  2386. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  2387. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  2388. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  2389. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  2390. pix1 += line_size;
  2391. pix2 += line_size;
  2392. pix3 += line_size;
  2393. }
  2394. return s;
  2395. }
  2396. static int pix_abs8_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2397. {
  2398. int s, i;
  2399. uint8_t *pix3 = pix2 + line_size;
  2400. s = 0;
  2401. for(i=0;i<h;i++) {
  2402. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  2403. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  2404. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  2405. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  2406. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  2407. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  2408. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  2409. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  2410. pix1 += line_size;
  2411. pix2 += line_size;
  2412. pix3 += line_size;
  2413. }
  2414. return s;
  2415. }
  2416. static int try_8x8basis_c(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){
  2417. int i;
  2418. unsigned int sum=0;
  2419. for(i=0; i<8*8; i++){
  2420. int b= rem[i] + ((basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT));
  2421. int w= weight[i];
  2422. b>>= RECON_SHIFT;
  2423. assert(-512<b && b<512);
  2424. sum += (w*b)*(w*b)>>4;
  2425. }
  2426. return sum>>2;
  2427. }
  2428. static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale){
  2429. int i;
  2430. for(i=0; i<8*8; i++){
  2431. rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT);
  2432. }
  2433. }
  2434. /**
  2435. * permutes an 8x8 block.
  2436. * @param block the block which will be permuted according to the given permutation vector
  2437. * @param permutation the permutation vector
  2438. * @param last the last non zero coefficient in scantable order, used to speed the permutation up
  2439. * @param scantable the used scantable, this is only used to speed the permutation up, the block is not
  2440. * (inverse) permutated to scantable order!
  2441. */
  2442. void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last)
  2443. {
  2444. int i;
  2445. DCTELEM temp[64];
  2446. if(last<=0) return;
  2447. //if(permutation[1]==1) return; //FIXME its ok but not clean and might fail for some perms
  2448. for(i=0; i<=last; i++){
  2449. const int j= scantable[i];
  2450. temp[j]= block[j];
  2451. block[j]=0;
  2452. }
  2453. for(i=0; i<=last; i++){
  2454. const int j= scantable[i];
  2455. const int perm_j= permutation[j];
  2456. block[perm_j]= temp[j];
  2457. }
  2458. }
  2459. static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){
  2460. return 0;
  2461. }
  2462. void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){
  2463. int i;
  2464. memset(cmp, 0, sizeof(void*)*5);
  2465. for(i=0; i<5; i++){
  2466. switch(type&0xFF){
  2467. case FF_CMP_SAD:
  2468. cmp[i]= c->sad[i];
  2469. break;
  2470. case FF_CMP_SATD:
  2471. cmp[i]= c->hadamard8_diff[i];
  2472. break;
  2473. case FF_CMP_SSE:
  2474. cmp[i]= c->sse[i];
  2475. break;
  2476. case FF_CMP_DCT:
  2477. cmp[i]= c->dct_sad[i];
  2478. break;
  2479. case FF_CMP_PSNR:
  2480. cmp[i]= c->quant_psnr[i];
  2481. break;
  2482. case FF_CMP_BIT:
  2483. cmp[i]= c->bit[i];
  2484. break;
  2485. case FF_CMP_RD:
  2486. cmp[i]= c->rd[i];
  2487. break;
  2488. case FF_CMP_VSAD:
  2489. cmp[i]= c->vsad[i];
  2490. break;
  2491. case FF_CMP_VSSE:
  2492. cmp[i]= c->vsse[i];
  2493. break;
  2494. case FF_CMP_ZERO:
  2495. cmp[i]= zero_cmp;
  2496. break;
  2497. default:
  2498. av_log(NULL, AV_LOG_ERROR,"internal error in cmp function selection\n");
  2499. }
  2500. }
  2501. }
  2502. /**
  2503. * memset(blocks, 0, sizeof(DCTELEM)*6*64)
  2504. */
  2505. static void clear_blocks_c(DCTELEM *blocks)
  2506. {
  2507. memset(blocks, 0, sizeof(DCTELEM)*6*64);
  2508. }
  2509. static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){
  2510. int i;
  2511. for(i=0; i+7<w; i+=8){
  2512. dst[i+0] += src[i+0];
  2513. dst[i+1] += src[i+1];
  2514. dst[i+2] += src[i+2];
  2515. dst[i+3] += src[i+3];
  2516. dst[i+4] += src[i+4];
  2517. dst[i+5] += src[i+5];
  2518. dst[i+6] += src[i+6];
  2519. dst[i+7] += src[i+7];
  2520. }
  2521. for(; i<w; i++)
  2522. dst[i+0] += src[i+0];
  2523. }
  2524. static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
  2525. int i;
  2526. for(i=0; i+7<w; i+=8){
  2527. dst[i+0] = src1[i+0]-src2[i+0];
  2528. dst[i+1] = src1[i+1]-src2[i+1];
  2529. dst[i+2] = src1[i+2]-src2[i+2];
  2530. dst[i+3] = src1[i+3]-src2[i+3];
  2531. dst[i+4] = src1[i+4]-src2[i+4];
  2532. dst[i+5] = src1[i+5]-src2[i+5];
  2533. dst[i+6] = src1[i+6]-src2[i+6];
  2534. dst[i+7] = src1[i+7]-src2[i+7];
  2535. }
  2536. for(; i<w; i++)
  2537. dst[i+0] = src1[i+0]-src2[i+0];
  2538. }
  2539. static void sub_hfyu_median_prediction_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top){
  2540. int i;
  2541. uint8_t l, lt;
  2542. l= *left;
  2543. lt= *left_top;
  2544. for(i=0; i<w; i++){
  2545. const int pred= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF);
  2546. lt= src1[i];
  2547. l= src2[i];
  2548. dst[i]= l - pred;
  2549. }
  2550. *left= l;
  2551. *left_top= lt;
  2552. }
  2553. #define BUTTERFLY2(o1,o2,i1,i2) \
  2554. o1= (i1)+(i2);\
  2555. o2= (i1)-(i2);
  2556. #define BUTTERFLY1(x,y) \
  2557. {\
  2558. int a,b;\
  2559. a= x;\
  2560. b= y;\
  2561. x= a+b;\
  2562. y= a-b;\
  2563. }
  2564. #define BUTTERFLYA(x,y) (ABS((x)+(y)) + ABS((x)-(y)))
  2565. static int hadamard8_diff8x8_c(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){
  2566. int i;
  2567. int temp[64];
  2568. int sum=0;
  2569. assert(h==8);
  2570. for(i=0; i<8; i++){
  2571. //FIXME try pointer walks
  2572. 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]);
  2573. 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]);
  2574. 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]);
  2575. 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]);
  2576. BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
  2577. BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
  2578. BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
  2579. BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
  2580. BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
  2581. BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
  2582. BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
  2583. BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
  2584. }
  2585. for(i=0; i<8; i++){
  2586. BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
  2587. BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
  2588. BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
  2589. BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
  2590. BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
  2591. BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
  2592. BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
  2593. BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
  2594. sum +=
  2595. BUTTERFLYA(temp[8*0+i], temp[8*4+i])
  2596. +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
  2597. +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
  2598. +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
  2599. }
  2600. #if 0
  2601. static int maxi=0;
  2602. if(sum>maxi){
  2603. maxi=sum;
  2604. printf("MAX:%d\n", maxi);
  2605. }
  2606. #endif
  2607. return sum;
  2608. }
  2609. static int hadamard8_intra8x8_c(/*MpegEncContext*/ void *s, uint8_t *src, uint8_t *dummy, int stride, int h){
  2610. int i;
  2611. int temp[64];
  2612. int sum=0;
  2613. assert(h==8);
  2614. for(i=0; i<8; i++){
  2615. //FIXME try pointer walks
  2616. BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0],src[stride*i+1]);
  2617. BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2],src[stride*i+3]);
  2618. BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4],src[stride*i+5]);
  2619. BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6],src[stride*i+7]);
  2620. BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
  2621. BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
  2622. BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
  2623. BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
  2624. BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
  2625. BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
  2626. BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
  2627. BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
  2628. }
  2629. for(i=0; i<8; i++){
  2630. BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
  2631. BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
  2632. BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
  2633. BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
  2634. BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
  2635. BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
  2636. BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
  2637. BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
  2638. sum +=
  2639. BUTTERFLYA(temp[8*0+i], temp[8*4+i])
  2640. +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
  2641. +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
  2642. +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
  2643. }
  2644. sum -= ABS(temp[8*0] + temp[8*4]); // -mean
  2645. return sum;
  2646. }
  2647. static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  2648. MpegEncContext * const s= (MpegEncContext *)c;
  2649. uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64/8];
  2650. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  2651. int sum=0, i;
  2652. assert(h==8);
  2653. s->dsp.diff_pixels(temp, src1, src2, stride);
  2654. s->dsp.fdct(temp);
  2655. for(i=0; i<64; i++)
  2656. sum+= ABS(temp[i]);
  2657. return sum;
  2658. }
  2659. void simple_idct(DCTELEM *block); //FIXME
  2660. static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  2661. MpegEncContext * const s= (MpegEncContext *)c;
  2662. uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64*2/8];
  2663. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  2664. DCTELEM * const bak = ((DCTELEM*)aligned_temp)+64;
  2665. int sum=0, i;
  2666. assert(h==8);
  2667. s->mb_intra=0;
  2668. s->dsp.diff_pixels(temp, src1, src2, stride);
  2669. memcpy(bak, temp, 64*sizeof(DCTELEM));
  2670. s->block_last_index[0/*FIXME*/]= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  2671. s->dct_unquantize_inter(s, temp, 0, s->qscale);
  2672. simple_idct(temp); //FIXME
  2673. for(i=0; i<64; i++)
  2674. sum+= (temp[i]-bak[i])*(temp[i]-bak[i]);
  2675. return sum;
  2676. }
  2677. static int rd8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  2678. MpegEncContext * const s= (MpegEncContext *)c;
  2679. const uint8_t *scantable= s->intra_scantable.permutated;
  2680. uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64/8];
  2681. uint64_t __align8 aligned_bak[stride];
  2682. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  2683. uint8_t * const bak= (uint8_t*)aligned_bak;
  2684. int i, last, run, bits, level, distoration, start_i;
  2685. const int esc_length= s->ac_esc_length;
  2686. uint8_t * length;
  2687. uint8_t * last_length;
  2688. assert(h==8);
  2689. for(i=0; i<8; i++){
  2690. ((uint32_t*)(bak + i*stride))[0]= ((uint32_t*)(src2 + i*stride))[0];
  2691. ((uint32_t*)(bak + i*stride))[1]= ((uint32_t*)(src2 + i*stride))[1];
  2692. }
  2693. s->dsp.diff_pixels(temp, src1, src2, stride);
  2694. s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  2695. bits=0;
  2696. if (s->mb_intra) {
  2697. start_i = 1;
  2698. length = s->intra_ac_vlc_length;
  2699. last_length= s->intra_ac_vlc_last_length;
  2700. bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
  2701. } else {
  2702. start_i = 0;
  2703. length = s->inter_ac_vlc_length;
  2704. last_length= s->inter_ac_vlc_last_length;
  2705. }
  2706. if(last>=start_i){
  2707. run=0;
  2708. for(i=start_i; i<last; i++){
  2709. int j= scantable[i];
  2710. level= temp[j];
  2711. if(level){
  2712. level+=64;
  2713. if((level&(~127)) == 0){
  2714. bits+= length[UNI_AC_ENC_INDEX(run, level)];
  2715. }else
  2716. bits+= esc_length;
  2717. run=0;
  2718. }else
  2719. run++;
  2720. }
  2721. i= scantable[last];
  2722. level= temp[i] + 64;
  2723. assert(level - 64);
  2724. if((level&(~127)) == 0){
  2725. bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
  2726. }else
  2727. bits+= esc_length;
  2728. }
  2729. if(last>=0){
  2730. if(s->mb_intra)
  2731. s->dct_unquantize_intra(s, temp, 0, s->qscale);
  2732. else
  2733. s->dct_unquantize_inter(s, temp, 0, s->qscale);
  2734. }
  2735. s->dsp.idct_add(bak, stride, temp);
  2736. distoration= s->dsp.sse[1](NULL, bak, src1, stride, 8);
  2737. return distoration + ((bits*s->qscale*s->qscale*109 + 64)>>7);
  2738. }
  2739. static int bit8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  2740. MpegEncContext * const s= (MpegEncContext *)c;
  2741. const uint8_t *scantable= s->intra_scantable.permutated;
  2742. uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64/8];
  2743. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  2744. int i, last, run, bits, level, start_i;
  2745. const int esc_length= s->ac_esc_length;
  2746. uint8_t * length;
  2747. uint8_t * last_length;
  2748. assert(h==8);
  2749. s->dsp.diff_pixels(temp, src1, src2, stride);
  2750. s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  2751. bits=0;
  2752. if (s->mb_intra) {
  2753. start_i = 1;
  2754. length = s->intra_ac_vlc_length;
  2755. last_length= s->intra_ac_vlc_last_length;
  2756. bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
  2757. } else {
  2758. start_i = 0;
  2759. length = s->inter_ac_vlc_length;
  2760. last_length= s->inter_ac_vlc_last_length;
  2761. }
  2762. if(last>=start_i){
  2763. run=0;
  2764. for(i=start_i; i<last; i++){
  2765. int j= scantable[i];
  2766. level= temp[j];
  2767. if(level){
  2768. level+=64;
  2769. if((level&(~127)) == 0){
  2770. bits+= length[UNI_AC_ENC_INDEX(run, level)];
  2771. }else
  2772. bits+= esc_length;
  2773. run=0;
  2774. }else
  2775. run++;
  2776. }
  2777. i= scantable[last];
  2778. level= temp[i] + 64;
  2779. assert(level - 64);
  2780. if((level&(~127)) == 0){
  2781. bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
  2782. }else
  2783. bits+= esc_length;
  2784. }
  2785. return bits;
  2786. }
  2787. static int vsad_intra16_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){
  2788. int score=0;
  2789. int x,y;
  2790. for(y=1; y<h; y++){
  2791. for(x=0; x<16; x+=4){
  2792. score+= ABS(s[x ] - s[x +stride]) + ABS(s[x+1] - s[x+1+stride])
  2793. +ABS(s[x+2] - s[x+2+stride]) + ABS(s[x+3] - s[x+3+stride]);
  2794. }
  2795. s+= stride;
  2796. }
  2797. return score;
  2798. }
  2799. static int vsad16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
  2800. int score=0;
  2801. int x,y;
  2802. for(y=1; y<h; y++){
  2803. for(x=0; x<16; x++){
  2804. score+= ABS(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
  2805. }
  2806. s1+= stride;
  2807. s2+= stride;
  2808. }
  2809. return score;
  2810. }
  2811. #define SQ(a) ((a)*(a))
  2812. static int vsse_intra16_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){
  2813. int score=0;
  2814. int x,y;
  2815. for(y=1; y<h; y++){
  2816. for(x=0; x<16; x+=4){
  2817. score+= SQ(s[x ] - s[x +stride]) + SQ(s[x+1] - s[x+1+stride])
  2818. +SQ(s[x+2] - s[x+2+stride]) + SQ(s[x+3] - s[x+3+stride]);
  2819. }
  2820. s+= stride;
  2821. }
  2822. return score;
  2823. }
  2824. static int vsse16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
  2825. int score=0;
  2826. int x,y;
  2827. for(y=1; y<h; y++){
  2828. for(x=0; x<16; x++){
  2829. score+= SQ(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
  2830. }
  2831. s1+= stride;
  2832. s2+= stride;
  2833. }
  2834. return score;
  2835. }
  2836. WARPER8_16_SQ(hadamard8_diff8x8_c, hadamard8_diff16_c)
  2837. WARPER8_16_SQ(hadamard8_intra8x8_c, hadamard8_intra16_c)
  2838. WARPER8_16_SQ(dct_sad8x8_c, dct_sad16_c)
  2839. WARPER8_16_SQ(quant_psnr8x8_c, quant_psnr16_c)
  2840. WARPER8_16_SQ(rd8x8_c, rd16_c)
  2841. WARPER8_16_SQ(bit8x8_c, bit16_c)
  2842. /* XXX: those functions should be suppressed ASAP when all IDCTs are
  2843. converted */
  2844. static void ff_jref_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
  2845. {
  2846. j_rev_dct (block);
  2847. put_pixels_clamped_c(block, dest, line_size);
  2848. }
  2849. static void ff_jref_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
  2850. {
  2851. j_rev_dct (block);
  2852. add_pixels_clamped_c(block, dest, line_size);
  2853. }
  2854. /* init static data */
  2855. void dsputil_static_init(void)
  2856. {
  2857. int i;
  2858. for(i=0;i<256;i++) cropTbl[i + MAX_NEG_CROP] = i;
  2859. for(i=0;i<MAX_NEG_CROP;i++) {
  2860. cropTbl[i] = 0;
  2861. cropTbl[i + MAX_NEG_CROP + 256] = 255;
  2862. }
  2863. for(i=0;i<512;i++) {
  2864. squareTbl[i] = (i - 256) * (i - 256);
  2865. }
  2866. for(i=0; i<64; i++) inv_zigzag_direct16[ff_zigzag_direct[i]]= i+1;
  2867. }
  2868. void dsputil_init(DSPContext* c, AVCodecContext *avctx)
  2869. {
  2870. int i;
  2871. #ifdef CONFIG_ENCODERS
  2872. if(avctx->dct_algo==FF_DCT_FASTINT) {
  2873. c->fdct = fdct_ifast;
  2874. c->fdct248 = fdct_ifast248;
  2875. }
  2876. else if(avctx->dct_algo==FF_DCT_FAAN) {
  2877. c->fdct = ff_faandct;
  2878. c->fdct248 = ff_faandct248;
  2879. }
  2880. else {
  2881. c->fdct = ff_jpeg_fdct_islow; //slow/accurate/default
  2882. c->fdct248 = ff_fdct248_islow;
  2883. }
  2884. #endif //CONFIG_ENCODERS
  2885. if(avctx->idct_algo==FF_IDCT_INT){
  2886. c->idct_put= ff_jref_idct_put;
  2887. c->idct_add= ff_jref_idct_add;
  2888. c->idct = j_rev_dct;
  2889. c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
  2890. }else{ //accurate/default
  2891. c->idct_put= simple_idct_put;
  2892. c->idct_add= simple_idct_add;
  2893. c->idct = simple_idct;
  2894. c->idct_permutation_type= FF_NO_IDCT_PERM;
  2895. }
  2896. /* VP3 DSP support */
  2897. c->vp3_dsp_init = vp3_dsp_init_c;
  2898. c->vp3_idct_put = vp3_idct_put_c;
  2899. c->vp3_idct_add = vp3_idct_add_c;
  2900. c->get_pixels = get_pixels_c;
  2901. c->diff_pixels = diff_pixels_c;
  2902. c->put_pixels_clamped = put_pixels_clamped_c;
  2903. c->add_pixels_clamped = add_pixels_clamped_c;
  2904. c->gmc1 = gmc1_c;
  2905. c->gmc = gmc_c;
  2906. c->clear_blocks = clear_blocks_c;
  2907. c->pix_sum = pix_sum_c;
  2908. c->pix_norm1 = pix_norm1_c;
  2909. /* TODO [0] 16 [1] 8 */
  2910. c->pix_abs[0][0] = pix_abs16_c;
  2911. c->pix_abs[0][1] = pix_abs16_x2_c;
  2912. c->pix_abs[0][2] = pix_abs16_y2_c;
  2913. c->pix_abs[0][3] = pix_abs16_xy2_c;
  2914. c->pix_abs[1][0] = pix_abs8_c;
  2915. c->pix_abs[1][1] = pix_abs8_x2_c;
  2916. c->pix_abs[1][2] = pix_abs8_y2_c;
  2917. c->pix_abs[1][3] = pix_abs8_xy2_c;
  2918. #define dspfunc(PFX, IDX, NUM) \
  2919. c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## NUM ## _c; \
  2920. c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## NUM ## _x2_c; \
  2921. c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## NUM ## _y2_c; \
  2922. c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## NUM ## _xy2_c
  2923. dspfunc(put, 0, 16);
  2924. dspfunc(put_no_rnd, 0, 16);
  2925. dspfunc(put, 1, 8);
  2926. dspfunc(put_no_rnd, 1, 8);
  2927. dspfunc(put, 2, 4);
  2928. dspfunc(put, 3, 2);
  2929. dspfunc(avg, 0, 16);
  2930. dspfunc(avg_no_rnd, 0, 16);
  2931. dspfunc(avg, 1, 8);
  2932. dspfunc(avg_no_rnd, 1, 8);
  2933. dspfunc(avg, 2, 4);
  2934. dspfunc(avg, 3, 2);
  2935. #undef dspfunc
  2936. c->put_no_rnd_pixels_l2[0]= put_no_rnd_pixels16_l2_c;
  2937. c->put_no_rnd_pixels_l2[1]= put_no_rnd_pixels8_l2_c;
  2938. c->put_tpel_pixels_tab[ 0] = put_tpel_pixels_mc00_c;
  2939. c->put_tpel_pixels_tab[ 1] = put_tpel_pixels_mc10_c;
  2940. c->put_tpel_pixels_tab[ 2] = put_tpel_pixels_mc20_c;
  2941. c->put_tpel_pixels_tab[ 4] = put_tpel_pixels_mc01_c;
  2942. c->put_tpel_pixels_tab[ 5] = put_tpel_pixels_mc11_c;
  2943. c->put_tpel_pixels_tab[ 6] = put_tpel_pixels_mc21_c;
  2944. c->put_tpel_pixels_tab[ 8] = put_tpel_pixels_mc02_c;
  2945. c->put_tpel_pixels_tab[ 9] = put_tpel_pixels_mc12_c;
  2946. c->put_tpel_pixels_tab[10] = put_tpel_pixels_mc22_c;
  2947. c->avg_tpel_pixels_tab[ 0] = avg_tpel_pixels_mc00_c;
  2948. c->avg_tpel_pixels_tab[ 1] = avg_tpel_pixels_mc10_c;
  2949. c->avg_tpel_pixels_tab[ 2] = avg_tpel_pixels_mc20_c;
  2950. c->avg_tpel_pixels_tab[ 4] = avg_tpel_pixels_mc01_c;
  2951. c->avg_tpel_pixels_tab[ 5] = avg_tpel_pixels_mc11_c;
  2952. c->avg_tpel_pixels_tab[ 6] = avg_tpel_pixels_mc21_c;
  2953. c->avg_tpel_pixels_tab[ 8] = avg_tpel_pixels_mc02_c;
  2954. c->avg_tpel_pixels_tab[ 9] = avg_tpel_pixels_mc12_c;
  2955. c->avg_tpel_pixels_tab[10] = avg_tpel_pixels_mc22_c;
  2956. #define dspfunc(PFX, IDX, NUM) \
  2957. c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \
  2958. c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \
  2959. c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \
  2960. c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \
  2961. c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \
  2962. c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \
  2963. c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \
  2964. c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \
  2965. c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \
  2966. c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \
  2967. c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \
  2968. c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \
  2969. c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \
  2970. c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \
  2971. c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \
  2972. c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
  2973. dspfunc(put_qpel, 0, 16);
  2974. dspfunc(put_no_rnd_qpel, 0, 16);
  2975. dspfunc(avg_qpel, 0, 16);
  2976. /* dspfunc(avg_no_rnd_qpel, 0, 16); */
  2977. dspfunc(put_qpel, 1, 8);
  2978. dspfunc(put_no_rnd_qpel, 1, 8);
  2979. dspfunc(avg_qpel, 1, 8);
  2980. /* dspfunc(avg_no_rnd_qpel, 1, 8); */
  2981. dspfunc(put_h264_qpel, 0, 16);
  2982. dspfunc(put_h264_qpel, 1, 8);
  2983. dspfunc(put_h264_qpel, 2, 4);
  2984. dspfunc(avg_h264_qpel, 0, 16);
  2985. dspfunc(avg_h264_qpel, 1, 8);
  2986. dspfunc(avg_h264_qpel, 2, 4);
  2987. #undef dspfunc
  2988. c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_c;
  2989. c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_c;
  2990. c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_c;
  2991. c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_c;
  2992. c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_c;
  2993. c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_c;
  2994. c->put_mspel_pixels_tab[0]= put_mspel8_mc00_c;
  2995. c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
  2996. c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c;
  2997. c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c;
  2998. c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c;
  2999. c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c;
  3000. c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c;
  3001. c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c;
  3002. #define SET_CMP_FUNC(name) \
  3003. c->name[0]= name ## 16_c;\
  3004. c->name[1]= name ## 8x8_c;
  3005. SET_CMP_FUNC(hadamard8_diff)
  3006. c->hadamard8_diff[4]= hadamard8_intra16_c;
  3007. SET_CMP_FUNC(dct_sad)
  3008. c->sad[0]= pix_abs16_c;
  3009. c->sad[1]= pix_abs8_c;
  3010. c->sse[0]= sse16_c;
  3011. c->sse[1]= sse8_c;
  3012. SET_CMP_FUNC(quant_psnr)
  3013. SET_CMP_FUNC(rd)
  3014. SET_CMP_FUNC(bit)
  3015. c->vsad[0]= vsad16_c;
  3016. c->vsad[4]= vsad_intra16_c;
  3017. c->vsse[0]= vsse16_c;
  3018. c->vsse[4]= vsse_intra16_c;
  3019. c->add_bytes= add_bytes_c;
  3020. c->diff_bytes= diff_bytes_c;
  3021. c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c;
  3022. c->bswap_buf= bswap_buf;
  3023. c->h263_h_loop_filter= h263_h_loop_filter_c;
  3024. c->h263_v_loop_filter= h263_v_loop_filter_c;
  3025. c->try_8x8basis= try_8x8basis_c;
  3026. c->add_8x8basis= add_8x8basis_c;
  3027. #ifdef HAVE_MMX
  3028. dsputil_init_mmx(c, avctx);
  3029. #endif
  3030. #ifdef ARCH_ARMV4L
  3031. dsputil_init_armv4l(c, avctx);
  3032. #endif
  3033. #ifdef HAVE_MLIB
  3034. dsputil_init_mlib(c, avctx);
  3035. #endif
  3036. #ifdef ARCH_ALPHA
  3037. dsputil_init_alpha(c, avctx);
  3038. #endif
  3039. #ifdef ARCH_POWERPC
  3040. dsputil_init_ppc(c, avctx);
  3041. #endif
  3042. #ifdef HAVE_MMI
  3043. dsputil_init_mmi(c, avctx);
  3044. #endif
  3045. #ifdef ARCH_SH4
  3046. dsputil_init_sh4(c,avctx);
  3047. #endif
  3048. switch(c->idct_permutation_type){
  3049. case FF_NO_IDCT_PERM:
  3050. for(i=0; i<64; i++)
  3051. c->idct_permutation[i]= i;
  3052. break;
  3053. case FF_LIBMPEG2_IDCT_PERM:
  3054. for(i=0; i<64; i++)
  3055. c->idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
  3056. break;
  3057. case FF_SIMPLE_IDCT_PERM:
  3058. for(i=0; i<64; i++)
  3059. c->idct_permutation[i]= simple_mmx_permutation[i];
  3060. break;
  3061. case FF_TRANSPOSE_IDCT_PERM:
  3062. for(i=0; i<64; i++)
  3063. c->idct_permutation[i]= ((i&7)<<3) | (i>>3);
  3064. break;
  3065. default:
  3066. av_log(avctx, AV_LOG_ERROR, "Internal error, IDCT permutation not set\n");
  3067. }
  3068. }