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.

3139 lines
105KB

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