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.

3146 lines
106KB

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