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.

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