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.

3222 lines
108KB

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