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.

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