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.

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