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.

2945 lines
110KB

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