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.

3927 lines
139KB

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