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.

3250 lines
109KB

  1. /*
  2. * DSP utils
  3. * Copyright (c) 2000, 2001 Fabrice Bellard
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
  7. *
  8. * This file is part of FFmpeg.
  9. *
  10. * FFmpeg is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * FFmpeg is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with FFmpeg; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. /**
  25. * @file
  26. * DSP utils
  27. */
  28. #include "libavutil/imgutils.h"
  29. #include "avcodec.h"
  30. #include "dsputil.h"
  31. #include "simple_idct.h"
  32. #include "faandct.h"
  33. #include "faanidct.h"
  34. #include "mathops.h"
  35. #include "mpegvideo.h"
  36. #include "config.h"
  37. #include "ac3dec.h"
  38. #include "vorbis.h"
  39. uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP] = {0, };
  40. uint32_t ff_squareTbl[512] = {0, };
  41. #define BIT_DEPTH 9
  42. #include "dsputil_template.c"
  43. #undef BIT_DEPTH
  44. #define BIT_DEPTH 10
  45. #include "dsputil_template.c"
  46. #undef BIT_DEPTH
  47. #define BIT_DEPTH 8
  48. #include "dsputil_template.c"
  49. // 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size
  50. #define pb_7f (~0UL/255 * 0x7f)
  51. #define pb_80 (~0UL/255 * 0x80)
  52. const uint8_t ff_zigzag_direct[64] = {
  53. 0, 1, 8, 16, 9, 2, 3, 10,
  54. 17, 24, 32, 25, 18, 11, 4, 5,
  55. 12, 19, 26, 33, 40, 48, 41, 34,
  56. 27, 20, 13, 6, 7, 14, 21, 28,
  57. 35, 42, 49, 56, 57, 50, 43, 36,
  58. 29, 22, 15, 23, 30, 37, 44, 51,
  59. 58, 59, 52, 45, 38, 31, 39, 46,
  60. 53, 60, 61, 54, 47, 55, 62, 63
  61. };
  62. /* Specific zigzag scan for 248 idct. NOTE that unlike the
  63. specification, we interleave the fields */
  64. const uint8_t ff_zigzag248_direct[64] = {
  65. 0, 8, 1, 9, 16, 24, 2, 10,
  66. 17, 25, 32, 40, 48, 56, 33, 41,
  67. 18, 26, 3, 11, 4, 12, 19, 27,
  68. 34, 42, 49, 57, 50, 58, 35, 43,
  69. 20, 28, 5, 13, 6, 14, 21, 29,
  70. 36, 44, 51, 59, 52, 60, 37, 45,
  71. 22, 30, 7, 15, 23, 31, 38, 46,
  72. 53, 61, 54, 62, 39, 47, 55, 63,
  73. };
  74. /* not permutated inverse zigzag_direct + 1 for MMX quantizer */
  75. DECLARE_ALIGNED(16, uint16_t, inv_zigzag_direct16)[64];
  76. const uint8_t ff_alternate_horizontal_scan[64] = {
  77. 0, 1, 2, 3, 8, 9, 16, 17,
  78. 10, 11, 4, 5, 6, 7, 15, 14,
  79. 13, 12, 19, 18, 24, 25, 32, 33,
  80. 26, 27, 20, 21, 22, 23, 28, 29,
  81. 30, 31, 34, 35, 40, 41, 48, 49,
  82. 42, 43, 36, 37, 38, 39, 44, 45,
  83. 46, 47, 50, 51, 56, 57, 58, 59,
  84. 52, 53, 54, 55, 60, 61, 62, 63,
  85. };
  86. const uint8_t ff_alternate_vertical_scan[64] = {
  87. 0, 8, 16, 24, 1, 9, 2, 10,
  88. 17, 25, 32, 40, 48, 56, 57, 49,
  89. 41, 33, 26, 18, 3, 11, 4, 12,
  90. 19, 27, 34, 42, 50, 58, 35, 43,
  91. 51, 59, 20, 28, 5, 13, 6, 14,
  92. 21, 29, 36, 44, 52, 60, 37, 45,
  93. 53, 61, 22, 30, 7, 15, 23, 31,
  94. 38, 46, 54, 62, 39, 47, 55, 63,
  95. };
  96. /* Input permutation for the simple_idct_mmx */
  97. static const uint8_t simple_mmx_permutation[64]={
  98. 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D,
  99. 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D,
  100. 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D,
  101. 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F,
  102. 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F,
  103. 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D,
  104. 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F,
  105. 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F,
  106. };
  107. static const uint8_t idct_sse2_row_perm[8] = {0, 4, 1, 5, 2, 6, 3, 7};
  108. void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable){
  109. int i;
  110. int end;
  111. st->scantable= src_scantable;
  112. for(i=0; i<64; i++){
  113. int j;
  114. j = src_scantable[i];
  115. st->permutated[i] = permutation[j];
  116. #if ARCH_PPC
  117. st->inverse[j] = i;
  118. #endif
  119. }
  120. end=-1;
  121. for(i=0; i<64; i++){
  122. int j;
  123. j = st->permutated[i];
  124. if(j>end) end=j;
  125. st->raster_end[i]= end;
  126. }
  127. }
  128. static int pix_sum_c(uint8_t * pix, int line_size)
  129. {
  130. int s, i, j;
  131. s = 0;
  132. for (i = 0; i < 16; i++) {
  133. for (j = 0; j < 16; j += 8) {
  134. s += pix[0];
  135. s += pix[1];
  136. s += pix[2];
  137. s += pix[3];
  138. s += pix[4];
  139. s += pix[5];
  140. s += pix[6];
  141. s += pix[7];
  142. pix += 8;
  143. }
  144. pix += line_size - 16;
  145. }
  146. return s;
  147. }
  148. static int pix_norm1_c(uint8_t * pix, int line_size)
  149. {
  150. int s, i, j;
  151. uint32_t *sq = ff_squareTbl + 256;
  152. s = 0;
  153. for (i = 0; i < 16; i++) {
  154. for (j = 0; j < 16; j += 8) {
  155. #if 0
  156. s += sq[pix[0]];
  157. s += sq[pix[1]];
  158. s += sq[pix[2]];
  159. s += sq[pix[3]];
  160. s += sq[pix[4]];
  161. s += sq[pix[5]];
  162. s += sq[pix[6]];
  163. s += sq[pix[7]];
  164. #else
  165. #if HAVE_FAST_64BIT
  166. register uint64_t x=*(uint64_t*)pix;
  167. s += sq[x&0xff];
  168. s += sq[(x>>8)&0xff];
  169. s += sq[(x>>16)&0xff];
  170. s += sq[(x>>24)&0xff];
  171. s += sq[(x>>32)&0xff];
  172. s += sq[(x>>40)&0xff];
  173. s += sq[(x>>48)&0xff];
  174. s += sq[(x>>56)&0xff];
  175. #else
  176. register uint32_t x=*(uint32_t*)pix;
  177. s += sq[x&0xff];
  178. s += sq[(x>>8)&0xff];
  179. s += sq[(x>>16)&0xff];
  180. s += sq[(x>>24)&0xff];
  181. x=*(uint32_t*)(pix+4);
  182. s += sq[x&0xff];
  183. s += sq[(x>>8)&0xff];
  184. s += sq[(x>>16)&0xff];
  185. s += sq[(x>>24)&0xff];
  186. #endif
  187. #endif
  188. pix += 8;
  189. }
  190. pix += line_size - 16;
  191. }
  192. return s;
  193. }
  194. static void bswap_buf(uint32_t *dst, const uint32_t *src, int w){
  195. int i;
  196. for(i=0; i+8<=w; i+=8){
  197. dst[i+0]= av_bswap32(src[i+0]);
  198. dst[i+1]= av_bswap32(src[i+1]);
  199. dst[i+2]= av_bswap32(src[i+2]);
  200. dst[i+3]= av_bswap32(src[i+3]);
  201. dst[i+4]= av_bswap32(src[i+4]);
  202. dst[i+5]= av_bswap32(src[i+5]);
  203. dst[i+6]= av_bswap32(src[i+6]);
  204. dst[i+7]= av_bswap32(src[i+7]);
  205. }
  206. for(;i<w; i++){
  207. dst[i+0]= av_bswap32(src[i+0]);
  208. }
  209. }
  210. static void bswap16_buf(uint16_t *dst, const uint16_t *src, int len)
  211. {
  212. while (len--)
  213. *dst++ = av_bswap16(*src++);
  214. }
  215. static int sse4_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
  216. {
  217. int s, i;
  218. uint32_t *sq = ff_squareTbl + 256;
  219. s = 0;
  220. for (i = 0; i < h; i++) {
  221. s += sq[pix1[0] - pix2[0]];
  222. s += sq[pix1[1] - pix2[1]];
  223. s += sq[pix1[2] - pix2[2]];
  224. s += sq[pix1[3] - pix2[3]];
  225. pix1 += line_size;
  226. pix2 += line_size;
  227. }
  228. return s;
  229. }
  230. static int sse8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
  231. {
  232. int s, i;
  233. uint32_t *sq = ff_squareTbl + 256;
  234. s = 0;
  235. for (i = 0; i < h; i++) {
  236. s += sq[pix1[0] - pix2[0]];
  237. s += sq[pix1[1] - pix2[1]];
  238. s += sq[pix1[2] - pix2[2]];
  239. s += sq[pix1[3] - pix2[3]];
  240. s += sq[pix1[4] - pix2[4]];
  241. s += sq[pix1[5] - pix2[5]];
  242. s += sq[pix1[6] - pix2[6]];
  243. s += sq[pix1[7] - pix2[7]];
  244. pix1 += line_size;
  245. pix2 += line_size;
  246. }
  247. return s;
  248. }
  249. static int sse16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  250. {
  251. int s, i;
  252. uint32_t *sq = ff_squareTbl + 256;
  253. s = 0;
  254. for (i = 0; i < h; i++) {
  255. s += sq[pix1[ 0] - pix2[ 0]];
  256. s += sq[pix1[ 1] - pix2[ 1]];
  257. s += sq[pix1[ 2] - pix2[ 2]];
  258. s += sq[pix1[ 3] - pix2[ 3]];
  259. s += sq[pix1[ 4] - pix2[ 4]];
  260. s += sq[pix1[ 5] - pix2[ 5]];
  261. s += sq[pix1[ 6] - pix2[ 6]];
  262. s += sq[pix1[ 7] - pix2[ 7]];
  263. s += sq[pix1[ 8] - pix2[ 8]];
  264. s += sq[pix1[ 9] - pix2[ 9]];
  265. s += sq[pix1[10] - pix2[10]];
  266. s += sq[pix1[11] - pix2[11]];
  267. s += sq[pix1[12] - pix2[12]];
  268. s += sq[pix1[13] - pix2[13]];
  269. s += sq[pix1[14] - pix2[14]];
  270. s += sq[pix1[15] - pix2[15]];
  271. pix1 += line_size;
  272. pix2 += line_size;
  273. }
  274. return s;
  275. }
  276. static void get_pixels_c(DCTELEM *restrict block, const uint8_t *pixels, int line_size)
  277. {
  278. int i;
  279. /* read the pixels */
  280. for(i=0;i<8;i++) {
  281. block[0] = pixels[0];
  282. block[1] = pixels[1];
  283. block[2] = pixels[2];
  284. block[3] = pixels[3];
  285. block[4] = pixels[4];
  286. block[5] = pixels[5];
  287. block[6] = pixels[6];
  288. block[7] = pixels[7];
  289. pixels += line_size;
  290. block += 8;
  291. }
  292. }
  293. static void diff_pixels_c(DCTELEM *restrict block, const uint8_t *s1,
  294. const uint8_t *s2, int stride){
  295. int i;
  296. /* read the pixels */
  297. for(i=0;i<8;i++) {
  298. block[0] = s1[0] - s2[0];
  299. block[1] = s1[1] - s2[1];
  300. block[2] = s1[2] - s2[2];
  301. block[3] = s1[3] - s2[3];
  302. block[4] = s1[4] - s2[4];
  303. block[5] = s1[5] - s2[5];
  304. block[6] = s1[6] - s2[6];
  305. block[7] = s1[7] - s2[7];
  306. s1 += stride;
  307. s2 += stride;
  308. block += 8;
  309. }
  310. }
  311. void ff_put_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
  312. int line_size)
  313. {
  314. int i;
  315. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  316. /* read the pixels */
  317. for(i=0;i<8;i++) {
  318. pixels[0] = cm[block[0]];
  319. pixels[1] = cm[block[1]];
  320. pixels[2] = cm[block[2]];
  321. pixels[3] = cm[block[3]];
  322. pixels[4] = cm[block[4]];
  323. pixels[5] = cm[block[5]];
  324. pixels[6] = cm[block[6]];
  325. pixels[7] = cm[block[7]];
  326. pixels += line_size;
  327. block += 8;
  328. }
  329. }
  330. static void put_pixels_clamped4_c(const DCTELEM *block, uint8_t *restrict pixels,
  331. int line_size)
  332. {
  333. int i;
  334. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  335. /* read the pixels */
  336. for(i=0;i<4;i++) {
  337. pixels[0] = cm[block[0]];
  338. pixels[1] = cm[block[1]];
  339. pixels[2] = cm[block[2]];
  340. pixels[3] = cm[block[3]];
  341. pixels += line_size;
  342. block += 8;
  343. }
  344. }
  345. static void put_pixels_clamped2_c(const DCTELEM *block, uint8_t *restrict pixels,
  346. int line_size)
  347. {
  348. int i;
  349. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  350. /* read the pixels */
  351. for(i=0;i<2;i++) {
  352. pixels[0] = cm[block[0]];
  353. pixels[1] = cm[block[1]];
  354. pixels += line_size;
  355. block += 8;
  356. }
  357. }
  358. void ff_put_signed_pixels_clamped_c(const DCTELEM *block,
  359. uint8_t *restrict pixels,
  360. int line_size)
  361. {
  362. int i, j;
  363. for (i = 0; i < 8; i++) {
  364. for (j = 0; j < 8; j++) {
  365. if (*block < -128)
  366. *pixels = 0;
  367. else if (*block > 127)
  368. *pixels = 255;
  369. else
  370. *pixels = (uint8_t)(*block + 128);
  371. block++;
  372. pixels++;
  373. }
  374. pixels += (line_size - 8);
  375. }
  376. }
  377. static void put_pixels_nonclamped_c(const DCTELEM *block, uint8_t *restrict pixels,
  378. int line_size)
  379. {
  380. int i;
  381. /* read the pixels */
  382. for(i=0;i<8;i++) {
  383. pixels[0] = block[0];
  384. pixels[1] = block[1];
  385. pixels[2] = block[2];
  386. pixels[3] = block[3];
  387. pixels[4] = block[4];
  388. pixels[5] = block[5];
  389. pixels[6] = block[6];
  390. pixels[7] = block[7];
  391. pixels += line_size;
  392. block += 8;
  393. }
  394. }
  395. void ff_add_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
  396. int line_size)
  397. {
  398. int i;
  399. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  400. /* read the pixels */
  401. for(i=0;i<8;i++) {
  402. pixels[0] = cm[pixels[0] + block[0]];
  403. pixels[1] = cm[pixels[1] + block[1]];
  404. pixels[2] = cm[pixels[2] + block[2]];
  405. pixels[3] = cm[pixels[3] + block[3]];
  406. pixels[4] = cm[pixels[4] + block[4]];
  407. pixels[5] = cm[pixels[5] + block[5]];
  408. pixels[6] = cm[pixels[6] + block[6]];
  409. pixels[7] = cm[pixels[7] + block[7]];
  410. pixels += line_size;
  411. block += 8;
  412. }
  413. }
  414. static void add_pixels_clamped4_c(const DCTELEM *block, uint8_t *restrict pixels,
  415. int line_size)
  416. {
  417. int i;
  418. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  419. /* read the pixels */
  420. for(i=0;i<4;i++) {
  421. pixels[0] = cm[pixels[0] + block[0]];
  422. pixels[1] = cm[pixels[1] + block[1]];
  423. pixels[2] = cm[pixels[2] + block[2]];
  424. pixels[3] = cm[pixels[3] + block[3]];
  425. pixels += line_size;
  426. block += 8;
  427. }
  428. }
  429. static void add_pixels_clamped2_c(const DCTELEM *block, uint8_t *restrict pixels,
  430. int line_size)
  431. {
  432. int i;
  433. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  434. /* read the pixels */
  435. for(i=0;i<2;i++) {
  436. pixels[0] = cm[pixels[0] + block[0]];
  437. pixels[1] = cm[pixels[1] + block[1]];
  438. pixels += line_size;
  439. block += 8;
  440. }
  441. }
  442. static int sum_abs_dctelem_c(DCTELEM *block)
  443. {
  444. int sum=0, i;
  445. for(i=0; i<64; i++)
  446. sum+= FFABS(block[i]);
  447. return sum;
  448. }
  449. static void fill_block16_c(uint8_t *block, uint8_t value, int line_size, int h)
  450. {
  451. int i;
  452. for (i = 0; i < h; i++) {
  453. memset(block, value, 16);
  454. block += line_size;
  455. }
  456. }
  457. static void fill_block8_c(uint8_t *block, uint8_t value, int line_size, int h)
  458. {
  459. int i;
  460. for (i = 0; i < h; i++) {
  461. memset(block, value, 8);
  462. block += line_size;
  463. }
  464. }
  465. static void scale_block_c(const uint8_t src[64]/*align 8*/, uint8_t *dst/*align 8*/, int linesize)
  466. {
  467. int i, j;
  468. uint16_t *dst1 = (uint16_t *) dst;
  469. uint16_t *dst2 = (uint16_t *)(dst + linesize);
  470. for (j = 0; j < 8; j++) {
  471. for (i = 0; i < 8; i++) {
  472. dst1[i] = dst2[i] = src[i] * 0x0101;
  473. }
  474. src += 8;
  475. dst1 += linesize;
  476. dst2 += linesize;
  477. }
  478. }
  479. #define avg2(a,b) ((a+b+1)>>1)
  480. #define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
  481. static void gmc1_c(uint8_t *dst, uint8_t *src, int stride, int h, int x16, int y16, int rounder)
  482. {
  483. const int A=(16-x16)*(16-y16);
  484. const int B=( x16)*(16-y16);
  485. const int C=(16-x16)*( y16);
  486. const int D=( x16)*( y16);
  487. int i;
  488. for(i=0; i<h; i++)
  489. {
  490. dst[0]= (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + rounder)>>8;
  491. dst[1]= (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + rounder)>>8;
  492. dst[2]= (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + rounder)>>8;
  493. dst[3]= (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + rounder)>>8;
  494. dst[4]= (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + rounder)>>8;
  495. dst[5]= (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + rounder)>>8;
  496. dst[6]= (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + rounder)>>8;
  497. dst[7]= (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + rounder)>>8;
  498. dst+= stride;
  499. src+= stride;
  500. }
  501. }
  502. void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
  503. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
  504. {
  505. int y, vx, vy;
  506. const int s= 1<<shift;
  507. width--;
  508. height--;
  509. for(y=0; y<h; y++){
  510. int x;
  511. vx= ox;
  512. vy= oy;
  513. for(x=0; x<8; x++){ //XXX FIXME optimize
  514. int src_x, src_y, frac_x, frac_y, index;
  515. src_x= vx>>16;
  516. src_y= vy>>16;
  517. frac_x= src_x&(s-1);
  518. frac_y= src_y&(s-1);
  519. src_x>>=shift;
  520. src_y>>=shift;
  521. if((unsigned)src_x < width){
  522. if((unsigned)src_y < height){
  523. index= src_x + src_y*stride;
  524. dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
  525. + src[index +1]* frac_x )*(s-frac_y)
  526. + ( src[index+stride ]*(s-frac_x)
  527. + src[index+stride+1]* frac_x )* frac_y
  528. + r)>>(shift*2);
  529. }else{
  530. index= src_x + av_clip(src_y, 0, height)*stride;
  531. dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
  532. + src[index +1]* frac_x )*s
  533. + r)>>(shift*2);
  534. }
  535. }else{
  536. if((unsigned)src_y < height){
  537. index= av_clip(src_x, 0, width) + src_y*stride;
  538. dst[y*stride + x]= ( ( src[index ]*(s-frac_y)
  539. + src[index+stride ]* frac_y )*s
  540. + r)>>(shift*2);
  541. }else{
  542. index= av_clip(src_x, 0, width) + av_clip(src_y, 0, height)*stride;
  543. dst[y*stride + x]= src[index ];
  544. }
  545. }
  546. vx+= dxx;
  547. vy+= dyx;
  548. }
  549. ox += dxy;
  550. oy += dyy;
  551. }
  552. }
  553. static inline void put_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  554. switch(width){
  555. case 2: put_pixels2_8_c (dst, src, stride, height); break;
  556. case 4: put_pixels4_8_c (dst, src, stride, height); break;
  557. case 8: put_pixels8_8_c (dst, src, stride, height); break;
  558. case 16:put_pixels16_8_c(dst, src, stride, height); break;
  559. }
  560. }
  561. static inline void put_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  562. int i,j;
  563. for (i=0; i < height; i++) {
  564. for (j=0; j < width; j++) {
  565. dst[j] = (683*(2*src[j] + src[j+1] + 1)) >> 11;
  566. }
  567. src += stride;
  568. dst += stride;
  569. }
  570. }
  571. static inline void put_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  572. int i,j;
  573. for (i=0; i < height; i++) {
  574. for (j=0; j < width; j++) {
  575. dst[j] = (683*(src[j] + 2*src[j+1] + 1)) >> 11;
  576. }
  577. src += stride;
  578. dst += stride;
  579. }
  580. }
  581. static inline void put_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  582. int i,j;
  583. for (i=0; i < height; i++) {
  584. for (j=0; j < width; j++) {
  585. dst[j] = (683*(2*src[j] + src[j+stride] + 1)) >> 11;
  586. }
  587. src += stride;
  588. dst += stride;
  589. }
  590. }
  591. static inline void put_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  592. int i,j;
  593. for (i=0; i < height; i++) {
  594. for (j=0; j < width; j++) {
  595. dst[j] = (2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15;
  596. }
  597. src += stride;
  598. dst += stride;
  599. }
  600. }
  601. static inline void put_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  602. int i,j;
  603. for (i=0; i < height; i++) {
  604. for (j=0; j < width; j++) {
  605. dst[j] = (2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
  606. }
  607. src += stride;
  608. dst += stride;
  609. }
  610. }
  611. static inline void put_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  612. int i,j;
  613. for (i=0; i < height; i++) {
  614. for (j=0; j < width; j++) {
  615. dst[j] = (683*(src[j] + 2*src[j+stride] + 1)) >> 11;
  616. }
  617. src += stride;
  618. dst += stride;
  619. }
  620. }
  621. static inline void put_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  622. int i,j;
  623. for (i=0; i < height; i++) {
  624. for (j=0; j < width; j++) {
  625. dst[j] = (2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
  626. }
  627. src += stride;
  628. dst += stride;
  629. }
  630. }
  631. static inline void put_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  632. int i,j;
  633. for (i=0; i < height; i++) {
  634. for (j=0; j < width; j++) {
  635. dst[j] = (2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15;
  636. }
  637. src += stride;
  638. dst += stride;
  639. }
  640. }
  641. static inline void avg_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  642. switch(width){
  643. case 2: avg_pixels2_8_c (dst, src, stride, height); break;
  644. case 4: avg_pixels4_8_c (dst, src, stride, height); break;
  645. case 8: avg_pixels8_8_c (dst, src, stride, height); break;
  646. case 16:avg_pixels16_8_c(dst, src, stride, height); break;
  647. }
  648. }
  649. static inline void avg_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  650. int i,j;
  651. for (i=0; i < height; i++) {
  652. for (j=0; j < width; j++) {
  653. dst[j] = (dst[j] + ((683*(2*src[j] + src[j+1] + 1)) >> 11) + 1) >> 1;
  654. }
  655. src += stride;
  656. dst += stride;
  657. }
  658. }
  659. static inline void avg_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  660. int i,j;
  661. for (i=0; i < height; i++) {
  662. for (j=0; j < width; j++) {
  663. dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+1] + 1)) >> 11) + 1) >> 1;
  664. }
  665. src += stride;
  666. dst += stride;
  667. }
  668. }
  669. static inline void avg_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  670. int i,j;
  671. for (i=0; i < height; i++) {
  672. for (j=0; j < width; j++) {
  673. dst[j] = (dst[j] + ((683*(2*src[j] + src[j+stride] + 1)) >> 11) + 1) >> 1;
  674. }
  675. src += stride;
  676. dst += stride;
  677. }
  678. }
  679. static inline void avg_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  680. int i,j;
  681. for (i=0; i < height; i++) {
  682. for (j=0; j < width; j++) {
  683. 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;
  684. }
  685. src += stride;
  686. dst += stride;
  687. }
  688. }
  689. static inline void avg_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  690. int i,j;
  691. for (i=0; i < height; i++) {
  692. for (j=0; j < width; j++) {
  693. 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;
  694. }
  695. src += stride;
  696. dst += stride;
  697. }
  698. }
  699. static inline void avg_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  700. int i,j;
  701. for (i=0; i < height; i++) {
  702. for (j=0; j < width; j++) {
  703. dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+stride] + 1)) >> 11) + 1) >> 1;
  704. }
  705. src += stride;
  706. dst += stride;
  707. }
  708. }
  709. static inline void avg_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  710. int i,j;
  711. for (i=0; i < height; i++) {
  712. for (j=0; j < width; j++) {
  713. 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;
  714. }
  715. src += stride;
  716. dst += stride;
  717. }
  718. }
  719. static inline void avg_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  720. int i,j;
  721. for (i=0; i < height; i++) {
  722. for (j=0; j < width; j++) {
  723. 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;
  724. }
  725. src += stride;
  726. dst += stride;
  727. }
  728. }
  729. #define QPEL_MC(r, OPNAME, RND, OP) \
  730. static void OPNAME ## mpeg4_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  731. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  732. int i;\
  733. for(i=0; i<h; i++)\
  734. {\
  735. OP(dst[0], (src[0]+src[1])*20 - (src[0]+src[2])*6 + (src[1]+src[3])*3 - (src[2]+src[4]));\
  736. OP(dst[1], (src[1]+src[2])*20 - (src[0]+src[3])*6 + (src[0]+src[4])*3 - (src[1]+src[5]));\
  737. OP(dst[2], (src[2]+src[3])*20 - (src[1]+src[4])*6 + (src[0]+src[5])*3 - (src[0]+src[6]));\
  738. OP(dst[3], (src[3]+src[4])*20 - (src[2]+src[5])*6 + (src[1]+src[6])*3 - (src[0]+src[7]));\
  739. OP(dst[4], (src[4]+src[5])*20 - (src[3]+src[6])*6 + (src[2]+src[7])*3 - (src[1]+src[8]));\
  740. OP(dst[5], (src[5]+src[6])*20 - (src[4]+src[7])*6 + (src[3]+src[8])*3 - (src[2]+src[8]));\
  741. OP(dst[6], (src[6]+src[7])*20 - (src[5]+src[8])*6 + (src[4]+src[8])*3 - (src[3]+src[7]));\
  742. OP(dst[7], (src[7]+src[8])*20 - (src[6]+src[8])*6 + (src[5]+src[7])*3 - (src[4]+src[6]));\
  743. dst+=dstStride;\
  744. src+=srcStride;\
  745. }\
  746. }\
  747. \
  748. static void OPNAME ## mpeg4_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  749. const int w=8;\
  750. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  751. int i;\
  752. for(i=0; i<w; i++)\
  753. {\
  754. const int src0= src[0*srcStride];\
  755. const int src1= src[1*srcStride];\
  756. const int src2= src[2*srcStride];\
  757. const int src3= src[3*srcStride];\
  758. const int src4= src[4*srcStride];\
  759. const int src5= src[5*srcStride];\
  760. const int src6= src[6*srcStride];\
  761. const int src7= src[7*srcStride];\
  762. const int src8= src[8*srcStride];\
  763. OP(dst[0*dstStride], (src0+src1)*20 - (src0+src2)*6 + (src1+src3)*3 - (src2+src4));\
  764. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*6 + (src0+src4)*3 - (src1+src5));\
  765. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*6 + (src0+src5)*3 - (src0+src6));\
  766. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*6 + (src1+src6)*3 - (src0+src7));\
  767. OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*6 + (src2+src7)*3 - (src1+src8));\
  768. OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*6 + (src3+src8)*3 - (src2+src8));\
  769. OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*6 + (src4+src8)*3 - (src3+src7));\
  770. OP(dst[7*dstStride], (src7+src8)*20 - (src6+src8)*6 + (src5+src7)*3 - (src4+src6));\
  771. dst++;\
  772. src++;\
  773. }\
  774. }\
  775. \
  776. static void OPNAME ## mpeg4_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  777. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  778. int i;\
  779. \
  780. for(i=0; i<h; i++)\
  781. {\
  782. OP(dst[ 0], (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]));\
  783. OP(dst[ 1], (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]));\
  784. OP(dst[ 2], (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]));\
  785. OP(dst[ 3], (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]));\
  786. OP(dst[ 4], (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]));\
  787. OP(dst[ 5], (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]));\
  788. OP(dst[ 6], (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]));\
  789. OP(dst[ 7], (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]));\
  790. OP(dst[ 8], (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]));\
  791. OP(dst[ 9], (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]));\
  792. OP(dst[10], (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]));\
  793. OP(dst[11], (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]));\
  794. OP(dst[12], (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]));\
  795. OP(dst[13], (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]));\
  796. OP(dst[14], (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]));\
  797. OP(dst[15], (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]));\
  798. dst+=dstStride;\
  799. src+=srcStride;\
  800. }\
  801. }\
  802. \
  803. static void OPNAME ## mpeg4_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  804. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  805. int i;\
  806. const int w=16;\
  807. for(i=0; i<w; i++)\
  808. {\
  809. const int src0= src[0*srcStride];\
  810. const int src1= src[1*srcStride];\
  811. const int src2= src[2*srcStride];\
  812. const int src3= src[3*srcStride];\
  813. const int src4= src[4*srcStride];\
  814. const int src5= src[5*srcStride];\
  815. const int src6= src[6*srcStride];\
  816. const int src7= src[7*srcStride];\
  817. const int src8= src[8*srcStride];\
  818. const int src9= src[9*srcStride];\
  819. const int src10= src[10*srcStride];\
  820. const int src11= src[11*srcStride];\
  821. const int src12= src[12*srcStride];\
  822. const int src13= src[13*srcStride];\
  823. const int src14= src[14*srcStride];\
  824. const int src15= src[15*srcStride];\
  825. const int src16= src[16*srcStride];\
  826. OP(dst[ 0*dstStride], (src0 +src1 )*20 - (src0 +src2 )*6 + (src1 +src3 )*3 - (src2 +src4 ));\
  827. OP(dst[ 1*dstStride], (src1 +src2 )*20 - (src0 +src3 )*6 + (src0 +src4 )*3 - (src1 +src5 ));\
  828. OP(dst[ 2*dstStride], (src2 +src3 )*20 - (src1 +src4 )*6 + (src0 +src5 )*3 - (src0 +src6 ));\
  829. OP(dst[ 3*dstStride], (src3 +src4 )*20 - (src2 +src5 )*6 + (src1 +src6 )*3 - (src0 +src7 ));\
  830. OP(dst[ 4*dstStride], (src4 +src5 )*20 - (src3 +src6 )*6 + (src2 +src7 )*3 - (src1 +src8 ));\
  831. OP(dst[ 5*dstStride], (src5 +src6 )*20 - (src4 +src7 )*6 + (src3 +src8 )*3 - (src2 +src9 ));\
  832. OP(dst[ 6*dstStride], (src6 +src7 )*20 - (src5 +src8 )*6 + (src4 +src9 )*3 - (src3 +src10));\
  833. OP(dst[ 7*dstStride], (src7 +src8 )*20 - (src6 +src9 )*6 + (src5 +src10)*3 - (src4 +src11));\
  834. OP(dst[ 8*dstStride], (src8 +src9 )*20 - (src7 +src10)*6 + (src6 +src11)*3 - (src5 +src12));\
  835. OP(dst[ 9*dstStride], (src9 +src10)*20 - (src8 +src11)*6 + (src7 +src12)*3 - (src6 +src13));\
  836. OP(dst[10*dstStride], (src10+src11)*20 - (src9 +src12)*6 + (src8 +src13)*3 - (src7 +src14));\
  837. OP(dst[11*dstStride], (src11+src12)*20 - (src10+src13)*6 + (src9 +src14)*3 - (src8 +src15));\
  838. OP(dst[12*dstStride], (src12+src13)*20 - (src11+src14)*6 + (src10+src15)*3 - (src9 +src16));\
  839. OP(dst[13*dstStride], (src13+src14)*20 - (src12+src15)*6 + (src11+src16)*3 - (src10+src16));\
  840. OP(dst[14*dstStride], (src14+src15)*20 - (src13+src16)*6 + (src12+src16)*3 - (src11+src15));\
  841. OP(dst[15*dstStride], (src15+src16)*20 - (src14+src16)*6 + (src13+src15)*3 - (src12+src14));\
  842. dst++;\
  843. src++;\
  844. }\
  845. }\
  846. \
  847. static void OPNAME ## qpel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  848. uint8_t half[64];\
  849. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  850. OPNAME ## pixels8_l2_8(dst, src, half, stride, stride, 8, 8);\
  851. }\
  852. \
  853. static void OPNAME ## qpel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  854. OPNAME ## mpeg4_qpel8_h_lowpass(dst, src, stride, stride, 8);\
  855. }\
  856. \
  857. static void OPNAME ## qpel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  858. uint8_t half[64];\
  859. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  860. OPNAME ## pixels8_l2_8(dst, src+1, half, stride, stride, 8, 8);\
  861. }\
  862. \
  863. static void OPNAME ## qpel8_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  864. uint8_t full[16*9];\
  865. uint8_t half[64];\
  866. copy_block9(full, src, 16, stride, 9);\
  867. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
  868. OPNAME ## pixels8_l2_8(dst, full, half, stride, 16, 8, 8);\
  869. }\
  870. \
  871. static void OPNAME ## qpel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  872. uint8_t full[16*9];\
  873. copy_block9(full, src, 16, stride, 9);\
  874. OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);\
  875. }\
  876. \
  877. static void OPNAME ## qpel8_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  878. uint8_t full[16*9];\
  879. uint8_t half[64];\
  880. copy_block9(full, src, 16, stride, 9);\
  881. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
  882. OPNAME ## pixels8_l2_8(dst, full+16, half, stride, 16, 8, 8);\
  883. }\
  884. void ff_ ## OPNAME ## qpel8_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
  885. uint8_t full[16*9];\
  886. uint8_t halfH[72];\
  887. uint8_t halfV[64];\
  888. uint8_t halfHV[64];\
  889. copy_block9(full, src, 16, stride, 9);\
  890. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  891. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  892. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  893. OPNAME ## pixels8_l4_8(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  894. }\
  895. static void OPNAME ## qpel8_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  896. uint8_t full[16*9];\
  897. uint8_t halfH[72];\
  898. uint8_t halfHV[64];\
  899. copy_block9(full, src, 16, stride, 9);\
  900. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  901. put ## RND ## pixels8_l2_8(halfH, halfH, full, 8, 8, 16, 9);\
  902. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  903. OPNAME ## pixels8_l2_8(dst, halfH, halfHV, stride, 8, 8, 8);\
  904. }\
  905. void ff_ ## OPNAME ## qpel8_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
  906. uint8_t full[16*9];\
  907. uint8_t halfH[72];\
  908. uint8_t halfV[64];\
  909. uint8_t halfHV[64];\
  910. copy_block9(full, src, 16, stride, 9);\
  911. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  912. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  913. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  914. OPNAME ## pixels8_l4_8(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  915. }\
  916. static void OPNAME ## qpel8_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  917. uint8_t full[16*9];\
  918. uint8_t halfH[72];\
  919. uint8_t halfHV[64];\
  920. copy_block9(full, src, 16, stride, 9);\
  921. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  922. put ## RND ## pixels8_l2_8(halfH, halfH, full+1, 8, 8, 16, 9);\
  923. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  924. OPNAME ## pixels8_l2_8(dst, halfH, halfHV, stride, 8, 8, 8);\
  925. }\
  926. void ff_ ## OPNAME ## qpel8_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
  927. uint8_t full[16*9];\
  928. uint8_t halfH[72];\
  929. uint8_t halfV[64];\
  930. uint8_t halfHV[64];\
  931. copy_block9(full, src, 16, stride, 9);\
  932. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  933. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  934. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  935. OPNAME ## pixels8_l4_8(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  936. }\
  937. static void OPNAME ## qpel8_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  938. uint8_t full[16*9];\
  939. uint8_t halfH[72];\
  940. uint8_t halfHV[64];\
  941. copy_block9(full, src, 16, stride, 9);\
  942. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  943. put ## RND ## pixels8_l2_8(halfH, halfH, full, 8, 8, 16, 9);\
  944. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  945. OPNAME ## pixels8_l2_8(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  946. }\
  947. void ff_ ## OPNAME ## qpel8_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
  948. uint8_t full[16*9];\
  949. uint8_t halfH[72];\
  950. uint8_t halfV[64];\
  951. uint8_t halfHV[64];\
  952. copy_block9(full, src, 16, stride, 9);\
  953. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full , 8, 16, 9);\
  954. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  955. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  956. OPNAME ## pixels8_l4_8(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  957. }\
  958. static void OPNAME ## qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  959. uint8_t full[16*9];\
  960. uint8_t halfH[72];\
  961. uint8_t halfHV[64];\
  962. copy_block9(full, src, 16, stride, 9);\
  963. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  964. put ## RND ## pixels8_l2_8(halfH, halfH, full+1, 8, 8, 16, 9);\
  965. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  966. OPNAME ## pixels8_l2_8(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  967. }\
  968. static void OPNAME ## qpel8_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  969. uint8_t halfH[72];\
  970. uint8_t halfHV[64];\
  971. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  972. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  973. OPNAME ## pixels8_l2_8(dst, halfH, halfHV, stride, 8, 8, 8);\
  974. }\
  975. static void OPNAME ## qpel8_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  976. uint8_t halfH[72];\
  977. uint8_t halfHV[64];\
  978. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  979. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  980. OPNAME ## pixels8_l2_8(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  981. }\
  982. void ff_ ## OPNAME ## qpel8_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
  983. uint8_t full[16*9];\
  984. uint8_t halfH[72];\
  985. uint8_t halfV[64];\
  986. uint8_t halfHV[64];\
  987. copy_block9(full, src, 16, stride, 9);\
  988. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  989. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  990. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  991. OPNAME ## pixels8_l2_8(dst, halfV, halfHV, stride, 8, 8, 8);\
  992. }\
  993. static void OPNAME ## qpel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  994. uint8_t full[16*9];\
  995. uint8_t halfH[72];\
  996. copy_block9(full, src, 16, stride, 9);\
  997. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  998. put ## RND ## pixels8_l2_8(halfH, halfH, full, 8, 8, 16, 9);\
  999. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1000. }\
  1001. void ff_ ## OPNAME ## qpel8_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1002. uint8_t full[16*9];\
  1003. uint8_t halfH[72];\
  1004. uint8_t halfV[64];\
  1005. uint8_t halfHV[64];\
  1006. copy_block9(full, src, 16, stride, 9);\
  1007. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1008. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  1009. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1010. OPNAME ## pixels8_l2_8(dst, halfV, halfHV, stride, 8, 8, 8);\
  1011. }\
  1012. static void OPNAME ## qpel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  1013. uint8_t full[16*9];\
  1014. uint8_t halfH[72];\
  1015. copy_block9(full, src, 16, stride, 9);\
  1016. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1017. put ## RND ## pixels8_l2_8(halfH, halfH, full+1, 8, 8, 16, 9);\
  1018. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1019. }\
  1020. static void OPNAME ## qpel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  1021. uint8_t halfH[72];\
  1022. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1023. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1024. }\
  1025. \
  1026. static void OPNAME ## qpel16_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  1027. uint8_t half[256];\
  1028. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  1029. OPNAME ## pixels16_l2_8(dst, src, half, stride, stride, 16, 16);\
  1030. }\
  1031. \
  1032. static void OPNAME ## qpel16_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  1033. OPNAME ## mpeg4_qpel16_h_lowpass(dst, src, stride, stride, 16);\
  1034. }\
  1035. \
  1036. static void OPNAME ## qpel16_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  1037. uint8_t half[256];\
  1038. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  1039. OPNAME ## pixels16_l2_8(dst, src+1, half, stride, stride, 16, 16);\
  1040. }\
  1041. \
  1042. static void OPNAME ## qpel16_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  1043. uint8_t full[24*17];\
  1044. uint8_t half[256];\
  1045. copy_block17(full, src, 24, stride, 17);\
  1046. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
  1047. OPNAME ## pixels16_l2_8(dst, full, half, stride, 24, 16, 16);\
  1048. }\
  1049. \
  1050. static void OPNAME ## qpel16_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  1051. uint8_t full[24*17];\
  1052. copy_block17(full, src, 24, stride, 17);\
  1053. OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);\
  1054. }\
  1055. \
  1056. static void OPNAME ## qpel16_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  1057. uint8_t full[24*17];\
  1058. uint8_t half[256];\
  1059. copy_block17(full, src, 24, stride, 17);\
  1060. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
  1061. OPNAME ## pixels16_l2_8(dst, full+24, half, stride, 24, 16, 16);\
  1062. }\
  1063. void ff_ ## OPNAME ## qpel16_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1064. uint8_t full[24*17];\
  1065. uint8_t halfH[272];\
  1066. uint8_t halfV[256];\
  1067. uint8_t halfHV[256];\
  1068. copy_block17(full, src, 24, stride, 17);\
  1069. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1070. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1071. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1072. OPNAME ## pixels16_l4_8(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1073. }\
  1074. static void OPNAME ## qpel16_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  1075. uint8_t full[24*17];\
  1076. uint8_t halfH[272];\
  1077. uint8_t halfHV[256];\
  1078. copy_block17(full, src, 24, stride, 17);\
  1079. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1080. put ## RND ## pixels16_l2_8(halfH, halfH, full, 16, 16, 24, 17);\
  1081. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1082. OPNAME ## pixels16_l2_8(dst, halfH, halfHV, stride, 16, 16, 16);\
  1083. }\
  1084. void ff_ ## OPNAME ## qpel16_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1085. uint8_t full[24*17];\
  1086. uint8_t halfH[272];\
  1087. uint8_t halfV[256];\
  1088. uint8_t halfHV[256];\
  1089. copy_block17(full, src, 24, stride, 17);\
  1090. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1091. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1092. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1093. OPNAME ## pixels16_l4_8(dst, full+1, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1094. }\
  1095. static void OPNAME ## qpel16_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  1096. uint8_t full[24*17];\
  1097. uint8_t halfH[272];\
  1098. uint8_t halfHV[256];\
  1099. copy_block17(full, src, 24, stride, 17);\
  1100. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1101. put ## RND ## pixels16_l2_8(halfH, halfH, full+1, 16, 16, 24, 17);\
  1102. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1103. OPNAME ## pixels16_l2_8(dst, halfH, halfHV, stride, 16, 16, 16);\
  1104. }\
  1105. void ff_ ## OPNAME ## qpel16_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1106. uint8_t full[24*17];\
  1107. uint8_t halfH[272];\
  1108. uint8_t halfV[256];\
  1109. uint8_t halfHV[256];\
  1110. copy_block17(full, src, 24, stride, 17);\
  1111. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1112. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1113. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1114. OPNAME ## pixels16_l4_8(dst, full+24, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1115. }\
  1116. static void OPNAME ## qpel16_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  1117. uint8_t full[24*17];\
  1118. uint8_t halfH[272];\
  1119. uint8_t halfHV[256];\
  1120. copy_block17(full, src, 24, stride, 17);\
  1121. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1122. put ## RND ## pixels16_l2_8(halfH, halfH, full, 16, 16, 24, 17);\
  1123. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1124. OPNAME ## pixels16_l2_8(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1125. }\
  1126. void ff_ ## OPNAME ## qpel16_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1127. uint8_t full[24*17];\
  1128. uint8_t halfH[272];\
  1129. uint8_t halfV[256];\
  1130. uint8_t halfHV[256];\
  1131. copy_block17(full, src, 24, stride, 17);\
  1132. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full , 16, 24, 17);\
  1133. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1134. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1135. OPNAME ## pixels16_l4_8(dst, full+25, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1136. }\
  1137. static void OPNAME ## qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  1138. uint8_t full[24*17];\
  1139. uint8_t halfH[272];\
  1140. uint8_t halfHV[256];\
  1141. copy_block17(full, src, 24, stride, 17);\
  1142. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1143. put ## RND ## pixels16_l2_8(halfH, halfH, full+1, 16, 16, 24, 17);\
  1144. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1145. OPNAME ## pixels16_l2_8(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1146. }\
  1147. static void OPNAME ## qpel16_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  1148. uint8_t halfH[272];\
  1149. uint8_t halfHV[256];\
  1150. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1151. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1152. OPNAME ## pixels16_l2_8(dst, halfH, halfHV, stride, 16, 16, 16);\
  1153. }\
  1154. static void OPNAME ## qpel16_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  1155. uint8_t halfH[272];\
  1156. uint8_t halfHV[256];\
  1157. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1158. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1159. OPNAME ## pixels16_l2_8(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1160. }\
  1161. void ff_ ## OPNAME ## qpel16_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1162. uint8_t full[24*17];\
  1163. uint8_t halfH[272];\
  1164. uint8_t halfV[256];\
  1165. uint8_t halfHV[256];\
  1166. copy_block17(full, src, 24, stride, 17);\
  1167. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1168. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1169. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1170. OPNAME ## pixels16_l2_8(dst, halfV, halfHV, stride, 16, 16, 16);\
  1171. }\
  1172. static void OPNAME ## qpel16_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  1173. uint8_t full[24*17];\
  1174. uint8_t halfH[272];\
  1175. copy_block17(full, src, 24, stride, 17);\
  1176. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1177. put ## RND ## pixels16_l2_8(halfH, halfH, full, 16, 16, 24, 17);\
  1178. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1179. }\
  1180. void ff_ ## OPNAME ## qpel16_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1181. uint8_t full[24*17];\
  1182. uint8_t halfH[272];\
  1183. uint8_t halfV[256];\
  1184. uint8_t halfHV[256];\
  1185. copy_block17(full, src, 24, stride, 17);\
  1186. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1187. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1188. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1189. OPNAME ## pixels16_l2_8(dst, halfV, halfHV, stride, 16, 16, 16);\
  1190. }\
  1191. static void OPNAME ## qpel16_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  1192. uint8_t full[24*17];\
  1193. uint8_t halfH[272];\
  1194. copy_block17(full, src, 24, stride, 17);\
  1195. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1196. put ## RND ## pixels16_l2_8(halfH, halfH, full+1, 16, 16, 24, 17);\
  1197. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1198. }\
  1199. static void OPNAME ## qpel16_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  1200. uint8_t halfH[272];\
  1201. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1202. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1203. }
  1204. #define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
  1205. #define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1)
  1206. #define op_put(a, b) a = cm[((b) + 16)>>5]
  1207. #define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5]
  1208. QPEL_MC(0, put_ , _ , op_put)
  1209. QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd)
  1210. QPEL_MC(0, avg_ , _ , op_avg)
  1211. //QPEL_MC(1, avg_no_rnd , _ , op_avg)
  1212. #undef op_avg
  1213. #undef op_avg_no_rnd
  1214. #undef op_put
  1215. #undef op_put_no_rnd
  1216. #define put_qpel8_mc00_c ff_put_pixels8x8_c
  1217. #define avg_qpel8_mc00_c ff_avg_pixels8x8_c
  1218. #define put_qpel16_mc00_c ff_put_pixels16x16_c
  1219. #define avg_qpel16_mc00_c ff_avg_pixels16x16_c
  1220. #define put_no_rnd_qpel8_mc00_c ff_put_pixels8x8_c
  1221. #define put_no_rnd_qpel16_mc00_c ff_put_pixels16x16_8_c
  1222. static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){
  1223. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  1224. int i;
  1225. for(i=0; i<h; i++){
  1226. dst[0]= cm[(9*(src[0] + src[1]) - (src[-1] + src[2]) + 8)>>4];
  1227. dst[1]= cm[(9*(src[1] + src[2]) - (src[ 0] + src[3]) + 8)>>4];
  1228. dst[2]= cm[(9*(src[2] + src[3]) - (src[ 1] + src[4]) + 8)>>4];
  1229. dst[3]= cm[(9*(src[3] + src[4]) - (src[ 2] + src[5]) + 8)>>4];
  1230. dst[4]= cm[(9*(src[4] + src[5]) - (src[ 3] + src[6]) + 8)>>4];
  1231. dst[5]= cm[(9*(src[5] + src[6]) - (src[ 4] + src[7]) + 8)>>4];
  1232. dst[6]= cm[(9*(src[6] + src[7]) - (src[ 5] + src[8]) + 8)>>4];
  1233. dst[7]= cm[(9*(src[7] + src[8]) - (src[ 6] + src[9]) + 8)>>4];
  1234. dst+=dstStride;
  1235. src+=srcStride;
  1236. }
  1237. }
  1238. #if CONFIG_RV40_DECODER
  1239. static void put_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){
  1240. put_pixels16_xy2_8_c(dst, src, stride, 16);
  1241. }
  1242. static void avg_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){
  1243. avg_pixels16_xy2_8_c(dst, src, stride, 16);
  1244. }
  1245. static void put_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){
  1246. put_pixels8_xy2_8_c(dst, src, stride, 8);
  1247. }
  1248. static void avg_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){
  1249. avg_pixels8_xy2_8_c(dst, src, stride, 8);
  1250. }
  1251. #endif /* CONFIG_RV40_DECODER */
  1252. static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){
  1253. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  1254. int i;
  1255. for(i=0; i<w; i++){
  1256. const int src_1= src[ -srcStride];
  1257. const int src0 = src[0 ];
  1258. const int src1 = src[ srcStride];
  1259. const int src2 = src[2*srcStride];
  1260. const int src3 = src[3*srcStride];
  1261. const int src4 = src[4*srcStride];
  1262. const int src5 = src[5*srcStride];
  1263. const int src6 = src[6*srcStride];
  1264. const int src7 = src[7*srcStride];
  1265. const int src8 = src[8*srcStride];
  1266. const int src9 = src[9*srcStride];
  1267. dst[0*dstStride]= cm[(9*(src0 + src1) - (src_1 + src2) + 8)>>4];
  1268. dst[1*dstStride]= cm[(9*(src1 + src2) - (src0 + src3) + 8)>>4];
  1269. dst[2*dstStride]= cm[(9*(src2 + src3) - (src1 + src4) + 8)>>4];
  1270. dst[3*dstStride]= cm[(9*(src3 + src4) - (src2 + src5) + 8)>>4];
  1271. dst[4*dstStride]= cm[(9*(src4 + src5) - (src3 + src6) + 8)>>4];
  1272. dst[5*dstStride]= cm[(9*(src5 + src6) - (src4 + src7) + 8)>>4];
  1273. dst[6*dstStride]= cm[(9*(src6 + src7) - (src5 + src8) + 8)>>4];
  1274. dst[7*dstStride]= cm[(9*(src7 + src8) - (src6 + src9) + 8)>>4];
  1275. src++;
  1276. dst++;
  1277. }
  1278. }
  1279. static void put_mspel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){
  1280. uint8_t half[64];
  1281. wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
  1282. put_pixels8_l2_8(dst, src, half, stride, stride, 8, 8);
  1283. }
  1284. static void put_mspel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){
  1285. wmv2_mspel8_h_lowpass(dst, src, stride, stride, 8);
  1286. }
  1287. static void put_mspel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){
  1288. uint8_t half[64];
  1289. wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
  1290. put_pixels8_l2_8(dst, src+1, half, stride, stride, 8, 8);
  1291. }
  1292. static void put_mspel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){
  1293. wmv2_mspel8_v_lowpass(dst, src, stride, stride, 8);
  1294. }
  1295. static void put_mspel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){
  1296. uint8_t halfH[88];
  1297. uint8_t halfV[64];
  1298. uint8_t halfHV[64];
  1299. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  1300. wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8);
  1301. wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
  1302. put_pixels8_l2_8(dst, halfV, halfHV, stride, 8, 8, 8);
  1303. }
  1304. static void put_mspel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){
  1305. uint8_t halfH[88];
  1306. uint8_t halfV[64];
  1307. uint8_t halfHV[64];
  1308. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  1309. wmv2_mspel8_v_lowpass(halfV, src+1, 8, stride, 8);
  1310. wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
  1311. put_pixels8_l2_8(dst, halfV, halfHV, stride, 8, 8, 8);
  1312. }
  1313. static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){
  1314. uint8_t halfH[88];
  1315. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  1316. wmv2_mspel8_v_lowpass(dst, halfH+8, stride, 8, 8);
  1317. }
  1318. static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale){
  1319. if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
  1320. int x;
  1321. const int strength= ff_h263_loop_filter_strength[qscale];
  1322. for(x=0; x<8; x++){
  1323. int d1, d2, ad1;
  1324. int p0= src[x-2*stride];
  1325. int p1= src[x-1*stride];
  1326. int p2= src[x+0*stride];
  1327. int p3= src[x+1*stride];
  1328. int d = (p0 - p3 + 4*(p2 - p1)) / 8;
  1329. if (d<-2*strength) d1= 0;
  1330. else if(d<- strength) d1=-2*strength - d;
  1331. else if(d< strength) d1= d;
  1332. else if(d< 2*strength) d1= 2*strength - d;
  1333. else d1= 0;
  1334. p1 += d1;
  1335. p2 -= d1;
  1336. if(p1&256) p1= ~(p1>>31);
  1337. if(p2&256) p2= ~(p2>>31);
  1338. src[x-1*stride] = p1;
  1339. src[x+0*stride] = p2;
  1340. ad1= FFABS(d1)>>1;
  1341. d2= av_clip((p0-p3)/4, -ad1, ad1);
  1342. src[x-2*stride] = p0 - d2;
  1343. src[x+ stride] = p3 + d2;
  1344. }
  1345. }
  1346. }
  1347. static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale){
  1348. if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
  1349. int y;
  1350. const int strength= ff_h263_loop_filter_strength[qscale];
  1351. for(y=0; y<8; y++){
  1352. int d1, d2, ad1;
  1353. int p0= src[y*stride-2];
  1354. int p1= src[y*stride-1];
  1355. int p2= src[y*stride+0];
  1356. int p3= src[y*stride+1];
  1357. int d = (p0 - p3 + 4*(p2 - p1)) / 8;
  1358. if (d<-2*strength) d1= 0;
  1359. else if(d<- strength) d1=-2*strength - d;
  1360. else if(d< strength) d1= d;
  1361. else if(d< 2*strength) d1= 2*strength - d;
  1362. else d1= 0;
  1363. p1 += d1;
  1364. p2 -= d1;
  1365. if(p1&256) p1= ~(p1>>31);
  1366. if(p2&256) p2= ~(p2>>31);
  1367. src[y*stride-1] = p1;
  1368. src[y*stride+0] = p2;
  1369. ad1= FFABS(d1)>>1;
  1370. d2= av_clip((p0-p3)/4, -ad1, ad1);
  1371. src[y*stride-2] = p0 - d2;
  1372. src[y*stride+1] = p3 + d2;
  1373. }
  1374. }
  1375. }
  1376. static void h261_loop_filter_c(uint8_t *src, int stride){
  1377. int x,y,xy,yz;
  1378. int temp[64];
  1379. for(x=0; x<8; x++){
  1380. temp[x ] = 4*src[x ];
  1381. temp[x + 7*8] = 4*src[x + 7*stride];
  1382. }
  1383. for(y=1; y<7; y++){
  1384. for(x=0; x<8; x++){
  1385. xy = y * stride + x;
  1386. yz = y * 8 + x;
  1387. temp[yz] = src[xy - stride] + 2*src[xy] + src[xy + stride];
  1388. }
  1389. }
  1390. for(y=0; y<8; y++){
  1391. src[ y*stride] = (temp[ y*8] + 2)>>2;
  1392. src[7+y*stride] = (temp[7+y*8] + 2)>>2;
  1393. for(x=1; x<7; x++){
  1394. xy = y * stride + x;
  1395. yz = y * 8 + x;
  1396. src[xy] = (temp[yz-1] + 2*temp[yz] + temp[yz+1] + 8)>>4;
  1397. }
  1398. }
  1399. }
  1400. static inline int pix_abs16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1401. {
  1402. int s, i;
  1403. s = 0;
  1404. for(i=0;i<h;i++) {
  1405. s += abs(pix1[0] - pix2[0]);
  1406. s += abs(pix1[1] - pix2[1]);
  1407. s += abs(pix1[2] - pix2[2]);
  1408. s += abs(pix1[3] - pix2[3]);
  1409. s += abs(pix1[4] - pix2[4]);
  1410. s += abs(pix1[5] - pix2[5]);
  1411. s += abs(pix1[6] - pix2[6]);
  1412. s += abs(pix1[7] - pix2[7]);
  1413. s += abs(pix1[8] - pix2[8]);
  1414. s += abs(pix1[9] - pix2[9]);
  1415. s += abs(pix1[10] - pix2[10]);
  1416. s += abs(pix1[11] - pix2[11]);
  1417. s += abs(pix1[12] - pix2[12]);
  1418. s += abs(pix1[13] - pix2[13]);
  1419. s += abs(pix1[14] - pix2[14]);
  1420. s += abs(pix1[15] - pix2[15]);
  1421. pix1 += line_size;
  1422. pix2 += line_size;
  1423. }
  1424. return s;
  1425. }
  1426. static int pix_abs16_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1427. {
  1428. int s, i;
  1429. s = 0;
  1430. for(i=0;i<h;i++) {
  1431. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  1432. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  1433. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  1434. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  1435. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  1436. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  1437. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  1438. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  1439. s += abs(pix1[8] - avg2(pix2[8], pix2[9]));
  1440. s += abs(pix1[9] - avg2(pix2[9], pix2[10]));
  1441. s += abs(pix1[10] - avg2(pix2[10], pix2[11]));
  1442. s += abs(pix1[11] - avg2(pix2[11], pix2[12]));
  1443. s += abs(pix1[12] - avg2(pix2[12], pix2[13]));
  1444. s += abs(pix1[13] - avg2(pix2[13], pix2[14]));
  1445. s += abs(pix1[14] - avg2(pix2[14], pix2[15]));
  1446. s += abs(pix1[15] - avg2(pix2[15], pix2[16]));
  1447. pix1 += line_size;
  1448. pix2 += line_size;
  1449. }
  1450. return s;
  1451. }
  1452. static int pix_abs16_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1453. {
  1454. int s, i;
  1455. uint8_t *pix3 = pix2 + line_size;
  1456. s = 0;
  1457. for(i=0;i<h;i++) {
  1458. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  1459. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  1460. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  1461. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  1462. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  1463. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  1464. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  1465. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  1466. s += abs(pix1[8] - avg2(pix2[8], pix3[8]));
  1467. s += abs(pix1[9] - avg2(pix2[9], pix3[9]));
  1468. s += abs(pix1[10] - avg2(pix2[10], pix3[10]));
  1469. s += abs(pix1[11] - avg2(pix2[11], pix3[11]));
  1470. s += abs(pix1[12] - avg2(pix2[12], pix3[12]));
  1471. s += abs(pix1[13] - avg2(pix2[13], pix3[13]));
  1472. s += abs(pix1[14] - avg2(pix2[14], pix3[14]));
  1473. s += abs(pix1[15] - avg2(pix2[15], pix3[15]));
  1474. pix1 += line_size;
  1475. pix2 += line_size;
  1476. pix3 += line_size;
  1477. }
  1478. return s;
  1479. }
  1480. static int pix_abs16_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1481. {
  1482. int s, i;
  1483. uint8_t *pix3 = pix2 + line_size;
  1484. s = 0;
  1485. for(i=0;i<h;i++) {
  1486. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  1487. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  1488. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  1489. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  1490. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  1491. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  1492. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  1493. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  1494. s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9]));
  1495. s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10]));
  1496. s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11]));
  1497. s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12]));
  1498. s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13]));
  1499. s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14]));
  1500. s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15]));
  1501. s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16]));
  1502. pix1 += line_size;
  1503. pix2 += line_size;
  1504. pix3 += line_size;
  1505. }
  1506. return s;
  1507. }
  1508. static inline int pix_abs8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1509. {
  1510. int s, i;
  1511. s = 0;
  1512. for(i=0;i<h;i++) {
  1513. s += abs(pix1[0] - pix2[0]);
  1514. s += abs(pix1[1] - pix2[1]);
  1515. s += abs(pix1[2] - pix2[2]);
  1516. s += abs(pix1[3] - pix2[3]);
  1517. s += abs(pix1[4] - pix2[4]);
  1518. s += abs(pix1[5] - pix2[5]);
  1519. s += abs(pix1[6] - pix2[6]);
  1520. s += abs(pix1[7] - pix2[7]);
  1521. pix1 += line_size;
  1522. pix2 += line_size;
  1523. }
  1524. return s;
  1525. }
  1526. static int pix_abs8_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1527. {
  1528. int s, i;
  1529. s = 0;
  1530. for(i=0;i<h;i++) {
  1531. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  1532. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  1533. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  1534. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  1535. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  1536. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  1537. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  1538. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  1539. pix1 += line_size;
  1540. pix2 += line_size;
  1541. }
  1542. return s;
  1543. }
  1544. static int pix_abs8_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1545. {
  1546. int s, i;
  1547. uint8_t *pix3 = pix2 + line_size;
  1548. s = 0;
  1549. for(i=0;i<h;i++) {
  1550. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  1551. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  1552. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  1553. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  1554. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  1555. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  1556. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  1557. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  1558. pix1 += line_size;
  1559. pix2 += line_size;
  1560. pix3 += line_size;
  1561. }
  1562. return s;
  1563. }
  1564. static int pix_abs8_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  1565. {
  1566. int s, i;
  1567. uint8_t *pix3 = pix2 + line_size;
  1568. s = 0;
  1569. for(i=0;i<h;i++) {
  1570. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  1571. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  1572. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  1573. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  1574. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  1575. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  1576. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  1577. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  1578. pix1 += line_size;
  1579. pix2 += line_size;
  1580. pix3 += line_size;
  1581. }
  1582. return s;
  1583. }
  1584. static int nsse16_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
  1585. MpegEncContext *c = v;
  1586. int score1=0;
  1587. int score2=0;
  1588. int x,y;
  1589. for(y=0; y<h; y++){
  1590. for(x=0; x<16; x++){
  1591. score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
  1592. }
  1593. if(y+1<h){
  1594. for(x=0; x<15; x++){
  1595. score2+= FFABS( s1[x ] - s1[x +stride]
  1596. - s1[x+1] + s1[x+1+stride])
  1597. -FFABS( s2[x ] - s2[x +stride]
  1598. - s2[x+1] + s2[x+1+stride]);
  1599. }
  1600. }
  1601. s1+= stride;
  1602. s2+= stride;
  1603. }
  1604. if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
  1605. else return score1 + FFABS(score2)*8;
  1606. }
  1607. static int nsse8_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
  1608. MpegEncContext *c = v;
  1609. int score1=0;
  1610. int score2=0;
  1611. int x,y;
  1612. for(y=0; y<h; y++){
  1613. for(x=0; x<8; x++){
  1614. score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
  1615. }
  1616. if(y+1<h){
  1617. for(x=0; x<7; x++){
  1618. score2+= FFABS( s1[x ] - s1[x +stride]
  1619. - s1[x+1] + s1[x+1+stride])
  1620. -FFABS( s2[x ] - s2[x +stride]
  1621. - s2[x+1] + s2[x+1+stride]);
  1622. }
  1623. }
  1624. s1+= stride;
  1625. s2+= stride;
  1626. }
  1627. if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
  1628. else return score1 + FFABS(score2)*8;
  1629. }
  1630. static int try_8x8basis_c(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){
  1631. int i;
  1632. unsigned int sum=0;
  1633. for(i=0; i<8*8; i++){
  1634. int b= rem[i] + ((basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT));
  1635. int w= weight[i];
  1636. b>>= RECON_SHIFT;
  1637. assert(-512<b && b<512);
  1638. sum += (w*b)*(w*b)>>4;
  1639. }
  1640. return sum>>2;
  1641. }
  1642. static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale){
  1643. int i;
  1644. for(i=0; i<8*8; i++){
  1645. rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT);
  1646. }
  1647. }
  1648. /**
  1649. * permutes an 8x8 block.
  1650. * @param block the block which will be permuted according to the given permutation vector
  1651. * @param permutation the permutation vector
  1652. * @param last the last non zero coefficient in scantable order, used to speed the permutation up
  1653. * @param scantable the used scantable, this is only used to speed the permutation up, the block is not
  1654. * (inverse) permutated to scantable order!
  1655. */
  1656. void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last)
  1657. {
  1658. int i;
  1659. DCTELEM temp[64];
  1660. if(last<=0) return;
  1661. //if(permutation[1]==1) return; //FIXME it is ok but not clean and might fail for some permutations
  1662. for(i=0; i<=last; i++){
  1663. const int j= scantable[i];
  1664. temp[j]= block[j];
  1665. block[j]=0;
  1666. }
  1667. for(i=0; i<=last; i++){
  1668. const int j= scantable[i];
  1669. const int perm_j= permutation[j];
  1670. block[perm_j]= temp[j];
  1671. }
  1672. }
  1673. static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){
  1674. return 0;
  1675. }
  1676. void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){
  1677. int i;
  1678. memset(cmp, 0, sizeof(void*)*6);
  1679. for(i=0; i<6; i++){
  1680. switch(type&0xFF){
  1681. case FF_CMP_SAD:
  1682. cmp[i]= c->sad[i];
  1683. break;
  1684. case FF_CMP_SATD:
  1685. cmp[i]= c->hadamard8_diff[i];
  1686. break;
  1687. case FF_CMP_SSE:
  1688. cmp[i]= c->sse[i];
  1689. break;
  1690. case FF_CMP_DCT:
  1691. cmp[i]= c->dct_sad[i];
  1692. break;
  1693. case FF_CMP_DCT264:
  1694. cmp[i]= c->dct264_sad[i];
  1695. break;
  1696. case FF_CMP_DCTMAX:
  1697. cmp[i]= c->dct_max[i];
  1698. break;
  1699. case FF_CMP_PSNR:
  1700. cmp[i]= c->quant_psnr[i];
  1701. break;
  1702. case FF_CMP_BIT:
  1703. cmp[i]= c->bit[i];
  1704. break;
  1705. case FF_CMP_RD:
  1706. cmp[i]= c->rd[i];
  1707. break;
  1708. case FF_CMP_VSAD:
  1709. cmp[i]= c->vsad[i];
  1710. break;
  1711. case FF_CMP_VSSE:
  1712. cmp[i]= c->vsse[i];
  1713. break;
  1714. case FF_CMP_ZERO:
  1715. cmp[i]= zero_cmp;
  1716. break;
  1717. case FF_CMP_NSSE:
  1718. cmp[i]= c->nsse[i];
  1719. break;
  1720. #if CONFIG_DWT
  1721. case FF_CMP_W53:
  1722. cmp[i]= c->w53[i];
  1723. break;
  1724. case FF_CMP_W97:
  1725. cmp[i]= c->w97[i];
  1726. break;
  1727. #endif
  1728. default:
  1729. av_log(NULL, AV_LOG_ERROR,"internal error in cmp function selection\n");
  1730. }
  1731. }
  1732. }
  1733. static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){
  1734. long i;
  1735. for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
  1736. long a = *(long*)(src+i);
  1737. long b = *(long*)(dst+i);
  1738. *(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80);
  1739. }
  1740. for(; i<w; i++)
  1741. dst[i+0] += src[i+0];
  1742. }
  1743. static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
  1744. long i;
  1745. #if !HAVE_FAST_UNALIGNED
  1746. if((long)src2 & (sizeof(long)-1)){
  1747. for(i=0; i+7<w; i+=8){
  1748. dst[i+0] = src1[i+0]-src2[i+0];
  1749. dst[i+1] = src1[i+1]-src2[i+1];
  1750. dst[i+2] = src1[i+2]-src2[i+2];
  1751. dst[i+3] = src1[i+3]-src2[i+3];
  1752. dst[i+4] = src1[i+4]-src2[i+4];
  1753. dst[i+5] = src1[i+5]-src2[i+5];
  1754. dst[i+6] = src1[i+6]-src2[i+6];
  1755. dst[i+7] = src1[i+7]-src2[i+7];
  1756. }
  1757. }else
  1758. #endif
  1759. for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
  1760. long a = *(long*)(src1+i);
  1761. long b = *(long*)(src2+i);
  1762. *(long*)(dst+i) = ((a|pb_80) - (b&pb_7f)) ^ ((a^b^pb_80)&pb_80);
  1763. }
  1764. for(; i<w; i++)
  1765. dst[i+0] = src1[i+0]-src2[i+0];
  1766. }
  1767. static void add_hfyu_median_prediction_c(uint8_t *dst, const uint8_t *src1, const uint8_t *diff, int w, int *left, int *left_top){
  1768. int i;
  1769. uint8_t l, lt;
  1770. l= *left;
  1771. lt= *left_top;
  1772. for(i=0; i<w; i++){
  1773. l= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF) + diff[i];
  1774. lt= src1[i];
  1775. dst[i]= l;
  1776. }
  1777. *left= l;
  1778. *left_top= lt;
  1779. }
  1780. static void sub_hfyu_median_prediction_c(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top){
  1781. int i;
  1782. uint8_t l, lt;
  1783. l= *left;
  1784. lt= *left_top;
  1785. for(i=0; i<w; i++){
  1786. const int pred= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF);
  1787. lt= src1[i];
  1788. l= src2[i];
  1789. dst[i]= l - pred;
  1790. }
  1791. *left= l;
  1792. *left_top= lt;
  1793. }
  1794. static int add_hfyu_left_prediction_c(uint8_t *dst, const uint8_t *src, int w, int acc){
  1795. int i;
  1796. for(i=0; i<w-1; i++){
  1797. acc+= src[i];
  1798. dst[i]= acc;
  1799. i++;
  1800. acc+= src[i];
  1801. dst[i]= acc;
  1802. }
  1803. for(; i<w; i++){
  1804. acc+= src[i];
  1805. dst[i]= acc;
  1806. }
  1807. return acc;
  1808. }
  1809. #if HAVE_BIGENDIAN
  1810. #define B 3
  1811. #define G 2
  1812. #define R 1
  1813. #define A 0
  1814. #else
  1815. #define B 0
  1816. #define G 1
  1817. #define R 2
  1818. #define A 3
  1819. #endif
  1820. static void add_hfyu_left_prediction_bgr32_c(uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue, int *alpha){
  1821. int i;
  1822. int r,g,b,a;
  1823. r= *red;
  1824. g= *green;
  1825. b= *blue;
  1826. a= *alpha;
  1827. for(i=0; i<w; i++){
  1828. b+= src[4*i+B];
  1829. g+= src[4*i+G];
  1830. r+= src[4*i+R];
  1831. a+= src[4*i+A];
  1832. dst[4*i+B]= b;
  1833. dst[4*i+G]= g;
  1834. dst[4*i+R]= r;
  1835. dst[4*i+A]= a;
  1836. }
  1837. *red= r;
  1838. *green= g;
  1839. *blue= b;
  1840. *alpha= a;
  1841. }
  1842. #undef B
  1843. #undef G
  1844. #undef R
  1845. #undef A
  1846. #define BUTTERFLY2(o1,o2,i1,i2) \
  1847. o1= (i1)+(i2);\
  1848. o2= (i1)-(i2);
  1849. #define BUTTERFLY1(x,y) \
  1850. {\
  1851. int a,b;\
  1852. a= x;\
  1853. b= y;\
  1854. x= a+b;\
  1855. y= a-b;\
  1856. }
  1857. #define BUTTERFLYA(x,y) (FFABS((x)+(y)) + FFABS((x)-(y)))
  1858. static int hadamard8_diff8x8_c(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){
  1859. int i;
  1860. int temp[64];
  1861. int sum=0;
  1862. assert(h==8);
  1863. for(i=0; i<8; i++){
  1864. //FIXME try pointer walks
  1865. 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]);
  1866. 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]);
  1867. 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]);
  1868. 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]);
  1869. BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
  1870. BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
  1871. BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
  1872. BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
  1873. BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
  1874. BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
  1875. BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
  1876. BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
  1877. }
  1878. for(i=0; i<8; i++){
  1879. BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
  1880. BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
  1881. BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
  1882. BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
  1883. BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
  1884. BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
  1885. BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
  1886. BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
  1887. sum +=
  1888. BUTTERFLYA(temp[8*0+i], temp[8*4+i])
  1889. +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
  1890. +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
  1891. +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
  1892. }
  1893. return sum;
  1894. }
  1895. static int hadamard8_intra8x8_c(/*MpegEncContext*/ void *s, uint8_t *src, uint8_t *dummy, int stride, int h){
  1896. int i;
  1897. int temp[64];
  1898. int sum=0;
  1899. assert(h==8);
  1900. for(i=0; i<8; i++){
  1901. //FIXME try pointer walks
  1902. BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0],src[stride*i+1]);
  1903. BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2],src[stride*i+3]);
  1904. BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4],src[stride*i+5]);
  1905. BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6],src[stride*i+7]);
  1906. BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
  1907. BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
  1908. BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
  1909. BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
  1910. BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
  1911. BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
  1912. BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
  1913. BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
  1914. }
  1915. for(i=0; i<8; i++){
  1916. BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
  1917. BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
  1918. BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
  1919. BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
  1920. BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
  1921. BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
  1922. BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
  1923. BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
  1924. sum +=
  1925. BUTTERFLYA(temp[8*0+i], temp[8*4+i])
  1926. +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
  1927. +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
  1928. +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
  1929. }
  1930. sum -= FFABS(temp[8*0] + temp[8*4]); // -mean
  1931. return sum;
  1932. }
  1933. static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  1934. MpegEncContext * const s= (MpegEncContext *)c;
  1935. LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
  1936. assert(h==8);
  1937. s->dsp.diff_pixels(temp, src1, src2, stride);
  1938. s->dsp.fdct(temp);
  1939. return s->dsp.sum_abs_dctelem(temp);
  1940. }
  1941. #if CONFIG_GPL
  1942. #define DCT8_1D {\
  1943. const int s07 = SRC(0) + SRC(7);\
  1944. const int s16 = SRC(1) + SRC(6);\
  1945. const int s25 = SRC(2) + SRC(5);\
  1946. const int s34 = SRC(3) + SRC(4);\
  1947. const int a0 = s07 + s34;\
  1948. const int a1 = s16 + s25;\
  1949. const int a2 = s07 - s34;\
  1950. const int a3 = s16 - s25;\
  1951. const int d07 = SRC(0) - SRC(7);\
  1952. const int d16 = SRC(1) - SRC(6);\
  1953. const int d25 = SRC(2) - SRC(5);\
  1954. const int d34 = SRC(3) - SRC(4);\
  1955. const int a4 = d16 + d25 + (d07 + (d07>>1));\
  1956. const int a5 = d07 - d34 - (d25 + (d25>>1));\
  1957. const int a6 = d07 + d34 - (d16 + (d16>>1));\
  1958. const int a7 = d16 - d25 + (d34 + (d34>>1));\
  1959. DST(0, a0 + a1 ) ;\
  1960. DST(1, a4 + (a7>>2)) ;\
  1961. DST(2, a2 + (a3>>1)) ;\
  1962. DST(3, a5 + (a6>>2)) ;\
  1963. DST(4, a0 - a1 ) ;\
  1964. DST(5, a6 - (a5>>2)) ;\
  1965. DST(6, (a2>>1) - a3 ) ;\
  1966. DST(7, (a4>>2) - a7 ) ;\
  1967. }
  1968. static int dct264_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  1969. MpegEncContext * const s= (MpegEncContext *)c;
  1970. DCTELEM dct[8][8];
  1971. int i;
  1972. int sum=0;
  1973. s->dsp.diff_pixels(dct[0], src1, src2, stride);
  1974. #define SRC(x) dct[i][x]
  1975. #define DST(x,v) dct[i][x]= v
  1976. for( i = 0; i < 8; i++ )
  1977. DCT8_1D
  1978. #undef SRC
  1979. #undef DST
  1980. #define SRC(x) dct[x][i]
  1981. #define DST(x,v) sum += FFABS(v)
  1982. for( i = 0; i < 8; i++ )
  1983. DCT8_1D
  1984. #undef SRC
  1985. #undef DST
  1986. return sum;
  1987. }
  1988. #endif
  1989. static int dct_max8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  1990. MpegEncContext * const s= (MpegEncContext *)c;
  1991. LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
  1992. int sum=0, i;
  1993. assert(h==8);
  1994. s->dsp.diff_pixels(temp, src1, src2, stride);
  1995. s->dsp.fdct(temp);
  1996. for(i=0; i<64; i++)
  1997. sum= FFMAX(sum, FFABS(temp[i]));
  1998. return sum;
  1999. }
  2000. static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  2001. MpegEncContext * const s= (MpegEncContext *)c;
  2002. LOCAL_ALIGNED_16(DCTELEM, temp, [64*2]);
  2003. DCTELEM * const bak = temp+64;
  2004. int sum=0, i;
  2005. assert(h==8);
  2006. s->mb_intra=0;
  2007. s->dsp.diff_pixels(temp, src1, src2, stride);
  2008. memcpy(bak, temp, 64*sizeof(DCTELEM));
  2009. s->block_last_index[0/*FIXME*/]= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  2010. s->dct_unquantize_inter(s, temp, 0, s->qscale);
  2011. ff_simple_idct_8(temp); //FIXME
  2012. for(i=0; i<64; i++)
  2013. sum+= (temp[i]-bak[i])*(temp[i]-bak[i]);
  2014. return sum;
  2015. }
  2016. static int rd8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  2017. MpegEncContext * const s= (MpegEncContext *)c;
  2018. const uint8_t *scantable= s->intra_scantable.permutated;
  2019. LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
  2020. LOCAL_ALIGNED_16(uint8_t, lsrc1, [64]);
  2021. LOCAL_ALIGNED_16(uint8_t, lsrc2, [64]);
  2022. int i, last, run, bits, level, distortion, start_i;
  2023. const int esc_length= s->ac_esc_length;
  2024. uint8_t * length;
  2025. uint8_t * last_length;
  2026. assert(h==8);
  2027. copy_block8(lsrc1, src1, 8, stride, 8);
  2028. copy_block8(lsrc2, src2, 8, stride, 8);
  2029. s->dsp.diff_pixels(temp, lsrc1, lsrc2, 8);
  2030. s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  2031. bits=0;
  2032. if (s->mb_intra) {
  2033. start_i = 1;
  2034. length = s->intra_ac_vlc_length;
  2035. last_length= s->intra_ac_vlc_last_length;
  2036. bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
  2037. } else {
  2038. start_i = 0;
  2039. length = s->inter_ac_vlc_length;
  2040. last_length= s->inter_ac_vlc_last_length;
  2041. }
  2042. if(last>=start_i){
  2043. run=0;
  2044. for(i=start_i; i<last; i++){
  2045. int j= scantable[i];
  2046. level= temp[j];
  2047. if(level){
  2048. level+=64;
  2049. if((level&(~127)) == 0){
  2050. bits+= length[UNI_AC_ENC_INDEX(run, level)];
  2051. }else
  2052. bits+= esc_length;
  2053. run=0;
  2054. }else
  2055. run++;
  2056. }
  2057. i= scantable[last];
  2058. level= temp[i] + 64;
  2059. assert(level - 64);
  2060. if((level&(~127)) == 0){
  2061. bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
  2062. }else
  2063. bits+= esc_length;
  2064. }
  2065. if(last>=0){
  2066. if(s->mb_intra)
  2067. s->dct_unquantize_intra(s, temp, 0, s->qscale);
  2068. else
  2069. s->dct_unquantize_inter(s, temp, 0, s->qscale);
  2070. }
  2071. s->dsp.idct_add(lsrc2, 8, temp);
  2072. distortion= s->dsp.sse[1](NULL, lsrc2, lsrc1, 8, 8);
  2073. return distortion + ((bits*s->qscale*s->qscale*109 + 64)>>7);
  2074. }
  2075. static int bit8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  2076. MpegEncContext * const s= (MpegEncContext *)c;
  2077. const uint8_t *scantable= s->intra_scantable.permutated;
  2078. LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
  2079. int i, last, run, bits, level, start_i;
  2080. const int esc_length= s->ac_esc_length;
  2081. uint8_t * length;
  2082. uint8_t * last_length;
  2083. assert(h==8);
  2084. s->dsp.diff_pixels(temp, src1, src2, stride);
  2085. s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  2086. bits=0;
  2087. if (s->mb_intra) {
  2088. start_i = 1;
  2089. length = s->intra_ac_vlc_length;
  2090. last_length= s->intra_ac_vlc_last_length;
  2091. bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
  2092. } else {
  2093. start_i = 0;
  2094. length = s->inter_ac_vlc_length;
  2095. last_length= s->inter_ac_vlc_last_length;
  2096. }
  2097. if(last>=start_i){
  2098. run=0;
  2099. for(i=start_i; i<last; i++){
  2100. int j= scantable[i];
  2101. level= temp[j];
  2102. if(level){
  2103. level+=64;
  2104. if((level&(~127)) == 0){
  2105. bits+= length[UNI_AC_ENC_INDEX(run, level)];
  2106. }else
  2107. bits+= esc_length;
  2108. run=0;
  2109. }else
  2110. run++;
  2111. }
  2112. i= scantable[last];
  2113. level= temp[i] + 64;
  2114. assert(level - 64);
  2115. if((level&(~127)) == 0){
  2116. bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
  2117. }else
  2118. bits+= esc_length;
  2119. }
  2120. return bits;
  2121. }
  2122. #define VSAD_INTRA(size) \
  2123. static int vsad_intra##size##_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){ \
  2124. int score=0; \
  2125. int x,y; \
  2126. \
  2127. for(y=1; y<h; y++){ \
  2128. for(x=0; x<size; x+=4){ \
  2129. score+= FFABS(s[x ] - s[x +stride]) + FFABS(s[x+1] - s[x+1+stride]) \
  2130. +FFABS(s[x+2] - s[x+2+stride]) + FFABS(s[x+3] - s[x+3+stride]); \
  2131. } \
  2132. s+= stride; \
  2133. } \
  2134. \
  2135. return score; \
  2136. }
  2137. VSAD_INTRA(8)
  2138. VSAD_INTRA(16)
  2139. static int vsad16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
  2140. int score=0;
  2141. int x,y;
  2142. for(y=1; y<h; y++){
  2143. for(x=0; x<16; x++){
  2144. score+= FFABS(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
  2145. }
  2146. s1+= stride;
  2147. s2+= stride;
  2148. }
  2149. return score;
  2150. }
  2151. #define SQ(a) ((a)*(a))
  2152. #define VSSE_INTRA(size) \
  2153. static int vsse_intra##size##_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){ \
  2154. int score=0; \
  2155. int x,y; \
  2156. \
  2157. for(y=1; y<h; y++){ \
  2158. for(x=0; x<size; x+=4){ \
  2159. score+= SQ(s[x ] - s[x +stride]) + SQ(s[x+1] - s[x+1+stride]) \
  2160. +SQ(s[x+2] - s[x+2+stride]) + SQ(s[x+3] - s[x+3+stride]); \
  2161. } \
  2162. s+= stride; \
  2163. } \
  2164. \
  2165. return score; \
  2166. }
  2167. VSSE_INTRA(8)
  2168. VSSE_INTRA(16)
  2169. static int vsse16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
  2170. int score=0;
  2171. int x,y;
  2172. for(y=1; y<h; y++){
  2173. for(x=0; x<16; x++){
  2174. score+= SQ(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
  2175. }
  2176. s1+= stride;
  2177. s2+= stride;
  2178. }
  2179. return score;
  2180. }
  2181. static int ssd_int8_vs_int16_c(const int8_t *pix1, const int16_t *pix2,
  2182. int size){
  2183. int score=0;
  2184. int i;
  2185. for(i=0; i<size; i++)
  2186. score += (pix1[i]-pix2[i])*(pix1[i]-pix2[i]);
  2187. return score;
  2188. }
  2189. WRAPPER8_16_SQ(hadamard8_diff8x8_c, hadamard8_diff16_c)
  2190. WRAPPER8_16_SQ(hadamard8_intra8x8_c, hadamard8_intra16_c)
  2191. WRAPPER8_16_SQ(dct_sad8x8_c, dct_sad16_c)
  2192. #if CONFIG_GPL
  2193. WRAPPER8_16_SQ(dct264_sad8x8_c, dct264_sad16_c)
  2194. #endif
  2195. WRAPPER8_16_SQ(dct_max8x8_c, dct_max16_c)
  2196. WRAPPER8_16_SQ(quant_psnr8x8_c, quant_psnr16_c)
  2197. WRAPPER8_16_SQ(rd8x8_c, rd16_c)
  2198. WRAPPER8_16_SQ(bit8x8_c, bit16_c)
  2199. static void vector_fmul_c(float *dst, const float *src0, const float *src1, int len){
  2200. int i;
  2201. for(i=0; i<len; i++)
  2202. dst[i] = src0[i] * src1[i];
  2203. }
  2204. static void vector_fmul_reverse_c(float *dst, const float *src0, const float *src1, int len){
  2205. int i;
  2206. src1 += len-1;
  2207. for(i=0; i<len; i++)
  2208. dst[i] = src0[i] * src1[-i];
  2209. }
  2210. static void vector_fmul_add_c(float *dst, const float *src0, const float *src1, const float *src2, int len){
  2211. int i;
  2212. for(i=0; i<len; i++)
  2213. dst[i] = src0[i] * src1[i] + src2[i];
  2214. }
  2215. static void vector_fmul_window_c(float *dst, const float *src0,
  2216. const float *src1, const float *win, int len)
  2217. {
  2218. int i,j;
  2219. dst += len;
  2220. win += len;
  2221. src0+= len;
  2222. for(i=-len, j=len-1; i<0; i++, j--) {
  2223. float s0 = src0[i];
  2224. float s1 = src1[j];
  2225. float wi = win[i];
  2226. float wj = win[j];
  2227. dst[i] = s0*wj - s1*wi;
  2228. dst[j] = s0*wi + s1*wj;
  2229. }
  2230. }
  2231. static void vector_fmul_scalar_c(float *dst, const float *src, float mul,
  2232. int len)
  2233. {
  2234. int i;
  2235. for (i = 0; i < len; i++)
  2236. dst[i] = src[i] * mul;
  2237. }
  2238. static void vector_fmul_sv_scalar_2_c(float *dst, const float *src,
  2239. const float **sv, float mul, int len)
  2240. {
  2241. int i;
  2242. for (i = 0; i < len; i += 2, sv++) {
  2243. dst[i ] = src[i ] * sv[0][0] * mul;
  2244. dst[i+1] = src[i+1] * sv[0][1] * mul;
  2245. }
  2246. }
  2247. static void vector_fmul_sv_scalar_4_c(float *dst, const float *src,
  2248. const float **sv, float mul, int len)
  2249. {
  2250. int i;
  2251. for (i = 0; i < len; i += 4, sv++) {
  2252. dst[i ] = src[i ] * sv[0][0] * mul;
  2253. dst[i+1] = src[i+1] * sv[0][1] * mul;
  2254. dst[i+2] = src[i+2] * sv[0][2] * mul;
  2255. dst[i+3] = src[i+3] * sv[0][3] * mul;
  2256. }
  2257. }
  2258. static void sv_fmul_scalar_2_c(float *dst, const float **sv, float mul,
  2259. int len)
  2260. {
  2261. int i;
  2262. for (i = 0; i < len; i += 2, sv++) {
  2263. dst[i ] = sv[0][0] * mul;
  2264. dst[i+1] = sv[0][1] * mul;
  2265. }
  2266. }
  2267. static void sv_fmul_scalar_4_c(float *dst, const float **sv, float mul,
  2268. int len)
  2269. {
  2270. int i;
  2271. for (i = 0; i < len; i += 4, sv++) {
  2272. dst[i ] = sv[0][0] * mul;
  2273. dst[i+1] = sv[0][1] * mul;
  2274. dst[i+2] = sv[0][2] * mul;
  2275. dst[i+3] = sv[0][3] * mul;
  2276. }
  2277. }
  2278. static void butterflies_float_c(float *restrict v1, float *restrict v2,
  2279. int len)
  2280. {
  2281. int i;
  2282. for (i = 0; i < len; i++) {
  2283. float t = v1[i] - v2[i];
  2284. v1[i] += v2[i];
  2285. v2[i] = t;
  2286. }
  2287. }
  2288. static float scalarproduct_float_c(const float *v1, const float *v2, int len)
  2289. {
  2290. float p = 0.0;
  2291. int i;
  2292. for (i = 0; i < len; i++)
  2293. p += v1[i] * v2[i];
  2294. return p;
  2295. }
  2296. static inline uint32_t clipf_c_one(uint32_t a, uint32_t mini,
  2297. uint32_t maxi, uint32_t maxisign)
  2298. {
  2299. if(a > mini) return mini;
  2300. else if((a^(1U<<31)) > maxisign) return maxi;
  2301. else return a;
  2302. }
  2303. static void vector_clipf_c_opposite_sign(float *dst, const float *src, float *min, float *max, int len){
  2304. int i;
  2305. uint32_t mini = *(uint32_t*)min;
  2306. uint32_t maxi = *(uint32_t*)max;
  2307. uint32_t maxisign = maxi ^ (1U<<31);
  2308. uint32_t *dsti = (uint32_t*)dst;
  2309. const uint32_t *srci = (const uint32_t*)src;
  2310. for(i=0; i<len; i+=8) {
  2311. dsti[i + 0] = clipf_c_one(srci[i + 0], mini, maxi, maxisign);
  2312. dsti[i + 1] = clipf_c_one(srci[i + 1], mini, maxi, maxisign);
  2313. dsti[i + 2] = clipf_c_one(srci[i + 2], mini, maxi, maxisign);
  2314. dsti[i + 3] = clipf_c_one(srci[i + 3], mini, maxi, maxisign);
  2315. dsti[i + 4] = clipf_c_one(srci[i + 4], mini, maxi, maxisign);
  2316. dsti[i + 5] = clipf_c_one(srci[i + 5], mini, maxi, maxisign);
  2317. dsti[i + 6] = clipf_c_one(srci[i + 6], mini, maxi, maxisign);
  2318. dsti[i + 7] = clipf_c_one(srci[i + 7], mini, maxi, maxisign);
  2319. }
  2320. }
  2321. static void vector_clipf_c(float *dst, const float *src, float min, float max, int len){
  2322. int i;
  2323. if(min < 0 && max > 0) {
  2324. vector_clipf_c_opposite_sign(dst, src, &min, &max, len);
  2325. } else {
  2326. for(i=0; i < len; i+=8) {
  2327. dst[i ] = av_clipf(src[i ], min, max);
  2328. dst[i + 1] = av_clipf(src[i + 1], min, max);
  2329. dst[i + 2] = av_clipf(src[i + 2], min, max);
  2330. dst[i + 3] = av_clipf(src[i + 3], min, max);
  2331. dst[i + 4] = av_clipf(src[i + 4], min, max);
  2332. dst[i + 5] = av_clipf(src[i + 5], min, max);
  2333. dst[i + 6] = av_clipf(src[i + 6], min, max);
  2334. dst[i + 7] = av_clipf(src[i + 7], min, max);
  2335. }
  2336. }
  2337. }
  2338. static int32_t scalarproduct_int16_c(const int16_t * v1, const int16_t * v2, int order, int shift)
  2339. {
  2340. int res = 0;
  2341. while (order--)
  2342. res += (*v1++ * *v2++) >> shift;
  2343. return res;
  2344. }
  2345. static int32_t scalarproduct_and_madd_int16_c(int16_t *v1, const int16_t *v2, const int16_t *v3, int order, int mul)
  2346. {
  2347. int res = 0;
  2348. while (order--) {
  2349. res += *v1 * *v2++;
  2350. *v1++ += mul * *v3++;
  2351. }
  2352. return res;
  2353. }
  2354. static void apply_window_int16_c(int16_t *output, const int16_t *input,
  2355. const int16_t *window, unsigned int len)
  2356. {
  2357. int i;
  2358. int len2 = len >> 1;
  2359. for (i = 0; i < len2; i++) {
  2360. int16_t w = window[i];
  2361. output[i] = (MUL16(input[i], w) + (1 << 14)) >> 15;
  2362. output[len-i-1] = (MUL16(input[len-i-1], w) + (1 << 14)) >> 15;
  2363. }
  2364. }
  2365. static void vector_clip_int32_c(int32_t *dst, const int32_t *src, int32_t min,
  2366. int32_t max, unsigned int len)
  2367. {
  2368. do {
  2369. *dst++ = av_clip(*src++, min, max);
  2370. *dst++ = av_clip(*src++, min, max);
  2371. *dst++ = av_clip(*src++, min, max);
  2372. *dst++ = av_clip(*src++, min, max);
  2373. *dst++ = av_clip(*src++, min, max);
  2374. *dst++ = av_clip(*src++, min, max);
  2375. *dst++ = av_clip(*src++, min, max);
  2376. *dst++ = av_clip(*src++, min, max);
  2377. len -= 8;
  2378. } while (len > 0);
  2379. }
  2380. #define W0 2048
  2381. #define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */
  2382. #define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */
  2383. #define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */
  2384. #define W4 2048 /* 2048*sqrt (2)*cos (4*pi/16) */
  2385. #define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */
  2386. #define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */
  2387. #define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */
  2388. static void wmv2_idct_row(short * b)
  2389. {
  2390. int s1,s2;
  2391. int a0,a1,a2,a3,a4,a5,a6,a7;
  2392. /*step 1*/
  2393. a1 = W1*b[1]+W7*b[7];
  2394. a7 = W7*b[1]-W1*b[7];
  2395. a5 = W5*b[5]+W3*b[3];
  2396. a3 = W3*b[5]-W5*b[3];
  2397. a2 = W2*b[2]+W6*b[6];
  2398. a6 = W6*b[2]-W2*b[6];
  2399. a0 = W0*b[0]+W0*b[4];
  2400. a4 = W0*b[0]-W0*b[4];
  2401. /*step 2*/
  2402. s1 = (181*(a1-a5+a7-a3)+128)>>8;//1,3,5,7,
  2403. s2 = (181*(a1-a5-a7+a3)+128)>>8;
  2404. /*step 3*/
  2405. b[0] = (a0+a2+a1+a5 + (1<<7))>>8;
  2406. b[1] = (a4+a6 +s1 + (1<<7))>>8;
  2407. b[2] = (a4-a6 +s2 + (1<<7))>>8;
  2408. b[3] = (a0-a2+a7+a3 + (1<<7))>>8;
  2409. b[4] = (a0-a2-a7-a3 + (1<<7))>>8;
  2410. b[5] = (a4-a6 -s2 + (1<<7))>>8;
  2411. b[6] = (a4+a6 -s1 + (1<<7))>>8;
  2412. b[7] = (a0+a2-a1-a5 + (1<<7))>>8;
  2413. }
  2414. static void wmv2_idct_col(short * b)
  2415. {
  2416. int s1,s2;
  2417. int a0,a1,a2,a3,a4,a5,a6,a7;
  2418. /*step 1, with extended precision*/
  2419. a1 = (W1*b[8*1]+W7*b[8*7] + 4)>>3;
  2420. a7 = (W7*b[8*1]-W1*b[8*7] + 4)>>3;
  2421. a5 = (W5*b[8*5]+W3*b[8*3] + 4)>>3;
  2422. a3 = (W3*b[8*5]-W5*b[8*3] + 4)>>3;
  2423. a2 = (W2*b[8*2]+W6*b[8*6] + 4)>>3;
  2424. a6 = (W6*b[8*2]-W2*b[8*6] + 4)>>3;
  2425. a0 = (W0*b[8*0]+W0*b[8*4] )>>3;
  2426. a4 = (W0*b[8*0]-W0*b[8*4] )>>3;
  2427. /*step 2*/
  2428. s1 = (181*(a1-a5+a7-a3)+128)>>8;
  2429. s2 = (181*(a1-a5-a7+a3)+128)>>8;
  2430. /*step 3*/
  2431. b[8*0] = (a0+a2+a1+a5 + (1<<13))>>14;
  2432. b[8*1] = (a4+a6 +s1 + (1<<13))>>14;
  2433. b[8*2] = (a4-a6 +s2 + (1<<13))>>14;
  2434. b[8*3] = (a0-a2+a7+a3 + (1<<13))>>14;
  2435. b[8*4] = (a0-a2-a7-a3 + (1<<13))>>14;
  2436. b[8*5] = (a4-a6 -s2 + (1<<13))>>14;
  2437. b[8*6] = (a4+a6 -s1 + (1<<13))>>14;
  2438. b[8*7] = (a0+a2-a1-a5 + (1<<13))>>14;
  2439. }
  2440. void ff_wmv2_idct_c(short * block){
  2441. int i;
  2442. for(i=0;i<64;i+=8){
  2443. wmv2_idct_row(block+i);
  2444. }
  2445. for(i=0;i<8;i++){
  2446. wmv2_idct_col(block+i);
  2447. }
  2448. }
  2449. /* XXX: those functions should be suppressed ASAP when all IDCTs are
  2450. converted */
  2451. static void ff_wmv2_idct_put_c(uint8_t *dest, int line_size, DCTELEM *block)
  2452. {
  2453. ff_wmv2_idct_c(block);
  2454. ff_put_pixels_clamped_c(block, dest, line_size);
  2455. }
  2456. static void ff_wmv2_idct_add_c(uint8_t *dest, int line_size, DCTELEM *block)
  2457. {
  2458. ff_wmv2_idct_c(block);
  2459. ff_add_pixels_clamped_c(block, dest, line_size);
  2460. }
  2461. static void ff_jref_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
  2462. {
  2463. j_rev_dct (block);
  2464. ff_put_pixels_clamped_c(block, dest, line_size);
  2465. }
  2466. static void ff_jref_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
  2467. {
  2468. j_rev_dct (block);
  2469. ff_add_pixels_clamped_c(block, dest, line_size);
  2470. }
  2471. static void ff_jref_idct4_put(uint8_t *dest, int line_size, DCTELEM *block)
  2472. {
  2473. j_rev_dct4 (block);
  2474. put_pixels_clamped4_c(block, dest, line_size);
  2475. }
  2476. static void ff_jref_idct4_add(uint8_t *dest, int line_size, DCTELEM *block)
  2477. {
  2478. j_rev_dct4 (block);
  2479. add_pixels_clamped4_c(block, dest, line_size);
  2480. }
  2481. static void ff_jref_idct2_put(uint8_t *dest, int line_size, DCTELEM *block)
  2482. {
  2483. j_rev_dct2 (block);
  2484. put_pixels_clamped2_c(block, dest, line_size);
  2485. }
  2486. static void ff_jref_idct2_add(uint8_t *dest, int line_size, DCTELEM *block)
  2487. {
  2488. j_rev_dct2 (block);
  2489. add_pixels_clamped2_c(block, dest, line_size);
  2490. }
  2491. static void ff_jref_idct1_put(uint8_t *dest, int line_size, DCTELEM *block)
  2492. {
  2493. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  2494. dest[0] = cm[(block[0] + 4)>>3];
  2495. }
  2496. static void ff_jref_idct1_add(uint8_t *dest, int line_size, DCTELEM *block)
  2497. {
  2498. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  2499. dest[0] = cm[dest[0] + ((block[0] + 4)>>3)];
  2500. }
  2501. static void just_return(void *mem av_unused, int stride av_unused, int h av_unused) { return; }
  2502. /* init static data */
  2503. av_cold void dsputil_static_init(void)
  2504. {
  2505. int i;
  2506. for(i=0;i<256;i++) ff_cropTbl[i + MAX_NEG_CROP] = i;
  2507. for(i=0;i<MAX_NEG_CROP;i++) {
  2508. ff_cropTbl[i] = 0;
  2509. ff_cropTbl[i + MAX_NEG_CROP + 256] = 255;
  2510. }
  2511. for(i=0;i<512;i++) {
  2512. ff_squareTbl[i] = (i - 256) * (i - 256);
  2513. }
  2514. for(i=0; i<64; i++) inv_zigzag_direct16[ff_zigzag_direct[i]]= i+1;
  2515. }
  2516. int ff_check_alignment(void){
  2517. static int did_fail=0;
  2518. LOCAL_ALIGNED_16(int, aligned, [4]);
  2519. if((intptr_t)aligned & 15){
  2520. if(!did_fail){
  2521. #if HAVE_MMX || HAVE_ALTIVEC
  2522. av_log(NULL, AV_LOG_ERROR,
  2523. "Compiler did not align stack variables. Libavcodec has been miscompiled\n"
  2524. "and may be very slow or crash. This is not a bug in libavcodec,\n"
  2525. "but in the compiler. You may try recompiling using gcc >= 4.2.\n"
  2526. "Do not report crashes to FFmpeg developers.\n");
  2527. #endif
  2528. did_fail=1;
  2529. }
  2530. return -1;
  2531. }
  2532. return 0;
  2533. }
  2534. av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx)
  2535. {
  2536. int i;
  2537. ff_check_alignment();
  2538. #if CONFIG_ENCODERS
  2539. if(avctx->dct_algo==FF_DCT_FASTINT) {
  2540. c->fdct = fdct_ifast;
  2541. c->fdct248 = fdct_ifast248;
  2542. }
  2543. else if(avctx->dct_algo==FF_DCT_FAAN) {
  2544. c->fdct = ff_faandct;
  2545. c->fdct248 = ff_faandct248;
  2546. }
  2547. else {
  2548. c->fdct = ff_jpeg_fdct_islow; //slow/accurate/default
  2549. c->fdct248 = ff_fdct248_islow;
  2550. }
  2551. #endif //CONFIG_ENCODERS
  2552. if(avctx->lowres==1){
  2553. c->idct_put= ff_jref_idct4_put;
  2554. c->idct_add= ff_jref_idct4_add;
  2555. c->idct = j_rev_dct4;
  2556. c->idct_permutation_type= FF_NO_IDCT_PERM;
  2557. }else if(avctx->lowres==2){
  2558. c->idct_put= ff_jref_idct2_put;
  2559. c->idct_add= ff_jref_idct2_add;
  2560. c->idct = j_rev_dct2;
  2561. c->idct_permutation_type= FF_NO_IDCT_PERM;
  2562. }else if(avctx->lowres==3){
  2563. c->idct_put= ff_jref_idct1_put;
  2564. c->idct_add= ff_jref_idct1_add;
  2565. c->idct = j_rev_dct1;
  2566. c->idct_permutation_type= FF_NO_IDCT_PERM;
  2567. }else{
  2568. if (avctx->bits_per_raw_sample == 10) {
  2569. c->idct_put = ff_simple_idct_put_10;
  2570. c->idct_add = ff_simple_idct_add_10;
  2571. c->idct = ff_simple_idct_10;
  2572. c->idct_permutation_type = FF_NO_IDCT_PERM;
  2573. } else {
  2574. if(avctx->idct_algo==FF_IDCT_INT){
  2575. c->idct_put= ff_jref_idct_put;
  2576. c->idct_add= ff_jref_idct_add;
  2577. c->idct = j_rev_dct;
  2578. c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
  2579. }else if((CONFIG_VP3_DECODER || CONFIG_VP5_DECODER || CONFIG_VP6_DECODER ) &&
  2580. avctx->idct_algo==FF_IDCT_VP3){
  2581. c->idct_put= ff_vp3_idct_put_c;
  2582. c->idct_add= ff_vp3_idct_add_c;
  2583. c->idct = ff_vp3_idct_c;
  2584. c->idct_permutation_type= FF_NO_IDCT_PERM;
  2585. }else if(avctx->idct_algo==FF_IDCT_WMV2){
  2586. c->idct_put= ff_wmv2_idct_put_c;
  2587. c->idct_add= ff_wmv2_idct_add_c;
  2588. c->idct = ff_wmv2_idct_c;
  2589. c->idct_permutation_type= FF_NO_IDCT_PERM;
  2590. }else if(avctx->idct_algo==FF_IDCT_FAAN){
  2591. c->idct_put= ff_faanidct_put;
  2592. c->idct_add= ff_faanidct_add;
  2593. c->idct = ff_faanidct;
  2594. c->idct_permutation_type= FF_NO_IDCT_PERM;
  2595. }else if(CONFIG_EATGQ_DECODER && avctx->idct_algo==FF_IDCT_EA) {
  2596. c->idct_put= ff_ea_idct_put_c;
  2597. c->idct_permutation_type= FF_NO_IDCT_PERM;
  2598. }else if(CONFIG_BINK_DECODER && avctx->idct_algo==FF_IDCT_BINK) {
  2599. c->idct = ff_bink_idct_c;
  2600. c->idct_add = ff_bink_idct_add_c;
  2601. c->idct_put = ff_bink_idct_put_c;
  2602. c->idct_permutation_type = FF_NO_IDCT_PERM;
  2603. }else{ //accurate/default
  2604. c->idct_put = ff_simple_idct_put_8;
  2605. c->idct_add = ff_simple_idct_add_8;
  2606. c->idct = ff_simple_idct_8;
  2607. c->idct_permutation_type= FF_NO_IDCT_PERM;
  2608. }
  2609. }
  2610. }
  2611. c->get_pixels = get_pixels_c;
  2612. c->diff_pixels = diff_pixels_c;
  2613. c->put_pixels_clamped = ff_put_pixels_clamped_c;
  2614. c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_c;
  2615. c->put_pixels_nonclamped = put_pixels_nonclamped_c;
  2616. c->add_pixels_clamped = ff_add_pixels_clamped_c;
  2617. c->sum_abs_dctelem = sum_abs_dctelem_c;
  2618. c->gmc1 = gmc1_c;
  2619. c->gmc = ff_gmc_c;
  2620. c->pix_sum = pix_sum_c;
  2621. c->pix_norm1 = pix_norm1_c;
  2622. c->fill_block_tab[0] = fill_block16_c;
  2623. c->fill_block_tab[1] = fill_block8_c;
  2624. c->scale_block = scale_block_c;
  2625. /* TODO [0] 16 [1] 8 */
  2626. c->pix_abs[0][0] = pix_abs16_c;
  2627. c->pix_abs[0][1] = pix_abs16_x2_c;
  2628. c->pix_abs[0][2] = pix_abs16_y2_c;
  2629. c->pix_abs[0][3] = pix_abs16_xy2_c;
  2630. c->pix_abs[1][0] = pix_abs8_c;
  2631. c->pix_abs[1][1] = pix_abs8_x2_c;
  2632. c->pix_abs[1][2] = pix_abs8_y2_c;
  2633. c->pix_abs[1][3] = pix_abs8_xy2_c;
  2634. c->put_tpel_pixels_tab[ 0] = put_tpel_pixels_mc00_c;
  2635. c->put_tpel_pixels_tab[ 1] = put_tpel_pixels_mc10_c;
  2636. c->put_tpel_pixels_tab[ 2] = put_tpel_pixels_mc20_c;
  2637. c->put_tpel_pixels_tab[ 4] = put_tpel_pixels_mc01_c;
  2638. c->put_tpel_pixels_tab[ 5] = put_tpel_pixels_mc11_c;
  2639. c->put_tpel_pixels_tab[ 6] = put_tpel_pixels_mc21_c;
  2640. c->put_tpel_pixels_tab[ 8] = put_tpel_pixels_mc02_c;
  2641. c->put_tpel_pixels_tab[ 9] = put_tpel_pixels_mc12_c;
  2642. c->put_tpel_pixels_tab[10] = put_tpel_pixels_mc22_c;
  2643. c->avg_tpel_pixels_tab[ 0] = avg_tpel_pixels_mc00_c;
  2644. c->avg_tpel_pixels_tab[ 1] = avg_tpel_pixels_mc10_c;
  2645. c->avg_tpel_pixels_tab[ 2] = avg_tpel_pixels_mc20_c;
  2646. c->avg_tpel_pixels_tab[ 4] = avg_tpel_pixels_mc01_c;
  2647. c->avg_tpel_pixels_tab[ 5] = avg_tpel_pixels_mc11_c;
  2648. c->avg_tpel_pixels_tab[ 6] = avg_tpel_pixels_mc21_c;
  2649. c->avg_tpel_pixels_tab[ 8] = avg_tpel_pixels_mc02_c;
  2650. c->avg_tpel_pixels_tab[ 9] = avg_tpel_pixels_mc12_c;
  2651. c->avg_tpel_pixels_tab[10] = avg_tpel_pixels_mc22_c;
  2652. #define dspfunc(PFX, IDX, NUM) \
  2653. c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \
  2654. c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \
  2655. c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \
  2656. c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \
  2657. c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \
  2658. c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \
  2659. c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \
  2660. c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \
  2661. c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \
  2662. c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \
  2663. c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \
  2664. c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \
  2665. c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \
  2666. c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \
  2667. c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \
  2668. c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
  2669. dspfunc(put_qpel, 0, 16);
  2670. dspfunc(put_no_rnd_qpel, 0, 16);
  2671. dspfunc(avg_qpel, 0, 16);
  2672. /* dspfunc(avg_no_rnd_qpel, 0, 16); */
  2673. dspfunc(put_qpel, 1, 8);
  2674. dspfunc(put_no_rnd_qpel, 1, 8);
  2675. dspfunc(avg_qpel, 1, 8);
  2676. /* dspfunc(avg_no_rnd_qpel, 1, 8); */
  2677. #undef dspfunc
  2678. #if CONFIG_MLP_DECODER || CONFIG_TRUEHD_DECODER
  2679. ff_mlp_init(c, avctx);
  2680. #endif
  2681. #if CONFIG_WMV2_DECODER || CONFIG_VC1_DECODER
  2682. ff_intrax8dsp_init(c,avctx);
  2683. #endif
  2684. #if CONFIG_RV30_DECODER
  2685. ff_rv30dsp_init(c,avctx);
  2686. #endif
  2687. #if CONFIG_RV40_DECODER
  2688. ff_rv40dsp_init(c,avctx);
  2689. c->put_rv40_qpel_pixels_tab[0][15] = put_rv40_qpel16_mc33_c;
  2690. c->avg_rv40_qpel_pixels_tab[0][15] = avg_rv40_qpel16_mc33_c;
  2691. c->put_rv40_qpel_pixels_tab[1][15] = put_rv40_qpel8_mc33_c;
  2692. c->avg_rv40_qpel_pixels_tab[1][15] = avg_rv40_qpel8_mc33_c;
  2693. #endif
  2694. c->put_mspel_pixels_tab[0]= ff_put_pixels8x8_c;
  2695. c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
  2696. c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c;
  2697. c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c;
  2698. c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c;
  2699. c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c;
  2700. c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c;
  2701. c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c;
  2702. #define SET_CMP_FUNC(name) \
  2703. c->name[0]= name ## 16_c;\
  2704. c->name[1]= name ## 8x8_c;
  2705. SET_CMP_FUNC(hadamard8_diff)
  2706. c->hadamard8_diff[4]= hadamard8_intra16_c;
  2707. c->hadamard8_diff[5]= hadamard8_intra8x8_c;
  2708. SET_CMP_FUNC(dct_sad)
  2709. SET_CMP_FUNC(dct_max)
  2710. #if CONFIG_GPL
  2711. SET_CMP_FUNC(dct264_sad)
  2712. #endif
  2713. c->sad[0]= pix_abs16_c;
  2714. c->sad[1]= pix_abs8_c;
  2715. c->sse[0]= sse16_c;
  2716. c->sse[1]= sse8_c;
  2717. c->sse[2]= sse4_c;
  2718. SET_CMP_FUNC(quant_psnr)
  2719. SET_CMP_FUNC(rd)
  2720. SET_CMP_FUNC(bit)
  2721. c->vsad[0]= vsad16_c;
  2722. c->vsad[4]= vsad_intra16_c;
  2723. c->vsad[5]= vsad_intra8_c;
  2724. c->vsse[0]= vsse16_c;
  2725. c->vsse[4]= vsse_intra16_c;
  2726. c->vsse[5]= vsse_intra8_c;
  2727. c->nsse[0]= nsse16_c;
  2728. c->nsse[1]= nsse8_c;
  2729. #if CONFIG_DWT
  2730. ff_dsputil_init_dwt(c);
  2731. #endif
  2732. c->ssd_int8_vs_int16 = ssd_int8_vs_int16_c;
  2733. c->add_bytes= add_bytes_c;
  2734. c->diff_bytes= diff_bytes_c;
  2735. c->add_hfyu_median_prediction= add_hfyu_median_prediction_c;
  2736. c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c;
  2737. c->add_hfyu_left_prediction = add_hfyu_left_prediction_c;
  2738. c->add_hfyu_left_prediction_bgr32 = add_hfyu_left_prediction_bgr32_c;
  2739. c->bswap_buf= bswap_buf;
  2740. c->bswap16_buf = bswap16_buf;
  2741. if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
  2742. c->h263_h_loop_filter= h263_h_loop_filter_c;
  2743. c->h263_v_loop_filter= h263_v_loop_filter_c;
  2744. }
  2745. if (CONFIG_VP3_DECODER) {
  2746. c->vp3_h_loop_filter= ff_vp3_h_loop_filter_c;
  2747. c->vp3_v_loop_filter= ff_vp3_v_loop_filter_c;
  2748. c->vp3_idct_dc_add= ff_vp3_idct_dc_add_c;
  2749. }
  2750. c->h261_loop_filter= h261_loop_filter_c;
  2751. c->try_8x8basis= try_8x8basis_c;
  2752. c->add_8x8basis= add_8x8basis_c;
  2753. #if CONFIG_VORBIS_DECODER
  2754. c->vorbis_inverse_coupling = vorbis_inverse_coupling;
  2755. #endif
  2756. #if CONFIG_AC3_DECODER
  2757. c->ac3_downmix = ff_ac3_downmix_c;
  2758. #endif
  2759. c->vector_fmul = vector_fmul_c;
  2760. c->vector_fmul_reverse = vector_fmul_reverse_c;
  2761. c->vector_fmul_add = vector_fmul_add_c;
  2762. c->vector_fmul_window = vector_fmul_window_c;
  2763. c->vector_clipf = vector_clipf_c;
  2764. c->scalarproduct_int16 = scalarproduct_int16_c;
  2765. c->scalarproduct_and_madd_int16 = scalarproduct_and_madd_int16_c;
  2766. c->apply_window_int16 = apply_window_int16_c;
  2767. c->vector_clip_int32 = vector_clip_int32_c;
  2768. c->scalarproduct_float = scalarproduct_float_c;
  2769. c->butterflies_float = butterflies_float_c;
  2770. c->vector_fmul_scalar = vector_fmul_scalar_c;
  2771. c->vector_fmul_sv_scalar[0] = vector_fmul_sv_scalar_2_c;
  2772. c->vector_fmul_sv_scalar[1] = vector_fmul_sv_scalar_4_c;
  2773. c->sv_fmul_scalar[0] = sv_fmul_scalar_2_c;
  2774. c->sv_fmul_scalar[1] = sv_fmul_scalar_4_c;
  2775. c->shrink[0]= av_image_copy_plane;
  2776. c->shrink[1]= ff_shrink22;
  2777. c->shrink[2]= ff_shrink44;
  2778. c->shrink[3]= ff_shrink88;
  2779. c->prefetch= just_return;
  2780. memset(c->put_2tap_qpel_pixels_tab, 0, sizeof(c->put_2tap_qpel_pixels_tab));
  2781. memset(c->avg_2tap_qpel_pixels_tab, 0, sizeof(c->avg_2tap_qpel_pixels_tab));
  2782. #undef FUNC
  2783. #undef FUNCC
  2784. #define FUNC(f, depth) f ## _ ## depth
  2785. #define FUNCC(f, depth) f ## _ ## depth ## _c
  2786. #define dspfunc1(PFX, IDX, NUM, depth)\
  2787. c->PFX ## _pixels_tab[IDX][0] = FUNCC(PFX ## _pixels ## NUM , depth);\
  2788. c->PFX ## _pixels_tab[IDX][1] = FUNCC(PFX ## _pixels ## NUM ## _x2 , depth);\
  2789. c->PFX ## _pixels_tab[IDX][2] = FUNCC(PFX ## _pixels ## NUM ## _y2 , depth);\
  2790. c->PFX ## _pixels_tab[IDX][3] = FUNCC(PFX ## _pixels ## NUM ## _xy2, depth)
  2791. #define dspfunc2(PFX, IDX, NUM, depth)\
  2792. c->PFX ## _pixels_tab[IDX][ 0] = FUNCC(PFX ## NUM ## _mc00, depth);\
  2793. c->PFX ## _pixels_tab[IDX][ 1] = FUNCC(PFX ## NUM ## _mc10, depth);\
  2794. c->PFX ## _pixels_tab[IDX][ 2] = FUNCC(PFX ## NUM ## _mc20, depth);\
  2795. c->PFX ## _pixels_tab[IDX][ 3] = FUNCC(PFX ## NUM ## _mc30, depth);\
  2796. c->PFX ## _pixels_tab[IDX][ 4] = FUNCC(PFX ## NUM ## _mc01, depth);\
  2797. c->PFX ## _pixels_tab[IDX][ 5] = FUNCC(PFX ## NUM ## _mc11, depth);\
  2798. c->PFX ## _pixels_tab[IDX][ 6] = FUNCC(PFX ## NUM ## _mc21, depth);\
  2799. c->PFX ## _pixels_tab[IDX][ 7] = FUNCC(PFX ## NUM ## _mc31, depth);\
  2800. c->PFX ## _pixels_tab[IDX][ 8] = FUNCC(PFX ## NUM ## _mc02, depth);\
  2801. c->PFX ## _pixels_tab[IDX][ 9] = FUNCC(PFX ## NUM ## _mc12, depth);\
  2802. c->PFX ## _pixels_tab[IDX][10] = FUNCC(PFX ## NUM ## _mc22, depth);\
  2803. c->PFX ## _pixels_tab[IDX][11] = FUNCC(PFX ## NUM ## _mc32, depth);\
  2804. c->PFX ## _pixels_tab[IDX][12] = FUNCC(PFX ## NUM ## _mc03, depth);\
  2805. c->PFX ## _pixels_tab[IDX][13] = FUNCC(PFX ## NUM ## _mc13, depth);\
  2806. c->PFX ## _pixels_tab[IDX][14] = FUNCC(PFX ## NUM ## _mc23, depth);\
  2807. c->PFX ## _pixels_tab[IDX][15] = FUNCC(PFX ## NUM ## _mc33, depth)
  2808. #define BIT_DEPTH_FUNCS(depth)\
  2809. c->draw_edges = FUNCC(draw_edges , depth);\
  2810. c->emulated_edge_mc = FUNC (ff_emulated_edge_mc , depth);\
  2811. c->clear_block = FUNCC(clear_block , depth);\
  2812. c->clear_blocks = FUNCC(clear_blocks , depth);\
  2813. c->add_pixels8 = FUNCC(add_pixels8 , depth);\
  2814. c->add_pixels4 = FUNCC(add_pixels4 , depth);\
  2815. c->put_no_rnd_pixels_l2[0] = FUNCC(put_no_rnd_pixels16_l2, depth);\
  2816. c->put_no_rnd_pixels_l2[1] = FUNCC(put_no_rnd_pixels8_l2 , depth);\
  2817. \
  2818. c->put_h264_chroma_pixels_tab[0] = FUNCC(put_h264_chroma_mc8 , depth);\
  2819. c->put_h264_chroma_pixels_tab[1] = FUNCC(put_h264_chroma_mc4 , depth);\
  2820. c->put_h264_chroma_pixels_tab[2] = FUNCC(put_h264_chroma_mc2 , depth);\
  2821. c->avg_h264_chroma_pixels_tab[0] = FUNCC(avg_h264_chroma_mc8 , depth);\
  2822. c->avg_h264_chroma_pixels_tab[1] = FUNCC(avg_h264_chroma_mc4 , depth);\
  2823. c->avg_h264_chroma_pixels_tab[2] = FUNCC(avg_h264_chroma_mc2 , depth);\
  2824. \
  2825. dspfunc1(put , 0, 16, depth);\
  2826. dspfunc1(put , 1, 8, depth);\
  2827. dspfunc1(put , 2, 4, depth);\
  2828. dspfunc1(put , 3, 2, depth);\
  2829. dspfunc1(put_no_rnd, 0, 16, depth);\
  2830. dspfunc1(put_no_rnd, 1, 8, depth);\
  2831. dspfunc1(avg , 0, 16, depth);\
  2832. dspfunc1(avg , 1, 8, depth);\
  2833. dspfunc1(avg , 2, 4, depth);\
  2834. dspfunc1(avg , 3, 2, depth);\
  2835. dspfunc1(avg_no_rnd, 0, 16, depth);\
  2836. dspfunc1(avg_no_rnd, 1, 8, depth);\
  2837. \
  2838. dspfunc2(put_h264_qpel, 0, 16, depth);\
  2839. dspfunc2(put_h264_qpel, 1, 8, depth);\
  2840. dspfunc2(put_h264_qpel, 2, 4, depth);\
  2841. dspfunc2(put_h264_qpel, 3, 2, depth);\
  2842. dspfunc2(avg_h264_qpel, 0, 16, depth);\
  2843. dspfunc2(avg_h264_qpel, 1, 8, depth);\
  2844. dspfunc2(avg_h264_qpel, 2, 4, depth);
  2845. switch (avctx->bits_per_raw_sample) {
  2846. case 9:
  2847. BIT_DEPTH_FUNCS(9);
  2848. break;
  2849. case 10:
  2850. BIT_DEPTH_FUNCS(10);
  2851. break;
  2852. default:
  2853. av_log(avctx, AV_LOG_DEBUG, "Unsupported bit depth: %d\n", avctx->bits_per_raw_sample);
  2854. case 8:
  2855. BIT_DEPTH_FUNCS(8);
  2856. break;
  2857. }
  2858. if (HAVE_MMX) dsputil_init_mmx (c, avctx);
  2859. if (ARCH_ARM) dsputil_init_arm (c, avctx);
  2860. if (CONFIG_MLIB) dsputil_init_mlib (c, avctx);
  2861. if (HAVE_VIS) dsputil_init_vis (c, avctx);
  2862. if (ARCH_ALPHA) dsputil_init_alpha (c, avctx);
  2863. if (ARCH_PPC) dsputil_init_ppc (c, avctx);
  2864. if (HAVE_MMI) dsputil_init_mmi (c, avctx);
  2865. if (ARCH_SH4) dsputil_init_sh4 (c, avctx);
  2866. if (ARCH_BFIN) dsputil_init_bfin (c, avctx);
  2867. for(i=0; i<64; i++){
  2868. if(!c->put_2tap_qpel_pixels_tab[0][i])
  2869. c->put_2tap_qpel_pixels_tab[0][i]= c->put_h264_qpel_pixels_tab[0][i];
  2870. if(!c->avg_2tap_qpel_pixels_tab[0][i])
  2871. c->avg_2tap_qpel_pixels_tab[0][i]= c->avg_h264_qpel_pixels_tab[0][i];
  2872. }
  2873. c->put_rv30_tpel_pixels_tab[0][0] = c->put_h264_qpel_pixels_tab[0][0];
  2874. c->put_rv30_tpel_pixels_tab[1][0] = c->put_h264_qpel_pixels_tab[1][0];
  2875. c->avg_rv30_tpel_pixels_tab[0][0] = c->avg_h264_qpel_pixels_tab[0][0];
  2876. c->avg_rv30_tpel_pixels_tab[1][0] = c->avg_h264_qpel_pixels_tab[1][0];
  2877. c->put_rv40_qpel_pixels_tab[0][0] = c->put_h264_qpel_pixels_tab[0][0];
  2878. c->put_rv40_qpel_pixels_tab[1][0] = c->put_h264_qpel_pixels_tab[1][0];
  2879. c->avg_rv40_qpel_pixels_tab[0][0] = c->avg_h264_qpel_pixels_tab[0][0];
  2880. c->avg_rv40_qpel_pixels_tab[1][0] = c->avg_h264_qpel_pixels_tab[1][0];
  2881. switch(c->idct_permutation_type){
  2882. case FF_NO_IDCT_PERM:
  2883. for(i=0; i<64; i++)
  2884. c->idct_permutation[i]= i;
  2885. break;
  2886. case FF_LIBMPEG2_IDCT_PERM:
  2887. for(i=0; i<64; i++)
  2888. c->idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
  2889. break;
  2890. case FF_SIMPLE_IDCT_PERM:
  2891. for(i=0; i<64; i++)
  2892. c->idct_permutation[i]= simple_mmx_permutation[i];
  2893. break;
  2894. case FF_TRANSPOSE_IDCT_PERM:
  2895. for(i=0; i<64; i++)
  2896. c->idct_permutation[i]= ((i&7)<<3) | (i>>3);
  2897. break;
  2898. case FF_PARTTRANS_IDCT_PERM:
  2899. for(i=0; i<64; i++)
  2900. c->idct_permutation[i]= (i&0x24) | ((i&3)<<3) | ((i>>3)&3);
  2901. break;
  2902. case FF_SSE2_IDCT_PERM:
  2903. for(i=0; i<64; i++)
  2904. c->idct_permutation[i]= (i&0x38) | idct_sse2_row_perm[i&7];
  2905. break;
  2906. default:
  2907. av_log(avctx, AV_LOG_ERROR, "Internal error, IDCT permutation not set\n");
  2908. }
  2909. }