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.

3288 lines
111KB

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