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.

3272 lines
110KB

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