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.

4536 lines
158KB

  1. /*
  2. * DSP utils
  3. * Copyright (c) 2000, 2001 Fabrice Bellard
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
  7. *
  8. * This file is part of FFmpeg.
  9. *
  10. * FFmpeg is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * FFmpeg is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with FFmpeg; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. /**
  25. * @file
  26. * DSP utils
  27. */
  28. #include "avcodec.h"
  29. #include "dsputil.h"
  30. #include "simple_idct.h"
  31. #include "faandct.h"
  32. #include "faanidct.h"
  33. #include "mathops.h"
  34. #include "mpegvideo.h"
  35. #include "config.h"
  36. #include "lpc.h"
  37. #include "ac3dec.h"
  38. #include "vorbis.h"
  39. #include "png.h"
  40. #include "vp8dsp.h"
  41. uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP] = {0, };
  42. uint32_t ff_squareTbl[512] = {0, };
  43. // 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size
  44. #define pb_7f (~0UL/255 * 0x7f)
  45. #define pb_80 (~0UL/255 * 0x80)
  46. const uint8_t ff_zigzag_direct[64] = {
  47. 0, 1, 8, 16, 9, 2, 3, 10,
  48. 17, 24, 32, 25, 18, 11, 4, 5,
  49. 12, 19, 26, 33, 40, 48, 41, 34,
  50. 27, 20, 13, 6, 7, 14, 21, 28,
  51. 35, 42, 49, 56, 57, 50, 43, 36,
  52. 29, 22, 15, 23, 30, 37, 44, 51,
  53. 58, 59, 52, 45, 38, 31, 39, 46,
  54. 53, 60, 61, 54, 47, 55, 62, 63
  55. };
  56. /* Specific zigzag scan for 248 idct. NOTE that unlike the
  57. specification, we interleave the fields */
  58. const uint8_t ff_zigzag248_direct[64] = {
  59. 0, 8, 1, 9, 16, 24, 2, 10,
  60. 17, 25, 32, 40, 48, 56, 33, 41,
  61. 18, 26, 3, 11, 4, 12, 19, 27,
  62. 34, 42, 49, 57, 50, 58, 35, 43,
  63. 20, 28, 5, 13, 6, 14, 21, 29,
  64. 36, 44, 51, 59, 52, 60, 37, 45,
  65. 22, 30, 7, 15, 23, 31, 38, 46,
  66. 53, 61, 54, 62, 39, 47, 55, 63,
  67. };
  68. /* not permutated inverse zigzag_direct + 1 for MMX quantizer */
  69. DECLARE_ALIGNED(16, uint16_t, inv_zigzag_direct16)[64];
  70. const uint8_t ff_alternate_horizontal_scan[64] = {
  71. 0, 1, 2, 3, 8, 9, 16, 17,
  72. 10, 11, 4, 5, 6, 7, 15, 14,
  73. 13, 12, 19, 18, 24, 25, 32, 33,
  74. 26, 27, 20, 21, 22, 23, 28, 29,
  75. 30, 31, 34, 35, 40, 41, 48, 49,
  76. 42, 43, 36, 37, 38, 39, 44, 45,
  77. 46, 47, 50, 51, 56, 57, 58, 59,
  78. 52, 53, 54, 55, 60, 61, 62, 63,
  79. };
  80. const uint8_t ff_alternate_vertical_scan[64] = {
  81. 0, 8, 16, 24, 1, 9, 2, 10,
  82. 17, 25, 32, 40, 48, 56, 57, 49,
  83. 41, 33, 26, 18, 3, 11, 4, 12,
  84. 19, 27, 34, 42, 50, 58, 35, 43,
  85. 51, 59, 20, 28, 5, 13, 6, 14,
  86. 21, 29, 36, 44, 52, 60, 37, 45,
  87. 53, 61, 22, 30, 7, 15, 23, 31,
  88. 38, 46, 54, 62, 39, 47, 55, 63,
  89. };
  90. /* Input permutation for the simple_idct_mmx */
  91. static const uint8_t simple_mmx_permutation[64]={
  92. 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D,
  93. 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D,
  94. 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D,
  95. 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F,
  96. 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F,
  97. 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D,
  98. 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F,
  99. 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F,
  100. };
  101. static const uint8_t idct_sse2_row_perm[8] = {0, 4, 1, 5, 2, 6, 3, 7};
  102. void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable){
  103. int i;
  104. int end;
  105. st->scantable= src_scantable;
  106. for(i=0; i<64; i++){
  107. int j;
  108. j = src_scantable[i];
  109. st->permutated[i] = permutation[j];
  110. #if ARCH_PPC
  111. st->inverse[j] = i;
  112. #endif
  113. }
  114. end=-1;
  115. for(i=0; i<64; i++){
  116. int j;
  117. j = st->permutated[i];
  118. if(j>end) end=j;
  119. st->raster_end[i]= end;
  120. }
  121. }
  122. static int pix_sum_c(uint8_t * pix, int line_size)
  123. {
  124. int s, i, j;
  125. s = 0;
  126. for (i = 0; i < 16; i++) {
  127. for (j = 0; j < 16; j += 8) {
  128. s += pix[0];
  129. s += pix[1];
  130. s += pix[2];
  131. s += pix[3];
  132. s += pix[4];
  133. s += pix[5];
  134. s += pix[6];
  135. s += pix[7];
  136. pix += 8;
  137. }
  138. pix += line_size - 16;
  139. }
  140. return s;
  141. }
  142. static int pix_norm1_c(uint8_t * pix, int line_size)
  143. {
  144. int s, i, j;
  145. uint32_t *sq = ff_squareTbl + 256;
  146. s = 0;
  147. for (i = 0; i < 16; i++) {
  148. for (j = 0; j < 16; j += 8) {
  149. #if 0
  150. s += sq[pix[0]];
  151. s += sq[pix[1]];
  152. s += sq[pix[2]];
  153. s += sq[pix[3]];
  154. s += sq[pix[4]];
  155. s += sq[pix[5]];
  156. s += sq[pix[6]];
  157. s += sq[pix[7]];
  158. #else
  159. #if LONG_MAX > 2147483647
  160. register uint64_t x=*(uint64_t*)pix;
  161. s += sq[x&0xff];
  162. s += sq[(x>>8)&0xff];
  163. s += sq[(x>>16)&0xff];
  164. s += sq[(x>>24)&0xff];
  165. s += sq[(x>>32)&0xff];
  166. s += sq[(x>>40)&0xff];
  167. s += sq[(x>>48)&0xff];
  168. s += sq[(x>>56)&0xff];
  169. #else
  170. register uint32_t x=*(uint32_t*)pix;
  171. s += sq[x&0xff];
  172. s += sq[(x>>8)&0xff];
  173. s += sq[(x>>16)&0xff];
  174. s += sq[(x>>24)&0xff];
  175. x=*(uint32_t*)(pix+4);
  176. s += sq[x&0xff];
  177. s += sq[(x>>8)&0xff];
  178. s += sq[(x>>16)&0xff];
  179. s += sq[(x>>24)&0xff];
  180. #endif
  181. #endif
  182. pix += 8;
  183. }
  184. pix += line_size - 16;
  185. }
  186. return s;
  187. }
  188. static void bswap_buf(uint32_t *dst, const uint32_t *src, int w){
  189. int i;
  190. for(i=0; i+8<=w; i+=8){
  191. dst[i+0]= av_bswap32(src[i+0]);
  192. dst[i+1]= av_bswap32(src[i+1]);
  193. dst[i+2]= av_bswap32(src[i+2]);
  194. dst[i+3]= av_bswap32(src[i+3]);
  195. dst[i+4]= av_bswap32(src[i+4]);
  196. dst[i+5]= av_bswap32(src[i+5]);
  197. dst[i+6]= av_bswap32(src[i+6]);
  198. dst[i+7]= av_bswap32(src[i+7]);
  199. }
  200. for(;i<w; i++){
  201. dst[i+0]= av_bswap32(src[i+0]);
  202. }
  203. }
  204. static int sse4_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
  205. {
  206. int s, i;
  207. uint32_t *sq = ff_squareTbl + 256;
  208. s = 0;
  209. for (i = 0; i < h; i++) {
  210. s += sq[pix1[0] - pix2[0]];
  211. s += sq[pix1[1] - pix2[1]];
  212. s += sq[pix1[2] - pix2[2]];
  213. s += sq[pix1[3] - pix2[3]];
  214. pix1 += line_size;
  215. pix2 += line_size;
  216. }
  217. return s;
  218. }
  219. static int sse8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
  220. {
  221. int s, i;
  222. uint32_t *sq = ff_squareTbl + 256;
  223. s = 0;
  224. for (i = 0; i < h; i++) {
  225. s += sq[pix1[0] - pix2[0]];
  226. s += sq[pix1[1] - pix2[1]];
  227. s += sq[pix1[2] - pix2[2]];
  228. s += sq[pix1[3] - pix2[3]];
  229. s += sq[pix1[4] - pix2[4]];
  230. s += sq[pix1[5] - pix2[5]];
  231. s += sq[pix1[6] - pix2[6]];
  232. s += sq[pix1[7] - pix2[7]];
  233. pix1 += line_size;
  234. pix2 += line_size;
  235. }
  236. return s;
  237. }
  238. static int sse16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  239. {
  240. int s, i;
  241. uint32_t *sq = ff_squareTbl + 256;
  242. s = 0;
  243. for (i = 0; i < h; i++) {
  244. s += sq[pix1[ 0] - pix2[ 0]];
  245. s += sq[pix1[ 1] - pix2[ 1]];
  246. s += sq[pix1[ 2] - pix2[ 2]];
  247. s += sq[pix1[ 3] - pix2[ 3]];
  248. s += sq[pix1[ 4] - pix2[ 4]];
  249. s += sq[pix1[ 5] - pix2[ 5]];
  250. s += sq[pix1[ 6] - pix2[ 6]];
  251. s += sq[pix1[ 7] - pix2[ 7]];
  252. s += sq[pix1[ 8] - pix2[ 8]];
  253. s += sq[pix1[ 9] - pix2[ 9]];
  254. s += sq[pix1[10] - pix2[10]];
  255. s += sq[pix1[11] - pix2[11]];
  256. s += sq[pix1[12] - pix2[12]];
  257. s += sq[pix1[13] - pix2[13]];
  258. s += sq[pix1[14] - pix2[14]];
  259. s += sq[pix1[15] - pix2[15]];
  260. pix1 += line_size;
  261. pix2 += line_size;
  262. }
  263. return s;
  264. }
  265. /* draw the edges of width 'w' of an image of size width, height */
  266. //FIXME check that this is ok for mpeg4 interlaced
  267. static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w)
  268. {
  269. uint8_t *ptr, *last_line;
  270. int i;
  271. last_line = buf + (height - 1) * wrap;
  272. for(i=0;i<w;i++) {
  273. /* top and bottom */
  274. memcpy(buf - (i + 1) * wrap, buf, width);
  275. memcpy(last_line + (i + 1) * wrap, last_line, width);
  276. }
  277. /* left and right */
  278. ptr = buf;
  279. for(i=0;i<height;i++) {
  280. memset(ptr - w, ptr[0], w);
  281. memset(ptr + width, ptr[width-1], w);
  282. ptr += wrap;
  283. }
  284. /* corners */
  285. for(i=0;i<w;i++) {
  286. memset(buf - (i + 1) * wrap - w, buf[0], w); /* top left */
  287. memset(buf - (i + 1) * wrap + width, buf[width-1], w); /* top right */
  288. memset(last_line + (i + 1) * wrap - w, last_line[0], w); /* top left */
  289. memset(last_line + (i + 1) * wrap + width, last_line[width-1], w); /* top right */
  290. }
  291. }
  292. /**
  293. * Copy a rectangular area of samples to a temporary buffer and replicate the border samples.
  294. * @param buf destination buffer
  295. * @param src source buffer
  296. * @param linesize number of bytes between 2 vertically adjacent samples in both the source and destination buffers
  297. * @param block_w width of block
  298. * @param block_h height of block
  299. * @param src_x x coordinate of the top left sample of the block in the source buffer
  300. * @param src_y y coordinate of the top left sample of the block in the source buffer
  301. * @param w width of the source buffer
  302. * @param h height of the source buffer
  303. */
  304. void ff_emulated_edge_mc(uint8_t *buf, const uint8_t *src, int linesize, int block_w, int block_h,
  305. int src_x, int src_y, int w, int h){
  306. int x, y;
  307. int start_y, start_x, end_y, end_x;
  308. if(src_y>= h){
  309. src+= (h-1-src_y)*linesize;
  310. src_y=h-1;
  311. }else if(src_y<=-block_h){
  312. src+= (1-block_h-src_y)*linesize;
  313. src_y=1-block_h;
  314. }
  315. if(src_x>= w){
  316. src+= (w-1-src_x);
  317. src_x=w-1;
  318. }else if(src_x<=-block_w){
  319. src+= (1-block_w-src_x);
  320. src_x=1-block_w;
  321. }
  322. start_y= FFMAX(0, -src_y);
  323. start_x= FFMAX(0, -src_x);
  324. end_y= FFMIN(block_h, h-src_y);
  325. end_x= FFMIN(block_w, w-src_x);
  326. // copy existing part
  327. for(y=start_y; y<end_y; y++){
  328. for(x=start_x; x<end_x; x++){
  329. buf[x + y*linesize]= src[x + y*linesize];
  330. }
  331. }
  332. //top
  333. for(y=0; y<start_y; y++){
  334. for(x=start_x; x<end_x; x++){
  335. buf[x + y*linesize]= buf[x + start_y*linesize];
  336. }
  337. }
  338. //bottom
  339. for(y=end_y; y<block_h; y++){
  340. for(x=start_x; x<end_x; x++){
  341. buf[x + y*linesize]= buf[x + (end_y-1)*linesize];
  342. }
  343. }
  344. for(y=0; y<block_h; y++){
  345. //left
  346. for(x=0; x<start_x; x++){
  347. buf[x + y*linesize]= buf[start_x + y*linesize];
  348. }
  349. //right
  350. for(x=end_x; x<block_w; x++){
  351. buf[x + y*linesize]= buf[end_x - 1 + y*linesize];
  352. }
  353. }
  354. }
  355. static void get_pixels_c(DCTELEM *restrict block, const uint8_t *pixels, int line_size)
  356. {
  357. int i;
  358. /* read the pixels */
  359. for(i=0;i<8;i++) {
  360. block[0] = pixels[0];
  361. block[1] = pixels[1];
  362. block[2] = pixels[2];
  363. block[3] = pixels[3];
  364. block[4] = pixels[4];
  365. block[5] = pixels[5];
  366. block[6] = pixels[6];
  367. block[7] = pixels[7];
  368. pixels += line_size;
  369. block += 8;
  370. }
  371. }
  372. static void diff_pixels_c(DCTELEM *restrict block, const uint8_t *s1,
  373. const uint8_t *s2, int stride){
  374. int i;
  375. /* read the pixels */
  376. for(i=0;i<8;i++) {
  377. block[0] = s1[0] - s2[0];
  378. block[1] = s1[1] - s2[1];
  379. block[2] = s1[2] - s2[2];
  380. block[3] = s1[3] - s2[3];
  381. block[4] = s1[4] - s2[4];
  382. block[5] = s1[5] - s2[5];
  383. block[6] = s1[6] - s2[6];
  384. block[7] = s1[7] - s2[7];
  385. s1 += stride;
  386. s2 += stride;
  387. block += 8;
  388. }
  389. }
  390. static void put_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
  391. int line_size)
  392. {
  393. int i;
  394. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  395. /* read the pixels */
  396. for(i=0;i<8;i++) {
  397. pixels[0] = cm[block[0]];
  398. pixels[1] = cm[block[1]];
  399. pixels[2] = cm[block[2]];
  400. pixels[3] = cm[block[3]];
  401. pixels[4] = cm[block[4]];
  402. pixels[5] = cm[block[5]];
  403. pixels[6] = cm[block[6]];
  404. pixels[7] = cm[block[7]];
  405. pixels += line_size;
  406. block += 8;
  407. }
  408. }
  409. static void put_pixels_clamped4_c(const DCTELEM *block, uint8_t *restrict pixels,
  410. int line_size)
  411. {
  412. int i;
  413. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  414. /* read the pixels */
  415. for(i=0;i<4;i++) {
  416. pixels[0] = cm[block[0]];
  417. pixels[1] = cm[block[1]];
  418. pixels[2] = cm[block[2]];
  419. pixels[3] = cm[block[3]];
  420. pixels += line_size;
  421. block += 8;
  422. }
  423. }
  424. static void put_pixels_clamped2_c(const DCTELEM *block, uint8_t *restrict pixels,
  425. int line_size)
  426. {
  427. int i;
  428. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  429. /* read the pixels */
  430. for(i=0;i<2;i++) {
  431. pixels[0] = cm[block[0]];
  432. pixels[1] = cm[block[1]];
  433. pixels += line_size;
  434. block += 8;
  435. }
  436. }
  437. static void put_signed_pixels_clamped_c(const DCTELEM *block,
  438. uint8_t *restrict pixels,
  439. int line_size)
  440. {
  441. int i, j;
  442. for (i = 0; i < 8; i++) {
  443. for (j = 0; j < 8; j++) {
  444. if (*block < -128)
  445. *pixels = 0;
  446. else if (*block > 127)
  447. *pixels = 255;
  448. else
  449. *pixels = (uint8_t)(*block + 128);
  450. block++;
  451. pixels++;
  452. }
  453. pixels += (line_size - 8);
  454. }
  455. }
  456. static void put_pixels_nonclamped_c(const DCTELEM *block, uint8_t *restrict pixels,
  457. int line_size)
  458. {
  459. int i;
  460. /* read the pixels */
  461. for(i=0;i<8;i++) {
  462. pixels[0] = block[0];
  463. pixels[1] = block[1];
  464. pixels[2] = block[2];
  465. pixels[3] = block[3];
  466. pixels[4] = block[4];
  467. pixels[5] = block[5];
  468. pixels[6] = block[6];
  469. pixels[7] = block[7];
  470. pixels += line_size;
  471. block += 8;
  472. }
  473. }
  474. static void add_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
  475. int line_size)
  476. {
  477. int i;
  478. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  479. /* read the pixels */
  480. for(i=0;i<8;i++) {
  481. pixels[0] = cm[pixels[0] + block[0]];
  482. pixels[1] = cm[pixels[1] + block[1]];
  483. pixels[2] = cm[pixels[2] + block[2]];
  484. pixels[3] = cm[pixels[3] + block[3]];
  485. pixels[4] = cm[pixels[4] + block[4]];
  486. pixels[5] = cm[pixels[5] + block[5]];
  487. pixels[6] = cm[pixels[6] + block[6]];
  488. pixels[7] = cm[pixels[7] + block[7]];
  489. pixels += line_size;
  490. block += 8;
  491. }
  492. }
  493. static void add_pixels_clamped4_c(const DCTELEM *block, uint8_t *restrict pixels,
  494. int line_size)
  495. {
  496. int i;
  497. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  498. /* read the pixels */
  499. for(i=0;i<4;i++) {
  500. pixels[0] = cm[pixels[0] + block[0]];
  501. pixels[1] = cm[pixels[1] + block[1]];
  502. pixels[2] = cm[pixels[2] + block[2]];
  503. pixels[3] = cm[pixels[3] + block[3]];
  504. pixels += line_size;
  505. block += 8;
  506. }
  507. }
  508. static void add_pixels_clamped2_c(const DCTELEM *block, uint8_t *restrict pixels,
  509. int line_size)
  510. {
  511. int i;
  512. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  513. /* read the pixels */
  514. for(i=0;i<2;i++) {
  515. pixels[0] = cm[pixels[0] + block[0]];
  516. pixels[1] = cm[pixels[1] + block[1]];
  517. pixels += line_size;
  518. block += 8;
  519. }
  520. }
  521. static void add_pixels8_c(uint8_t *restrict pixels, DCTELEM *block, int line_size)
  522. {
  523. int i;
  524. for(i=0;i<8;i++) {
  525. pixels[0] += block[0];
  526. pixels[1] += block[1];
  527. pixels[2] += block[2];
  528. pixels[3] += block[3];
  529. pixels[4] += block[4];
  530. pixels[5] += block[5];
  531. pixels[6] += block[6];
  532. pixels[7] += block[7];
  533. pixels += line_size;
  534. block += 8;
  535. }
  536. }
  537. static void add_pixels4_c(uint8_t *restrict pixels, DCTELEM *block, int line_size)
  538. {
  539. int i;
  540. for(i=0;i<4;i++) {
  541. pixels[0] += block[0];
  542. pixels[1] += block[1];
  543. pixels[2] += block[2];
  544. pixels[3] += block[3];
  545. pixels += line_size;
  546. block += 4;
  547. }
  548. }
  549. static int sum_abs_dctelem_c(DCTELEM *block)
  550. {
  551. int sum=0, i;
  552. for(i=0; i<64; i++)
  553. sum+= FFABS(block[i]);
  554. return sum;
  555. }
  556. static void fill_block16_c(uint8_t *block, uint8_t value, int line_size, int h)
  557. {
  558. int i;
  559. for (i = 0; i < h; i++) {
  560. memset(block, value, 16);
  561. block += line_size;
  562. }
  563. }
  564. static void fill_block8_c(uint8_t *block, uint8_t value, int line_size, int h)
  565. {
  566. int i;
  567. for (i = 0; i < h; i++) {
  568. memset(block, value, 8);
  569. block += line_size;
  570. }
  571. }
  572. static void scale_block_c(const uint8_t src[64]/*align 8*/, uint8_t *dst/*align 8*/, int linesize)
  573. {
  574. int i, j;
  575. uint16_t *dst1 = (uint16_t *) dst;
  576. uint16_t *dst2 = (uint16_t *)(dst + linesize);
  577. for (j = 0; j < 8; j++) {
  578. for (i = 0; i < 8; i++) {
  579. dst1[i] = dst2[i] = src[i] * 0x0101;
  580. }
  581. src += 8;
  582. dst1 += linesize;
  583. dst2 += linesize;
  584. }
  585. }
  586. #if 0
  587. #define PIXOP2(OPNAME, OP) \
  588. static void OPNAME ## _pixels(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  589. {\
  590. int i;\
  591. for(i=0; i<h; i++){\
  592. OP(*((uint64_t*)block), AV_RN64(pixels));\
  593. pixels+=line_size;\
  594. block +=line_size;\
  595. }\
  596. }\
  597. \
  598. static void OPNAME ## _no_rnd_pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  599. {\
  600. int i;\
  601. for(i=0; i<h; i++){\
  602. const uint64_t a= AV_RN64(pixels );\
  603. const uint64_t b= AV_RN64(pixels+1);\
  604. OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  605. pixels+=line_size;\
  606. block +=line_size;\
  607. }\
  608. }\
  609. \
  610. static void OPNAME ## _pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  611. {\
  612. int i;\
  613. for(i=0; i<h; i++){\
  614. const uint64_t a= AV_RN64(pixels );\
  615. const uint64_t b= AV_RN64(pixels+1);\
  616. OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  617. pixels+=line_size;\
  618. block +=line_size;\
  619. }\
  620. }\
  621. \
  622. static void OPNAME ## _no_rnd_pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  623. {\
  624. int i;\
  625. for(i=0; i<h; i++){\
  626. const uint64_t a= AV_RN64(pixels );\
  627. const uint64_t b= AV_RN64(pixels+line_size);\
  628. OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  629. pixels+=line_size;\
  630. block +=line_size;\
  631. }\
  632. }\
  633. \
  634. static void OPNAME ## _pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  635. {\
  636. int i;\
  637. for(i=0; i<h; i++){\
  638. const uint64_t a= AV_RN64(pixels );\
  639. const uint64_t b= AV_RN64(pixels+line_size);\
  640. OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  641. pixels+=line_size;\
  642. block +=line_size;\
  643. }\
  644. }\
  645. \
  646. static void OPNAME ## _pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  647. {\
  648. int i;\
  649. const uint64_t a= AV_RN64(pixels );\
  650. const uint64_t b= AV_RN64(pixels+1);\
  651. uint64_t l0= (a&0x0303030303030303ULL)\
  652. + (b&0x0303030303030303ULL)\
  653. + 0x0202020202020202ULL;\
  654. uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  655. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  656. uint64_t l1,h1;\
  657. \
  658. pixels+=line_size;\
  659. for(i=0; i<h; i+=2){\
  660. uint64_t a= AV_RN64(pixels );\
  661. uint64_t b= AV_RN64(pixels+1);\
  662. l1= (a&0x0303030303030303ULL)\
  663. + (b&0x0303030303030303ULL);\
  664. h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  665. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  666. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  667. pixels+=line_size;\
  668. block +=line_size;\
  669. a= AV_RN64(pixels );\
  670. b= AV_RN64(pixels+1);\
  671. l0= (a&0x0303030303030303ULL)\
  672. + (b&0x0303030303030303ULL)\
  673. + 0x0202020202020202ULL;\
  674. h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  675. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  676. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  677. pixels+=line_size;\
  678. block +=line_size;\
  679. }\
  680. }\
  681. \
  682. static void OPNAME ## _no_rnd_pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  683. {\
  684. int i;\
  685. const uint64_t a= AV_RN64(pixels );\
  686. const uint64_t b= AV_RN64(pixels+1);\
  687. uint64_t l0= (a&0x0303030303030303ULL)\
  688. + (b&0x0303030303030303ULL)\
  689. + 0x0101010101010101ULL;\
  690. uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  691. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  692. uint64_t l1,h1;\
  693. \
  694. pixels+=line_size;\
  695. for(i=0; i<h; i+=2){\
  696. uint64_t a= AV_RN64(pixels );\
  697. uint64_t b= AV_RN64(pixels+1);\
  698. l1= (a&0x0303030303030303ULL)\
  699. + (b&0x0303030303030303ULL);\
  700. h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  701. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  702. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  703. pixels+=line_size;\
  704. block +=line_size;\
  705. a= AV_RN64(pixels );\
  706. b= AV_RN64(pixels+1);\
  707. l0= (a&0x0303030303030303ULL)\
  708. + (b&0x0303030303030303ULL)\
  709. + 0x0101010101010101ULL;\
  710. h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  711. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  712. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  713. pixels+=line_size;\
  714. block +=line_size;\
  715. }\
  716. }\
  717. \
  718. CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels_c , 8)\
  719. CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels_x2_c , 8)\
  720. CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels_y2_c , 8)\
  721. CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels_xy2_c, 8)\
  722. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels_x2_c , 8)\
  723. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels_y2_c , 8)\
  724. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels_xy2_c, 8)
  725. #define op_avg(a, b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEFEFEFEFEULL)>>1) )
  726. #else // 64 bit variant
  727. #define PIXOP2(OPNAME, OP) \
  728. static void OPNAME ## _pixels2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  729. int i;\
  730. for(i=0; i<h; i++){\
  731. OP(*((uint16_t*)(block )), AV_RN16(pixels ));\
  732. pixels+=line_size;\
  733. block +=line_size;\
  734. }\
  735. }\
  736. static void OPNAME ## _pixels4_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  737. int i;\
  738. for(i=0; i<h; i++){\
  739. OP(*((uint32_t*)(block )), AV_RN32(pixels ));\
  740. pixels+=line_size;\
  741. block +=line_size;\
  742. }\
  743. }\
  744. static void OPNAME ## _pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  745. int i;\
  746. for(i=0; i<h; i++){\
  747. OP(*((uint32_t*)(block )), AV_RN32(pixels ));\
  748. OP(*((uint32_t*)(block+4)), AV_RN32(pixels+4));\
  749. pixels+=line_size;\
  750. block +=line_size;\
  751. }\
  752. }\
  753. static inline void OPNAME ## _no_rnd_pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  754. OPNAME ## _pixels8_c(block, pixels, line_size, h);\
  755. }\
  756. \
  757. static inline void OPNAME ## _no_rnd_pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  758. int src_stride1, int src_stride2, int h){\
  759. int i;\
  760. for(i=0; i<h; i++){\
  761. uint32_t a,b;\
  762. a= AV_RN32(&src1[i*src_stride1 ]);\
  763. b= AV_RN32(&src2[i*src_stride2 ]);\
  764. OP(*((uint32_t*)&dst[i*dst_stride ]), no_rnd_avg32(a, b));\
  765. a= AV_RN32(&src1[i*src_stride1+4]);\
  766. b= AV_RN32(&src2[i*src_stride2+4]);\
  767. OP(*((uint32_t*)&dst[i*dst_stride+4]), no_rnd_avg32(a, b));\
  768. }\
  769. }\
  770. \
  771. static inline void OPNAME ## _pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  772. int src_stride1, int src_stride2, int h){\
  773. int i;\
  774. for(i=0; i<h; i++){\
  775. uint32_t a,b;\
  776. a= AV_RN32(&src1[i*src_stride1 ]);\
  777. b= AV_RN32(&src2[i*src_stride2 ]);\
  778. OP(*((uint32_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
  779. a= AV_RN32(&src1[i*src_stride1+4]);\
  780. b= AV_RN32(&src2[i*src_stride2+4]);\
  781. OP(*((uint32_t*)&dst[i*dst_stride+4]), rnd_avg32(a, b));\
  782. }\
  783. }\
  784. \
  785. static inline void OPNAME ## _pixels4_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  786. int src_stride1, int src_stride2, int h){\
  787. int i;\
  788. for(i=0; i<h; i++){\
  789. uint32_t a,b;\
  790. a= AV_RN32(&src1[i*src_stride1 ]);\
  791. b= AV_RN32(&src2[i*src_stride2 ]);\
  792. OP(*((uint32_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
  793. }\
  794. }\
  795. \
  796. static inline void OPNAME ## _pixels2_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  797. int src_stride1, int src_stride2, int h){\
  798. int i;\
  799. for(i=0; i<h; i++){\
  800. uint32_t a,b;\
  801. a= AV_RN16(&src1[i*src_stride1 ]);\
  802. b= AV_RN16(&src2[i*src_stride2 ]);\
  803. OP(*((uint16_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
  804. }\
  805. }\
  806. \
  807. static inline void OPNAME ## _pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  808. int src_stride1, int src_stride2, int h){\
  809. OPNAME ## _pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
  810. OPNAME ## _pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
  811. }\
  812. \
  813. static inline void OPNAME ## _no_rnd_pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  814. int src_stride1, int src_stride2, int h){\
  815. OPNAME ## _no_rnd_pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
  816. OPNAME ## _no_rnd_pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
  817. }\
  818. \
  819. static inline void OPNAME ## _no_rnd_pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  820. OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
  821. }\
  822. \
  823. static inline void OPNAME ## _pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  824. OPNAME ## _pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
  825. }\
  826. \
  827. static inline void OPNAME ## _no_rnd_pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  828. OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
  829. }\
  830. \
  831. static inline void OPNAME ## _pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  832. OPNAME ## _pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
  833. }\
  834. \
  835. static inline void OPNAME ## _pixels8_l4(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\
  836. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  837. int i;\
  838. for(i=0; i<h; i++){\
  839. uint32_t a, b, c, d, l0, l1, h0, h1;\
  840. a= AV_RN32(&src1[i*src_stride1]);\
  841. b= AV_RN32(&src2[i*src_stride2]);\
  842. c= AV_RN32(&src3[i*src_stride3]);\
  843. d= AV_RN32(&src4[i*src_stride4]);\
  844. l0= (a&0x03030303UL)\
  845. + (b&0x03030303UL)\
  846. + 0x02020202UL;\
  847. h0= ((a&0xFCFCFCFCUL)>>2)\
  848. + ((b&0xFCFCFCFCUL)>>2);\
  849. l1= (c&0x03030303UL)\
  850. + (d&0x03030303UL);\
  851. h1= ((c&0xFCFCFCFCUL)>>2)\
  852. + ((d&0xFCFCFCFCUL)>>2);\
  853. OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  854. a= AV_RN32(&src1[i*src_stride1+4]);\
  855. b= AV_RN32(&src2[i*src_stride2+4]);\
  856. c= AV_RN32(&src3[i*src_stride3+4]);\
  857. d= AV_RN32(&src4[i*src_stride4+4]);\
  858. l0= (a&0x03030303UL)\
  859. + (b&0x03030303UL)\
  860. + 0x02020202UL;\
  861. h0= ((a&0xFCFCFCFCUL)>>2)\
  862. + ((b&0xFCFCFCFCUL)>>2);\
  863. l1= (c&0x03030303UL)\
  864. + (d&0x03030303UL);\
  865. h1= ((c&0xFCFCFCFCUL)>>2)\
  866. + ((d&0xFCFCFCFCUL)>>2);\
  867. OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  868. }\
  869. }\
  870. \
  871. static inline void OPNAME ## _pixels4_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  872. OPNAME ## _pixels4_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
  873. }\
  874. \
  875. static inline void OPNAME ## _pixels4_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  876. OPNAME ## _pixels4_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
  877. }\
  878. \
  879. static inline void OPNAME ## _pixels2_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  880. OPNAME ## _pixels2_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
  881. }\
  882. \
  883. static inline void OPNAME ## _pixels2_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  884. OPNAME ## _pixels2_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
  885. }\
  886. \
  887. static inline void OPNAME ## _no_rnd_pixels8_l4(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\
  888. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  889. int i;\
  890. for(i=0; i<h; i++){\
  891. uint32_t a, b, c, d, l0, l1, h0, h1;\
  892. a= AV_RN32(&src1[i*src_stride1]);\
  893. b= AV_RN32(&src2[i*src_stride2]);\
  894. c= AV_RN32(&src3[i*src_stride3]);\
  895. d= AV_RN32(&src4[i*src_stride4]);\
  896. l0= (a&0x03030303UL)\
  897. + (b&0x03030303UL)\
  898. + 0x01010101UL;\
  899. h0= ((a&0xFCFCFCFCUL)>>2)\
  900. + ((b&0xFCFCFCFCUL)>>2);\
  901. l1= (c&0x03030303UL)\
  902. + (d&0x03030303UL);\
  903. h1= ((c&0xFCFCFCFCUL)>>2)\
  904. + ((d&0xFCFCFCFCUL)>>2);\
  905. OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  906. a= AV_RN32(&src1[i*src_stride1+4]);\
  907. b= AV_RN32(&src2[i*src_stride2+4]);\
  908. c= AV_RN32(&src3[i*src_stride3+4]);\
  909. d= AV_RN32(&src4[i*src_stride4+4]);\
  910. l0= (a&0x03030303UL)\
  911. + (b&0x03030303UL)\
  912. + 0x01010101UL;\
  913. h0= ((a&0xFCFCFCFCUL)>>2)\
  914. + ((b&0xFCFCFCFCUL)>>2);\
  915. l1= (c&0x03030303UL)\
  916. + (d&0x03030303UL);\
  917. h1= ((c&0xFCFCFCFCUL)>>2)\
  918. + ((d&0xFCFCFCFCUL)>>2);\
  919. OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  920. }\
  921. }\
  922. static inline void OPNAME ## _pixels16_l4(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\
  923. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  924. OPNAME ## _pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  925. OPNAME ## _pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  926. }\
  927. static inline void OPNAME ## _no_rnd_pixels16_l4(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\
  928. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  929. OPNAME ## _no_rnd_pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  930. OPNAME ## _no_rnd_pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  931. }\
  932. \
  933. static inline void OPNAME ## _pixels2_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  934. {\
  935. int i, a0, b0, a1, b1;\
  936. a0= pixels[0];\
  937. b0= pixels[1] + 2;\
  938. a0 += b0;\
  939. b0 += pixels[2];\
  940. \
  941. pixels+=line_size;\
  942. for(i=0; i<h; i+=2){\
  943. a1= pixels[0];\
  944. b1= pixels[1];\
  945. a1 += b1;\
  946. b1 += pixels[2];\
  947. \
  948. block[0]= (a1+a0)>>2; /* FIXME non put */\
  949. block[1]= (b1+b0)>>2;\
  950. \
  951. pixels+=line_size;\
  952. block +=line_size;\
  953. \
  954. a0= pixels[0];\
  955. b0= pixels[1] + 2;\
  956. a0 += b0;\
  957. b0 += pixels[2];\
  958. \
  959. block[0]= (a1+a0)>>2;\
  960. block[1]= (b1+b0)>>2;\
  961. pixels+=line_size;\
  962. block +=line_size;\
  963. }\
  964. }\
  965. \
  966. static inline void OPNAME ## _pixels4_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  967. {\
  968. int i;\
  969. const uint32_t a= AV_RN32(pixels );\
  970. const uint32_t b= AV_RN32(pixels+1);\
  971. uint32_t l0= (a&0x03030303UL)\
  972. + (b&0x03030303UL)\
  973. + 0x02020202UL;\
  974. uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
  975. + ((b&0xFCFCFCFCUL)>>2);\
  976. uint32_t l1,h1;\
  977. \
  978. pixels+=line_size;\
  979. for(i=0; i<h; i+=2){\
  980. uint32_t a= AV_RN32(pixels );\
  981. uint32_t b= AV_RN32(pixels+1);\
  982. l1= (a&0x03030303UL)\
  983. + (b&0x03030303UL);\
  984. h1= ((a&0xFCFCFCFCUL)>>2)\
  985. + ((b&0xFCFCFCFCUL)>>2);\
  986. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  987. pixels+=line_size;\
  988. block +=line_size;\
  989. a= AV_RN32(pixels );\
  990. b= AV_RN32(pixels+1);\
  991. l0= (a&0x03030303UL)\
  992. + (b&0x03030303UL)\
  993. + 0x02020202UL;\
  994. h0= ((a&0xFCFCFCFCUL)>>2)\
  995. + ((b&0xFCFCFCFCUL)>>2);\
  996. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  997. pixels+=line_size;\
  998. block +=line_size;\
  999. }\
  1000. }\
  1001. \
  1002. static inline void OPNAME ## _pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  1003. {\
  1004. int j;\
  1005. for(j=0; j<2; j++){\
  1006. int i;\
  1007. const uint32_t a= AV_RN32(pixels );\
  1008. const uint32_t b= AV_RN32(pixels+1);\
  1009. uint32_t l0= (a&0x03030303UL)\
  1010. + (b&0x03030303UL)\
  1011. + 0x02020202UL;\
  1012. uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
  1013. + ((b&0xFCFCFCFCUL)>>2);\
  1014. uint32_t l1,h1;\
  1015. \
  1016. pixels+=line_size;\
  1017. for(i=0; i<h; i+=2){\
  1018. uint32_t a= AV_RN32(pixels );\
  1019. uint32_t b= AV_RN32(pixels+1);\
  1020. l1= (a&0x03030303UL)\
  1021. + (b&0x03030303UL);\
  1022. h1= ((a&0xFCFCFCFCUL)>>2)\
  1023. + ((b&0xFCFCFCFCUL)>>2);\
  1024. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  1025. pixels+=line_size;\
  1026. block +=line_size;\
  1027. a= AV_RN32(pixels );\
  1028. b= AV_RN32(pixels+1);\
  1029. l0= (a&0x03030303UL)\
  1030. + (b&0x03030303UL)\
  1031. + 0x02020202UL;\
  1032. h0= ((a&0xFCFCFCFCUL)>>2)\
  1033. + ((b&0xFCFCFCFCUL)>>2);\
  1034. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  1035. pixels+=line_size;\
  1036. block +=line_size;\
  1037. }\
  1038. pixels+=4-line_size*(h+1);\
  1039. block +=4-line_size*h;\
  1040. }\
  1041. }\
  1042. \
  1043. static inline void OPNAME ## _no_rnd_pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  1044. {\
  1045. int j;\
  1046. for(j=0; j<2; j++){\
  1047. int i;\
  1048. const uint32_t a= AV_RN32(pixels );\
  1049. const uint32_t b= AV_RN32(pixels+1);\
  1050. uint32_t l0= (a&0x03030303UL)\
  1051. + (b&0x03030303UL)\
  1052. + 0x01010101UL;\
  1053. uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
  1054. + ((b&0xFCFCFCFCUL)>>2);\
  1055. uint32_t l1,h1;\
  1056. \
  1057. pixels+=line_size;\
  1058. for(i=0; i<h; i+=2){\
  1059. uint32_t a= AV_RN32(pixels );\
  1060. uint32_t b= AV_RN32(pixels+1);\
  1061. l1= (a&0x03030303UL)\
  1062. + (b&0x03030303UL);\
  1063. h1= ((a&0xFCFCFCFCUL)>>2)\
  1064. + ((b&0xFCFCFCFCUL)>>2);\
  1065. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  1066. pixels+=line_size;\
  1067. block +=line_size;\
  1068. a= AV_RN32(pixels );\
  1069. b= AV_RN32(pixels+1);\
  1070. l0= (a&0x03030303UL)\
  1071. + (b&0x03030303UL)\
  1072. + 0x01010101UL;\
  1073. h0= ((a&0xFCFCFCFCUL)>>2)\
  1074. + ((b&0xFCFCFCFCUL)>>2);\
  1075. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  1076. pixels+=line_size;\
  1077. block +=line_size;\
  1078. }\
  1079. pixels+=4-line_size*(h+1);\
  1080. block +=4-line_size*h;\
  1081. }\
  1082. }\
  1083. \
  1084. CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels8_c , 8)\
  1085. CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels8_x2_c , 8)\
  1086. CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels8_y2_c , 8)\
  1087. CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels8_xy2_c, 8)\
  1088. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_c , OPNAME ## _pixels8_c , 8)\
  1089. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels8_x2_c , 8)\
  1090. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels8_y2_c , 8)\
  1091. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels8_xy2_c, 8)\
  1092. #define op_avg(a, b) a = rnd_avg32(a, b)
  1093. #endif
  1094. #define op_put(a, b) a = b
  1095. PIXOP2(avg, op_avg)
  1096. PIXOP2(put, op_put)
  1097. #undef op_avg
  1098. #undef op_put
  1099. #define avg2(a,b) ((a+b+1)>>1)
  1100. #define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
  1101. static void put_no_rnd_pixels16_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){
  1102. put_no_rnd_pixels16_l2(dst, a, b, stride, stride, stride, h);
  1103. }
  1104. static void put_no_rnd_pixels8_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){
  1105. put_no_rnd_pixels8_l2(dst, a, b, stride, stride, stride, h);
  1106. }
  1107. static void gmc1_c(uint8_t *dst, uint8_t *src, int stride, int h, int x16, int y16, int rounder)
  1108. {
  1109. const int A=(16-x16)*(16-y16);
  1110. const int B=( x16)*(16-y16);
  1111. const int C=(16-x16)*( y16);
  1112. const int D=( x16)*( y16);
  1113. int i;
  1114. for(i=0; i<h; i++)
  1115. {
  1116. dst[0]= (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + rounder)>>8;
  1117. dst[1]= (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + rounder)>>8;
  1118. dst[2]= (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + rounder)>>8;
  1119. dst[3]= (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + rounder)>>8;
  1120. dst[4]= (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + rounder)>>8;
  1121. dst[5]= (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + rounder)>>8;
  1122. dst[6]= (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + rounder)>>8;
  1123. dst[7]= (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + rounder)>>8;
  1124. dst+= stride;
  1125. src+= stride;
  1126. }
  1127. }
  1128. void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
  1129. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
  1130. {
  1131. int y, vx, vy;
  1132. const int s= 1<<shift;
  1133. width--;
  1134. height--;
  1135. for(y=0; y<h; y++){
  1136. int x;
  1137. vx= ox;
  1138. vy= oy;
  1139. for(x=0; x<8; x++){ //XXX FIXME optimize
  1140. int src_x, src_y, frac_x, frac_y, index;
  1141. src_x= vx>>16;
  1142. src_y= vy>>16;
  1143. frac_x= src_x&(s-1);
  1144. frac_y= src_y&(s-1);
  1145. src_x>>=shift;
  1146. src_y>>=shift;
  1147. if((unsigned)src_x < width){
  1148. if((unsigned)src_y < height){
  1149. index= src_x + src_y*stride;
  1150. dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
  1151. + src[index +1]* frac_x )*(s-frac_y)
  1152. + ( src[index+stride ]*(s-frac_x)
  1153. + src[index+stride+1]* frac_x )* frac_y
  1154. + r)>>(shift*2);
  1155. }else{
  1156. index= src_x + av_clip(src_y, 0, height)*stride;
  1157. dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
  1158. + src[index +1]* frac_x )*s
  1159. + r)>>(shift*2);
  1160. }
  1161. }else{
  1162. if((unsigned)src_y < height){
  1163. index= av_clip(src_x, 0, width) + src_y*stride;
  1164. dst[y*stride + x]= ( ( src[index ]*(s-frac_y)
  1165. + src[index+stride ]* frac_y )*s
  1166. + r)>>(shift*2);
  1167. }else{
  1168. index= av_clip(src_x, 0, width) + av_clip(src_y, 0, height)*stride;
  1169. dst[y*stride + x]= src[index ];
  1170. }
  1171. }
  1172. vx+= dxx;
  1173. vy+= dyx;
  1174. }
  1175. ox += dxy;
  1176. oy += dyy;
  1177. }
  1178. }
  1179. static inline void put_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1180. switch(width){
  1181. case 2: put_pixels2_c (dst, src, stride, height); break;
  1182. case 4: put_pixels4_c (dst, src, stride, height); break;
  1183. case 8: put_pixels8_c (dst, src, stride, height); break;
  1184. case 16:put_pixels16_c(dst, src, stride, height); break;
  1185. }
  1186. }
  1187. static inline void put_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1188. int i,j;
  1189. for (i=0; i < height; i++) {
  1190. for (j=0; j < width; j++) {
  1191. dst[j] = (683*(2*src[j] + src[j+1] + 1)) >> 11;
  1192. }
  1193. src += stride;
  1194. dst += stride;
  1195. }
  1196. }
  1197. static inline void put_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1198. int i,j;
  1199. for (i=0; i < height; i++) {
  1200. for (j=0; j < width; j++) {
  1201. dst[j] = (683*(src[j] + 2*src[j+1] + 1)) >> 11;
  1202. }
  1203. src += stride;
  1204. dst += stride;
  1205. }
  1206. }
  1207. static inline void put_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1208. int i,j;
  1209. for (i=0; i < height; i++) {
  1210. for (j=0; j < width; j++) {
  1211. dst[j] = (683*(2*src[j] + src[j+stride] + 1)) >> 11;
  1212. }
  1213. src += stride;
  1214. dst += stride;
  1215. }
  1216. }
  1217. static inline void put_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1218. int i,j;
  1219. for (i=0; i < height; i++) {
  1220. for (j=0; j < width; j++) {
  1221. dst[j] = (2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15;
  1222. }
  1223. src += stride;
  1224. dst += stride;
  1225. }
  1226. }
  1227. static inline void put_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1228. int i,j;
  1229. for (i=0; i < height; i++) {
  1230. for (j=0; j < width; j++) {
  1231. dst[j] = (2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
  1232. }
  1233. src += stride;
  1234. dst += stride;
  1235. }
  1236. }
  1237. static inline void put_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1238. int i,j;
  1239. for (i=0; i < height; i++) {
  1240. for (j=0; j < width; j++) {
  1241. dst[j] = (683*(src[j] + 2*src[j+stride] + 1)) >> 11;
  1242. }
  1243. src += stride;
  1244. dst += stride;
  1245. }
  1246. }
  1247. static inline void put_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1248. int i,j;
  1249. for (i=0; i < height; i++) {
  1250. for (j=0; j < width; j++) {
  1251. dst[j] = (2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
  1252. }
  1253. src += stride;
  1254. dst += stride;
  1255. }
  1256. }
  1257. static inline void put_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1258. int i,j;
  1259. for (i=0; i < height; i++) {
  1260. for (j=0; j < width; j++) {
  1261. dst[j] = (2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15;
  1262. }
  1263. src += stride;
  1264. dst += stride;
  1265. }
  1266. }
  1267. static inline void avg_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1268. switch(width){
  1269. case 2: avg_pixels2_c (dst, src, stride, height); break;
  1270. case 4: avg_pixels4_c (dst, src, stride, height); break;
  1271. case 8: avg_pixels8_c (dst, src, stride, height); break;
  1272. case 16:avg_pixels16_c(dst, src, stride, height); break;
  1273. }
  1274. }
  1275. static inline void avg_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1276. int i,j;
  1277. for (i=0; i < height; i++) {
  1278. for (j=0; j < width; j++) {
  1279. dst[j] = (dst[j] + ((683*(2*src[j] + src[j+1] + 1)) >> 11) + 1) >> 1;
  1280. }
  1281. src += stride;
  1282. dst += stride;
  1283. }
  1284. }
  1285. static inline void avg_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1286. int i,j;
  1287. for (i=0; i < height; i++) {
  1288. for (j=0; j < width; j++) {
  1289. dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+1] + 1)) >> 11) + 1) >> 1;
  1290. }
  1291. src += stride;
  1292. dst += stride;
  1293. }
  1294. }
  1295. static inline void avg_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1296. int i,j;
  1297. for (i=0; i < height; i++) {
  1298. for (j=0; j < width; j++) {
  1299. dst[j] = (dst[j] + ((683*(2*src[j] + src[j+stride] + 1)) >> 11) + 1) >> 1;
  1300. }
  1301. src += stride;
  1302. dst += stride;
  1303. }
  1304. }
  1305. static inline void avg_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1306. int i,j;
  1307. for (i=0; i < height; i++) {
  1308. for (j=0; j < width; j++) {
  1309. 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;
  1310. }
  1311. src += stride;
  1312. dst += stride;
  1313. }
  1314. }
  1315. static inline void avg_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1316. int i,j;
  1317. for (i=0; i < height; i++) {
  1318. for (j=0; j < width; j++) {
  1319. 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;
  1320. }
  1321. src += stride;
  1322. dst += stride;
  1323. }
  1324. }
  1325. static inline void avg_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1326. int i,j;
  1327. for (i=0; i < height; i++) {
  1328. for (j=0; j < width; j++) {
  1329. dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+stride] + 1)) >> 11) + 1) >> 1;
  1330. }
  1331. src += stride;
  1332. dst += stride;
  1333. }
  1334. }
  1335. static inline void avg_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1336. int i,j;
  1337. for (i=0; i < height; i++) {
  1338. for (j=0; j < width; j++) {
  1339. 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;
  1340. }
  1341. src += stride;
  1342. dst += stride;
  1343. }
  1344. }
  1345. static inline void avg_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
  1346. int i,j;
  1347. for (i=0; i < height; i++) {
  1348. for (j=0; j < width; j++) {
  1349. 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;
  1350. }
  1351. src += stride;
  1352. dst += stride;
  1353. }
  1354. }
  1355. #if 0
  1356. #define TPEL_WIDTH(width)\
  1357. static void put_tpel_pixels ## width ## _mc00_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1358. void put_tpel_pixels_mc00_c(dst, src, stride, width, height);}\
  1359. static void put_tpel_pixels ## width ## _mc10_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1360. void put_tpel_pixels_mc10_c(dst, src, stride, width, height);}\
  1361. static void put_tpel_pixels ## width ## _mc20_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1362. void put_tpel_pixels_mc20_c(dst, src, stride, width, height);}\
  1363. static void put_tpel_pixels ## width ## _mc01_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1364. void put_tpel_pixels_mc01_c(dst, src, stride, width, height);}\
  1365. static void put_tpel_pixels ## width ## _mc11_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1366. void put_tpel_pixels_mc11_c(dst, src, stride, width, height);}\
  1367. static void put_tpel_pixels ## width ## _mc21_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1368. void put_tpel_pixels_mc21_c(dst, src, stride, width, height);}\
  1369. static void put_tpel_pixels ## width ## _mc02_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1370. void put_tpel_pixels_mc02_c(dst, src, stride, width, height);}\
  1371. static void put_tpel_pixels ## width ## _mc12_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1372. void put_tpel_pixels_mc12_c(dst, src, stride, width, height);}\
  1373. static void put_tpel_pixels ## width ## _mc22_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
  1374. void put_tpel_pixels_mc22_c(dst, src, stride, width, height);}
  1375. #endif
  1376. #define H264_CHROMA_MC(OPNAME, OP)\
  1377. static void OPNAME ## h264_chroma_mc2_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
  1378. const int A=(8-x)*(8-y);\
  1379. const int B=( x)*(8-y);\
  1380. const int C=(8-x)*( y);\
  1381. const int D=( x)*( y);\
  1382. int i;\
  1383. \
  1384. assert(x<8 && y<8 && x>=0 && y>=0);\
  1385. \
  1386. if(D){\
  1387. for(i=0; i<h; i++){\
  1388. OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
  1389. OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
  1390. dst+= stride;\
  1391. src+= stride;\
  1392. }\
  1393. }else{\
  1394. const int E= B+C;\
  1395. const int step= C ? stride : 1;\
  1396. for(i=0; i<h; i++){\
  1397. OP(dst[0], (A*src[0] + E*src[step+0]));\
  1398. OP(dst[1], (A*src[1] + E*src[step+1]));\
  1399. dst+= stride;\
  1400. src+= stride;\
  1401. }\
  1402. }\
  1403. }\
  1404. \
  1405. static void OPNAME ## h264_chroma_mc4_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
  1406. const int A=(8-x)*(8-y);\
  1407. const int B=( x)*(8-y);\
  1408. const int C=(8-x)*( y);\
  1409. const int D=( x)*( y);\
  1410. int i;\
  1411. \
  1412. assert(x<8 && y<8 && x>=0 && y>=0);\
  1413. \
  1414. if(D){\
  1415. for(i=0; i<h; i++){\
  1416. OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
  1417. OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
  1418. OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
  1419. OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
  1420. dst+= stride;\
  1421. src+= stride;\
  1422. }\
  1423. }else{\
  1424. const int E= B+C;\
  1425. const int step= C ? stride : 1;\
  1426. for(i=0; i<h; i++){\
  1427. OP(dst[0], (A*src[0] + E*src[step+0]));\
  1428. OP(dst[1], (A*src[1] + E*src[step+1]));\
  1429. OP(dst[2], (A*src[2] + E*src[step+2]));\
  1430. OP(dst[3], (A*src[3] + E*src[step+3]));\
  1431. dst+= stride;\
  1432. src+= stride;\
  1433. }\
  1434. }\
  1435. }\
  1436. \
  1437. static void OPNAME ## h264_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
  1438. const int A=(8-x)*(8-y);\
  1439. const int B=( x)*(8-y);\
  1440. const int C=(8-x)*( y);\
  1441. const int D=( x)*( y);\
  1442. int i;\
  1443. \
  1444. assert(x<8 && y<8 && x>=0 && y>=0);\
  1445. \
  1446. if(D){\
  1447. for(i=0; i<h; i++){\
  1448. OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
  1449. OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
  1450. OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
  1451. OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
  1452. OP(dst[4], (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5]));\
  1453. OP(dst[5], (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6]));\
  1454. OP(dst[6], (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7]));\
  1455. OP(dst[7], (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8]));\
  1456. dst+= stride;\
  1457. src+= stride;\
  1458. }\
  1459. }else{\
  1460. const int E= B+C;\
  1461. const int step= C ? stride : 1;\
  1462. for(i=0; i<h; i++){\
  1463. OP(dst[0], (A*src[0] + E*src[step+0]));\
  1464. OP(dst[1], (A*src[1] + E*src[step+1]));\
  1465. OP(dst[2], (A*src[2] + E*src[step+2]));\
  1466. OP(dst[3], (A*src[3] + E*src[step+3]));\
  1467. OP(dst[4], (A*src[4] + E*src[step+4]));\
  1468. OP(dst[5], (A*src[5] + E*src[step+5]));\
  1469. OP(dst[6], (A*src[6] + E*src[step+6]));\
  1470. OP(dst[7], (A*src[7] + E*src[step+7]));\
  1471. dst+= stride;\
  1472. src+= stride;\
  1473. }\
  1474. }\
  1475. }
  1476. #define op_avg(a, b) a = (((a)+(((b) + 32)>>6)+1)>>1)
  1477. #define op_put(a, b) a = (((b) + 32)>>6)
  1478. H264_CHROMA_MC(put_ , op_put)
  1479. H264_CHROMA_MC(avg_ , op_avg)
  1480. #undef op_avg
  1481. #undef op_put
  1482. static void put_no_rnd_vc1_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){
  1483. const int A=(8-x)*(8-y);
  1484. const int B=( x)*(8-y);
  1485. const int C=(8-x)*( y);
  1486. const int D=( x)*( y);
  1487. int i;
  1488. assert(x<8 && y<8 && x>=0 && y>=0);
  1489. for(i=0; i<h; i++)
  1490. {
  1491. dst[0] = (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6;
  1492. dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6;
  1493. dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6;
  1494. dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6;
  1495. dst[4] = (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6;
  1496. dst[5] = (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6;
  1497. dst[6] = (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6;
  1498. dst[7] = (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6;
  1499. dst+= stride;
  1500. src+= stride;
  1501. }
  1502. }
  1503. static void avg_no_rnd_vc1_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){
  1504. const int A=(8-x)*(8-y);
  1505. const int B=( x)*(8-y);
  1506. const int C=(8-x)*( y);
  1507. const int D=( x)*( y);
  1508. int i;
  1509. assert(x<8 && y<8 && x>=0 && y>=0);
  1510. for(i=0; i<h; i++)
  1511. {
  1512. dst[0] = avg2(dst[0], ((A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6));
  1513. dst[1] = avg2(dst[1], ((A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6));
  1514. dst[2] = avg2(dst[2], ((A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6));
  1515. dst[3] = avg2(dst[3], ((A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6));
  1516. dst[4] = avg2(dst[4], ((A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6));
  1517. dst[5] = avg2(dst[5], ((A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6));
  1518. dst[6] = avg2(dst[6], ((A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6));
  1519. dst[7] = avg2(dst[7], ((A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6));
  1520. dst+= stride;
  1521. src+= stride;
  1522. }
  1523. }
  1524. #define QPEL_MC(r, OPNAME, RND, OP) \
  1525. static void OPNAME ## mpeg4_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  1526. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  1527. int i;\
  1528. for(i=0; i<h; i++)\
  1529. {\
  1530. OP(dst[0], (src[0]+src[1])*20 - (src[0]+src[2])*6 + (src[1]+src[3])*3 - (src[2]+src[4]));\
  1531. OP(dst[1], (src[1]+src[2])*20 - (src[0]+src[3])*6 + (src[0]+src[4])*3 - (src[1]+src[5]));\
  1532. OP(dst[2], (src[2]+src[3])*20 - (src[1]+src[4])*6 + (src[0]+src[5])*3 - (src[0]+src[6]));\
  1533. OP(dst[3], (src[3]+src[4])*20 - (src[2]+src[5])*6 + (src[1]+src[6])*3 - (src[0]+src[7]));\
  1534. OP(dst[4], (src[4]+src[5])*20 - (src[3]+src[6])*6 + (src[2]+src[7])*3 - (src[1]+src[8]));\
  1535. OP(dst[5], (src[5]+src[6])*20 - (src[4]+src[7])*6 + (src[3]+src[8])*3 - (src[2]+src[8]));\
  1536. OP(dst[6], (src[6]+src[7])*20 - (src[5]+src[8])*6 + (src[4]+src[8])*3 - (src[3]+src[7]));\
  1537. OP(dst[7], (src[7]+src[8])*20 - (src[6]+src[8])*6 + (src[5]+src[7])*3 - (src[4]+src[6]));\
  1538. dst+=dstStride;\
  1539. src+=srcStride;\
  1540. }\
  1541. }\
  1542. \
  1543. static void OPNAME ## mpeg4_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1544. const int w=8;\
  1545. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  1546. int i;\
  1547. for(i=0; i<w; i++)\
  1548. {\
  1549. const int src0= src[0*srcStride];\
  1550. const int src1= src[1*srcStride];\
  1551. const int src2= src[2*srcStride];\
  1552. const int src3= src[3*srcStride];\
  1553. const int src4= src[4*srcStride];\
  1554. const int src5= src[5*srcStride];\
  1555. const int src6= src[6*srcStride];\
  1556. const int src7= src[7*srcStride];\
  1557. const int src8= src[8*srcStride];\
  1558. OP(dst[0*dstStride], (src0+src1)*20 - (src0+src2)*6 + (src1+src3)*3 - (src2+src4));\
  1559. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*6 + (src0+src4)*3 - (src1+src5));\
  1560. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*6 + (src0+src5)*3 - (src0+src6));\
  1561. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*6 + (src1+src6)*3 - (src0+src7));\
  1562. OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*6 + (src2+src7)*3 - (src1+src8));\
  1563. OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*6 + (src3+src8)*3 - (src2+src8));\
  1564. OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*6 + (src4+src8)*3 - (src3+src7));\
  1565. OP(dst[7*dstStride], (src7+src8)*20 - (src6+src8)*6 + (src5+src7)*3 - (src4+src6));\
  1566. dst++;\
  1567. src++;\
  1568. }\
  1569. }\
  1570. \
  1571. static void OPNAME ## mpeg4_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  1572. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  1573. int i;\
  1574. \
  1575. for(i=0; i<h; i++)\
  1576. {\
  1577. OP(dst[ 0], (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]));\
  1578. OP(dst[ 1], (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]));\
  1579. OP(dst[ 2], (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]));\
  1580. OP(dst[ 3], (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]));\
  1581. OP(dst[ 4], (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]));\
  1582. OP(dst[ 5], (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]));\
  1583. OP(dst[ 6], (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]));\
  1584. OP(dst[ 7], (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]));\
  1585. OP(dst[ 8], (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]));\
  1586. OP(dst[ 9], (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]));\
  1587. OP(dst[10], (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]));\
  1588. OP(dst[11], (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]));\
  1589. OP(dst[12], (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]));\
  1590. OP(dst[13], (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]));\
  1591. OP(dst[14], (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]));\
  1592. OP(dst[15], (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]));\
  1593. dst+=dstStride;\
  1594. src+=srcStride;\
  1595. }\
  1596. }\
  1597. \
  1598. static void OPNAME ## mpeg4_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1599. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  1600. int i;\
  1601. const int w=16;\
  1602. for(i=0; i<w; i++)\
  1603. {\
  1604. const int src0= src[0*srcStride];\
  1605. const int src1= src[1*srcStride];\
  1606. const int src2= src[2*srcStride];\
  1607. const int src3= src[3*srcStride];\
  1608. const int src4= src[4*srcStride];\
  1609. const int src5= src[5*srcStride];\
  1610. const int src6= src[6*srcStride];\
  1611. const int src7= src[7*srcStride];\
  1612. const int src8= src[8*srcStride];\
  1613. const int src9= src[9*srcStride];\
  1614. const int src10= src[10*srcStride];\
  1615. const int src11= src[11*srcStride];\
  1616. const int src12= src[12*srcStride];\
  1617. const int src13= src[13*srcStride];\
  1618. const int src14= src[14*srcStride];\
  1619. const int src15= src[15*srcStride];\
  1620. const int src16= src[16*srcStride];\
  1621. OP(dst[ 0*dstStride], (src0 +src1 )*20 - (src0 +src2 )*6 + (src1 +src3 )*3 - (src2 +src4 ));\
  1622. OP(dst[ 1*dstStride], (src1 +src2 )*20 - (src0 +src3 )*6 + (src0 +src4 )*3 - (src1 +src5 ));\
  1623. OP(dst[ 2*dstStride], (src2 +src3 )*20 - (src1 +src4 )*6 + (src0 +src5 )*3 - (src0 +src6 ));\
  1624. OP(dst[ 3*dstStride], (src3 +src4 )*20 - (src2 +src5 )*6 + (src1 +src6 )*3 - (src0 +src7 ));\
  1625. OP(dst[ 4*dstStride], (src4 +src5 )*20 - (src3 +src6 )*6 + (src2 +src7 )*3 - (src1 +src8 ));\
  1626. OP(dst[ 5*dstStride], (src5 +src6 )*20 - (src4 +src7 )*6 + (src3 +src8 )*3 - (src2 +src9 ));\
  1627. OP(dst[ 6*dstStride], (src6 +src7 )*20 - (src5 +src8 )*6 + (src4 +src9 )*3 - (src3 +src10));\
  1628. OP(dst[ 7*dstStride], (src7 +src8 )*20 - (src6 +src9 )*6 + (src5 +src10)*3 - (src4 +src11));\
  1629. OP(dst[ 8*dstStride], (src8 +src9 )*20 - (src7 +src10)*6 + (src6 +src11)*3 - (src5 +src12));\
  1630. OP(dst[ 9*dstStride], (src9 +src10)*20 - (src8 +src11)*6 + (src7 +src12)*3 - (src6 +src13));\
  1631. OP(dst[10*dstStride], (src10+src11)*20 - (src9 +src12)*6 + (src8 +src13)*3 - (src7 +src14));\
  1632. OP(dst[11*dstStride], (src11+src12)*20 - (src10+src13)*6 + (src9 +src14)*3 - (src8 +src15));\
  1633. OP(dst[12*dstStride], (src12+src13)*20 - (src11+src14)*6 + (src10+src15)*3 - (src9 +src16));\
  1634. OP(dst[13*dstStride], (src13+src14)*20 - (src12+src15)*6 + (src11+src16)*3 - (src10+src16));\
  1635. OP(dst[14*dstStride], (src14+src15)*20 - (src13+src16)*6 + (src12+src16)*3 - (src11+src15));\
  1636. OP(dst[15*dstStride], (src15+src16)*20 - (src14+src16)*6 + (src13+src15)*3 - (src12+src14));\
  1637. dst++;\
  1638. src++;\
  1639. }\
  1640. }\
  1641. \
  1642. static void OPNAME ## qpel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
  1643. OPNAME ## pixels8_c(dst, src, stride, 8);\
  1644. }\
  1645. \
  1646. static void OPNAME ## qpel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  1647. uint8_t half[64];\
  1648. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  1649. OPNAME ## pixels8_l2(dst, src, half, stride, stride, 8, 8);\
  1650. }\
  1651. \
  1652. static void OPNAME ## qpel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  1653. OPNAME ## mpeg4_qpel8_h_lowpass(dst, src, stride, stride, 8);\
  1654. }\
  1655. \
  1656. static void OPNAME ## qpel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  1657. uint8_t half[64];\
  1658. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  1659. OPNAME ## pixels8_l2(dst, src+1, half, stride, stride, 8, 8);\
  1660. }\
  1661. \
  1662. static void OPNAME ## qpel8_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  1663. uint8_t full[16*9];\
  1664. uint8_t half[64];\
  1665. copy_block9(full, src, 16, stride, 9);\
  1666. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
  1667. OPNAME ## pixels8_l2(dst, full, half, stride, 16, 8, 8);\
  1668. }\
  1669. \
  1670. static void OPNAME ## qpel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  1671. uint8_t full[16*9];\
  1672. copy_block9(full, src, 16, stride, 9);\
  1673. OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);\
  1674. }\
  1675. \
  1676. static void OPNAME ## qpel8_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  1677. uint8_t full[16*9];\
  1678. uint8_t half[64];\
  1679. copy_block9(full, src, 16, stride, 9);\
  1680. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
  1681. OPNAME ## pixels8_l2(dst, full+16, half, stride, 16, 8, 8);\
  1682. }\
  1683. void ff_ ## OPNAME ## qpel8_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1684. uint8_t full[16*9];\
  1685. uint8_t halfH[72];\
  1686. uint8_t halfV[64];\
  1687. uint8_t halfHV[64];\
  1688. copy_block9(full, src, 16, stride, 9);\
  1689. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1690. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  1691. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1692. OPNAME ## pixels8_l4(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1693. }\
  1694. static void OPNAME ## qpel8_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  1695. uint8_t full[16*9];\
  1696. uint8_t halfH[72];\
  1697. uint8_t halfHV[64];\
  1698. copy_block9(full, src, 16, stride, 9);\
  1699. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1700. put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
  1701. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1702. OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
  1703. }\
  1704. void ff_ ## OPNAME ## qpel8_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1705. uint8_t full[16*9];\
  1706. uint8_t halfH[72];\
  1707. uint8_t halfV[64];\
  1708. uint8_t halfHV[64];\
  1709. copy_block9(full, src, 16, stride, 9);\
  1710. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1711. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  1712. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1713. OPNAME ## pixels8_l4(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1714. }\
  1715. static void OPNAME ## qpel8_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  1716. uint8_t full[16*9];\
  1717. uint8_t halfH[72];\
  1718. uint8_t halfHV[64];\
  1719. copy_block9(full, src, 16, stride, 9);\
  1720. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1721. put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
  1722. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1723. OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
  1724. }\
  1725. void ff_ ## OPNAME ## qpel8_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1726. uint8_t full[16*9];\
  1727. uint8_t halfH[72];\
  1728. uint8_t halfV[64];\
  1729. uint8_t halfHV[64];\
  1730. copy_block9(full, src, 16, stride, 9);\
  1731. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1732. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  1733. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1734. OPNAME ## pixels8_l4(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1735. }\
  1736. static void OPNAME ## qpel8_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  1737. uint8_t full[16*9];\
  1738. uint8_t halfH[72];\
  1739. uint8_t halfHV[64];\
  1740. copy_block9(full, src, 16, stride, 9);\
  1741. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1742. put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
  1743. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1744. OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  1745. }\
  1746. void ff_ ## OPNAME ## qpel8_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1747. uint8_t full[16*9];\
  1748. uint8_t halfH[72];\
  1749. uint8_t halfV[64];\
  1750. uint8_t halfHV[64];\
  1751. copy_block9(full, src, 16, stride, 9);\
  1752. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full , 8, 16, 9);\
  1753. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  1754. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1755. OPNAME ## pixels8_l4(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1756. }\
  1757. static void OPNAME ## qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  1758. uint8_t full[16*9];\
  1759. uint8_t halfH[72];\
  1760. uint8_t halfHV[64];\
  1761. copy_block9(full, src, 16, stride, 9);\
  1762. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1763. put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
  1764. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1765. OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  1766. }\
  1767. static void OPNAME ## qpel8_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  1768. uint8_t halfH[72];\
  1769. uint8_t halfHV[64];\
  1770. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1771. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1772. OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
  1773. }\
  1774. static void OPNAME ## qpel8_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  1775. uint8_t halfH[72];\
  1776. uint8_t halfHV[64];\
  1777. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1778. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1779. OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  1780. }\
  1781. void ff_ ## OPNAME ## qpel8_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1782. uint8_t full[16*9];\
  1783. uint8_t halfH[72];\
  1784. uint8_t halfV[64];\
  1785. uint8_t halfHV[64];\
  1786. copy_block9(full, src, 16, stride, 9);\
  1787. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1788. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  1789. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1790. OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
  1791. }\
  1792. static void OPNAME ## qpel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  1793. uint8_t full[16*9];\
  1794. uint8_t halfH[72];\
  1795. copy_block9(full, src, 16, stride, 9);\
  1796. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1797. put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
  1798. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1799. }\
  1800. void ff_ ## OPNAME ## qpel8_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1801. uint8_t full[16*9];\
  1802. uint8_t halfH[72];\
  1803. uint8_t halfV[64];\
  1804. uint8_t halfHV[64];\
  1805. copy_block9(full, src, 16, stride, 9);\
  1806. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1807. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  1808. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1809. OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
  1810. }\
  1811. static void OPNAME ## qpel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  1812. uint8_t full[16*9];\
  1813. uint8_t halfH[72];\
  1814. copy_block9(full, src, 16, stride, 9);\
  1815. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1816. put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
  1817. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1818. }\
  1819. static void OPNAME ## qpel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  1820. uint8_t halfH[72];\
  1821. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1822. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1823. }\
  1824. static void OPNAME ## qpel16_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
  1825. OPNAME ## pixels16_c(dst, src, stride, 16);\
  1826. }\
  1827. \
  1828. static void OPNAME ## qpel16_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  1829. uint8_t half[256];\
  1830. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  1831. OPNAME ## pixels16_l2(dst, src, half, stride, stride, 16, 16);\
  1832. }\
  1833. \
  1834. static void OPNAME ## qpel16_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  1835. OPNAME ## mpeg4_qpel16_h_lowpass(dst, src, stride, stride, 16);\
  1836. }\
  1837. \
  1838. static void OPNAME ## qpel16_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  1839. uint8_t half[256];\
  1840. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  1841. OPNAME ## pixels16_l2(dst, src+1, half, stride, stride, 16, 16);\
  1842. }\
  1843. \
  1844. static void OPNAME ## qpel16_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  1845. uint8_t full[24*17];\
  1846. uint8_t half[256];\
  1847. copy_block17(full, src, 24, stride, 17);\
  1848. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
  1849. OPNAME ## pixels16_l2(dst, full, half, stride, 24, 16, 16);\
  1850. }\
  1851. \
  1852. static void OPNAME ## qpel16_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  1853. uint8_t full[24*17];\
  1854. copy_block17(full, src, 24, stride, 17);\
  1855. OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);\
  1856. }\
  1857. \
  1858. static void OPNAME ## qpel16_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  1859. uint8_t full[24*17];\
  1860. uint8_t half[256];\
  1861. copy_block17(full, src, 24, stride, 17);\
  1862. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
  1863. OPNAME ## pixels16_l2(dst, full+24, half, stride, 24, 16, 16);\
  1864. }\
  1865. void ff_ ## OPNAME ## qpel16_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1866. uint8_t full[24*17];\
  1867. uint8_t halfH[272];\
  1868. uint8_t halfV[256];\
  1869. uint8_t halfHV[256];\
  1870. copy_block17(full, src, 24, stride, 17);\
  1871. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1872. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1873. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1874. OPNAME ## pixels16_l4(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1875. }\
  1876. static void OPNAME ## qpel16_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  1877. uint8_t full[24*17];\
  1878. uint8_t halfH[272];\
  1879. uint8_t halfHV[256];\
  1880. copy_block17(full, src, 24, stride, 17);\
  1881. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1882. put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
  1883. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1884. OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
  1885. }\
  1886. void ff_ ## OPNAME ## qpel16_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1887. uint8_t full[24*17];\
  1888. uint8_t halfH[272];\
  1889. uint8_t halfV[256];\
  1890. uint8_t halfHV[256];\
  1891. copy_block17(full, src, 24, stride, 17);\
  1892. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1893. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1894. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1895. OPNAME ## pixels16_l4(dst, full+1, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1896. }\
  1897. static void OPNAME ## qpel16_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  1898. uint8_t full[24*17];\
  1899. uint8_t halfH[272];\
  1900. uint8_t halfHV[256];\
  1901. copy_block17(full, src, 24, stride, 17);\
  1902. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1903. put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
  1904. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1905. OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
  1906. }\
  1907. void ff_ ## OPNAME ## qpel16_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1908. uint8_t full[24*17];\
  1909. uint8_t halfH[272];\
  1910. uint8_t halfV[256];\
  1911. uint8_t halfHV[256];\
  1912. copy_block17(full, src, 24, stride, 17);\
  1913. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1914. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1915. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1916. OPNAME ## pixels16_l4(dst, full+24, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1917. }\
  1918. static void OPNAME ## qpel16_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  1919. uint8_t full[24*17];\
  1920. uint8_t halfH[272];\
  1921. uint8_t halfHV[256];\
  1922. copy_block17(full, src, 24, stride, 17);\
  1923. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1924. put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
  1925. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1926. OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1927. }\
  1928. void ff_ ## OPNAME ## qpel16_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1929. uint8_t full[24*17];\
  1930. uint8_t halfH[272];\
  1931. uint8_t halfV[256];\
  1932. uint8_t halfHV[256];\
  1933. copy_block17(full, src, 24, stride, 17);\
  1934. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full , 16, 24, 17);\
  1935. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1936. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1937. OPNAME ## pixels16_l4(dst, full+25, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1938. }\
  1939. static void OPNAME ## qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  1940. uint8_t full[24*17];\
  1941. uint8_t halfH[272];\
  1942. uint8_t halfHV[256];\
  1943. copy_block17(full, src, 24, stride, 17);\
  1944. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1945. put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
  1946. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1947. OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1948. }\
  1949. static void OPNAME ## qpel16_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  1950. uint8_t halfH[272];\
  1951. uint8_t halfHV[256];\
  1952. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1953. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1954. OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
  1955. }\
  1956. static void OPNAME ## qpel16_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  1957. uint8_t halfH[272];\
  1958. uint8_t halfHV[256];\
  1959. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1960. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1961. OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1962. }\
  1963. void ff_ ## OPNAME ## qpel16_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1964. uint8_t full[24*17];\
  1965. uint8_t halfH[272];\
  1966. uint8_t halfV[256];\
  1967. uint8_t halfHV[256];\
  1968. copy_block17(full, src, 24, stride, 17);\
  1969. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1970. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1971. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1972. OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
  1973. }\
  1974. static void OPNAME ## qpel16_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  1975. uint8_t full[24*17];\
  1976. uint8_t halfH[272];\
  1977. copy_block17(full, src, 24, stride, 17);\
  1978. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1979. put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
  1980. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1981. }\
  1982. void ff_ ## OPNAME ## qpel16_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1983. uint8_t full[24*17];\
  1984. uint8_t halfH[272];\
  1985. uint8_t halfV[256];\
  1986. uint8_t halfHV[256];\
  1987. copy_block17(full, src, 24, stride, 17);\
  1988. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1989. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1990. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1991. OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
  1992. }\
  1993. static void OPNAME ## qpel16_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  1994. uint8_t full[24*17];\
  1995. uint8_t halfH[272];\
  1996. copy_block17(full, src, 24, stride, 17);\
  1997. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1998. put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
  1999. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  2000. }\
  2001. static void OPNAME ## qpel16_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  2002. uint8_t halfH[272];\
  2003. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  2004. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  2005. }
  2006. #define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
  2007. #define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1)
  2008. #define op_put(a, b) a = cm[((b) + 16)>>5]
  2009. #define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5]
  2010. QPEL_MC(0, put_ , _ , op_put)
  2011. QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd)
  2012. QPEL_MC(0, avg_ , _ , op_avg)
  2013. //QPEL_MC(1, avg_no_rnd , _ , op_avg)
  2014. #undef op_avg
  2015. #undef op_avg_no_rnd
  2016. #undef op_put
  2017. #undef op_put_no_rnd
  2018. #if 1
  2019. #define H264_LOWPASS(OPNAME, OP, OP2) \
  2020. static av_unused void OPNAME ## h264_qpel2_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2021. const int h=2;\
  2022. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2023. int i;\
  2024. for(i=0; i<h; i++)\
  2025. {\
  2026. OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
  2027. OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
  2028. dst+=dstStride;\
  2029. src+=srcStride;\
  2030. }\
  2031. }\
  2032. \
  2033. static av_unused void OPNAME ## h264_qpel2_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2034. const int w=2;\
  2035. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2036. int i;\
  2037. for(i=0; i<w; i++)\
  2038. {\
  2039. const int srcB= src[-2*srcStride];\
  2040. const int srcA= src[-1*srcStride];\
  2041. const int src0= src[0 *srcStride];\
  2042. const int src1= src[1 *srcStride];\
  2043. const int src2= src[2 *srcStride];\
  2044. const int src3= src[3 *srcStride];\
  2045. const int src4= src[4 *srcStride];\
  2046. OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
  2047. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
  2048. dst++;\
  2049. src++;\
  2050. }\
  2051. }\
  2052. \
  2053. static av_unused void OPNAME ## h264_qpel2_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  2054. const int h=2;\
  2055. const int w=2;\
  2056. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2057. int i;\
  2058. src -= 2*srcStride;\
  2059. for(i=0; i<h+5; i++)\
  2060. {\
  2061. tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
  2062. tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
  2063. tmp+=tmpStride;\
  2064. src+=srcStride;\
  2065. }\
  2066. tmp -= tmpStride*(h+5-2);\
  2067. for(i=0; i<w; i++)\
  2068. {\
  2069. const int tmpB= tmp[-2*tmpStride];\
  2070. const int tmpA= tmp[-1*tmpStride];\
  2071. const int tmp0= tmp[0 *tmpStride];\
  2072. const int tmp1= tmp[1 *tmpStride];\
  2073. const int tmp2= tmp[2 *tmpStride];\
  2074. const int tmp3= tmp[3 *tmpStride];\
  2075. const int tmp4= tmp[4 *tmpStride];\
  2076. OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
  2077. OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
  2078. dst++;\
  2079. tmp++;\
  2080. }\
  2081. }\
  2082. static void OPNAME ## h264_qpel4_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2083. const int h=4;\
  2084. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2085. int i;\
  2086. for(i=0; i<h; i++)\
  2087. {\
  2088. OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
  2089. OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
  2090. OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]));\
  2091. OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]));\
  2092. dst+=dstStride;\
  2093. src+=srcStride;\
  2094. }\
  2095. }\
  2096. \
  2097. static void OPNAME ## h264_qpel4_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2098. const int w=4;\
  2099. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2100. int i;\
  2101. for(i=0; i<w; i++)\
  2102. {\
  2103. const int srcB= src[-2*srcStride];\
  2104. const int srcA= src[-1*srcStride];\
  2105. const int src0= src[0 *srcStride];\
  2106. const int src1= src[1 *srcStride];\
  2107. const int src2= src[2 *srcStride];\
  2108. const int src3= src[3 *srcStride];\
  2109. const int src4= src[4 *srcStride];\
  2110. const int src5= src[5 *srcStride];\
  2111. const int src6= src[6 *srcStride];\
  2112. OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
  2113. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
  2114. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
  2115. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
  2116. dst++;\
  2117. src++;\
  2118. }\
  2119. }\
  2120. \
  2121. static void OPNAME ## h264_qpel4_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  2122. const int h=4;\
  2123. const int w=4;\
  2124. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2125. int i;\
  2126. src -= 2*srcStride;\
  2127. for(i=0; i<h+5; i++)\
  2128. {\
  2129. tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
  2130. tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
  2131. tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]);\
  2132. tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]);\
  2133. tmp+=tmpStride;\
  2134. src+=srcStride;\
  2135. }\
  2136. tmp -= tmpStride*(h+5-2);\
  2137. for(i=0; i<w; i++)\
  2138. {\
  2139. const int tmpB= tmp[-2*tmpStride];\
  2140. const int tmpA= tmp[-1*tmpStride];\
  2141. const int tmp0= tmp[0 *tmpStride];\
  2142. const int tmp1= tmp[1 *tmpStride];\
  2143. const int tmp2= tmp[2 *tmpStride];\
  2144. const int tmp3= tmp[3 *tmpStride];\
  2145. const int tmp4= tmp[4 *tmpStride];\
  2146. const int tmp5= tmp[5 *tmpStride];\
  2147. const int tmp6= tmp[6 *tmpStride];\
  2148. OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
  2149. OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
  2150. OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
  2151. OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
  2152. dst++;\
  2153. tmp++;\
  2154. }\
  2155. }\
  2156. \
  2157. static void OPNAME ## h264_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2158. const int h=8;\
  2159. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2160. int i;\
  2161. for(i=0; i<h; i++)\
  2162. {\
  2163. OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]));\
  2164. OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]));\
  2165. OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]));\
  2166. OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]));\
  2167. OP(dst[4], (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]));\
  2168. OP(dst[5], (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]));\
  2169. OP(dst[6], (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]));\
  2170. OP(dst[7], (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]));\
  2171. dst+=dstStride;\
  2172. src+=srcStride;\
  2173. }\
  2174. }\
  2175. \
  2176. static void OPNAME ## h264_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2177. const int w=8;\
  2178. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2179. int i;\
  2180. for(i=0; i<w; i++)\
  2181. {\
  2182. const int srcB= src[-2*srcStride];\
  2183. const int srcA= src[-1*srcStride];\
  2184. const int src0= src[0 *srcStride];\
  2185. const int src1= src[1 *srcStride];\
  2186. const int src2= src[2 *srcStride];\
  2187. const int src3= src[3 *srcStride];\
  2188. const int src4= src[4 *srcStride];\
  2189. const int src5= src[5 *srcStride];\
  2190. const int src6= src[6 *srcStride];\
  2191. const int src7= src[7 *srcStride];\
  2192. const int src8= src[8 *srcStride];\
  2193. const int src9= src[9 *srcStride];\
  2194. const int src10=src[10*srcStride];\
  2195. OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
  2196. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
  2197. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
  2198. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
  2199. OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*5 + (src2+src7));\
  2200. OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*5 + (src3+src8));\
  2201. OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*5 + (src4+src9));\
  2202. OP(dst[7*dstStride], (src7+src8)*20 - (src6+src9)*5 + (src5+src10));\
  2203. dst++;\
  2204. src++;\
  2205. }\
  2206. }\
  2207. \
  2208. static void OPNAME ## h264_qpel8_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  2209. const int h=8;\
  2210. const int w=8;\
  2211. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2212. int i;\
  2213. src -= 2*srcStride;\
  2214. for(i=0; i<h+5; i++)\
  2215. {\
  2216. tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]);\
  2217. tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]);\
  2218. tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]);\
  2219. tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]);\
  2220. tmp[4]= (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]);\
  2221. tmp[5]= (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]);\
  2222. tmp[6]= (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]);\
  2223. tmp[7]= (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]);\
  2224. tmp+=tmpStride;\
  2225. src+=srcStride;\
  2226. }\
  2227. tmp -= tmpStride*(h+5-2);\
  2228. for(i=0; i<w; i++)\
  2229. {\
  2230. const int tmpB= tmp[-2*tmpStride];\
  2231. const int tmpA= tmp[-1*tmpStride];\
  2232. const int tmp0= tmp[0 *tmpStride];\
  2233. const int tmp1= tmp[1 *tmpStride];\
  2234. const int tmp2= tmp[2 *tmpStride];\
  2235. const int tmp3= tmp[3 *tmpStride];\
  2236. const int tmp4= tmp[4 *tmpStride];\
  2237. const int tmp5= tmp[5 *tmpStride];\
  2238. const int tmp6= tmp[6 *tmpStride];\
  2239. const int tmp7= tmp[7 *tmpStride];\
  2240. const int tmp8= tmp[8 *tmpStride];\
  2241. const int tmp9= tmp[9 *tmpStride];\
  2242. const int tmp10=tmp[10*tmpStride];\
  2243. OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
  2244. OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
  2245. OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
  2246. OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
  2247. OP2(dst[4*dstStride], (tmp4+tmp5)*20 - (tmp3+tmp6)*5 + (tmp2+tmp7));\
  2248. OP2(dst[5*dstStride], (tmp5+tmp6)*20 - (tmp4+tmp7)*5 + (tmp3+tmp8));\
  2249. OP2(dst[6*dstStride], (tmp6+tmp7)*20 - (tmp5+tmp8)*5 + (tmp4+tmp9));\
  2250. OP2(dst[7*dstStride], (tmp7+tmp8)*20 - (tmp6+tmp9)*5 + (tmp5+tmp10));\
  2251. dst++;\
  2252. tmp++;\
  2253. }\
  2254. }\
  2255. \
  2256. static void OPNAME ## h264_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2257. OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
  2258. OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
  2259. src += 8*srcStride;\
  2260. dst += 8*dstStride;\
  2261. OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
  2262. OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
  2263. }\
  2264. \
  2265. static void OPNAME ## h264_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2266. OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
  2267. OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
  2268. src += 8*srcStride;\
  2269. dst += 8*dstStride;\
  2270. OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
  2271. OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
  2272. }\
  2273. \
  2274. static void OPNAME ## h264_qpel16_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  2275. OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
  2276. OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
  2277. src += 8*srcStride;\
  2278. dst += 8*dstStride;\
  2279. OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
  2280. OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
  2281. }\
  2282. #define H264_MC(OPNAME, SIZE) \
  2283. static void OPNAME ## h264_qpel ## SIZE ## _mc00_c (uint8_t *dst, uint8_t *src, int stride){\
  2284. OPNAME ## pixels ## SIZE ## _c(dst, src, stride, SIZE);\
  2285. }\
  2286. \
  2287. static void OPNAME ## h264_qpel ## SIZE ## _mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  2288. uint8_t half[SIZE*SIZE];\
  2289. put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
  2290. OPNAME ## pixels ## SIZE ## _l2(dst, src, half, stride, stride, SIZE, SIZE);\
  2291. }\
  2292. \
  2293. static void OPNAME ## h264_qpel ## SIZE ## _mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  2294. OPNAME ## h264_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride);\
  2295. }\
  2296. \
  2297. static void OPNAME ## h264_qpel ## SIZE ## _mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  2298. uint8_t half[SIZE*SIZE];\
  2299. put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
  2300. OPNAME ## pixels ## SIZE ## _l2(dst, src+1, half, stride, stride, SIZE, SIZE);\
  2301. }\
  2302. \
  2303. static void OPNAME ## h264_qpel ## SIZE ## _mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  2304. uint8_t full[SIZE*(SIZE+5)];\
  2305. uint8_t * const full_mid= full + SIZE*2;\
  2306. uint8_t half[SIZE*SIZE];\
  2307. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2308. put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
  2309. OPNAME ## pixels ## SIZE ## _l2(dst, full_mid, half, stride, SIZE, SIZE, SIZE);\
  2310. }\
  2311. \
  2312. static void OPNAME ## h264_qpel ## SIZE ## _mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  2313. uint8_t full[SIZE*(SIZE+5)];\
  2314. uint8_t * const full_mid= full + SIZE*2;\
  2315. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2316. OPNAME ## h264_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE);\
  2317. }\
  2318. \
  2319. static void OPNAME ## h264_qpel ## SIZE ## _mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  2320. uint8_t full[SIZE*(SIZE+5)];\
  2321. uint8_t * const full_mid= full + SIZE*2;\
  2322. uint8_t half[SIZE*SIZE];\
  2323. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2324. put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
  2325. OPNAME ## pixels ## SIZE ## _l2(dst, full_mid+SIZE, half, stride, SIZE, SIZE, SIZE);\
  2326. }\
  2327. \
  2328. static void OPNAME ## h264_qpel ## SIZE ## _mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  2329. uint8_t full[SIZE*(SIZE+5)];\
  2330. uint8_t * const full_mid= full + SIZE*2;\
  2331. uint8_t halfH[SIZE*SIZE];\
  2332. uint8_t halfV[SIZE*SIZE];\
  2333. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
  2334. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2335. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2336. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2337. }\
  2338. \
  2339. static void OPNAME ## h264_qpel ## SIZE ## _mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  2340. uint8_t full[SIZE*(SIZE+5)];\
  2341. uint8_t * const full_mid= full + SIZE*2;\
  2342. uint8_t halfH[SIZE*SIZE];\
  2343. uint8_t halfV[SIZE*SIZE];\
  2344. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
  2345. copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
  2346. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2347. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2348. }\
  2349. \
  2350. static void OPNAME ## h264_qpel ## SIZE ## _mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  2351. uint8_t full[SIZE*(SIZE+5)];\
  2352. uint8_t * const full_mid= full + SIZE*2;\
  2353. uint8_t halfH[SIZE*SIZE];\
  2354. uint8_t halfV[SIZE*SIZE];\
  2355. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
  2356. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2357. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2358. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2359. }\
  2360. \
  2361. static void OPNAME ## h264_qpel ## SIZE ## _mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  2362. uint8_t full[SIZE*(SIZE+5)];\
  2363. uint8_t * const full_mid= full + SIZE*2;\
  2364. uint8_t halfH[SIZE*SIZE];\
  2365. uint8_t halfV[SIZE*SIZE];\
  2366. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
  2367. copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
  2368. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2369. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2370. }\
  2371. \
  2372. static void OPNAME ## h264_qpel ## SIZE ## _mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  2373. int16_t tmp[SIZE*(SIZE+5)];\
  2374. OPNAME ## h264_qpel ## SIZE ## _hv_lowpass(dst, tmp, src, stride, SIZE, stride);\
  2375. }\
  2376. \
  2377. static void OPNAME ## h264_qpel ## SIZE ## _mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  2378. int16_t tmp[SIZE*(SIZE+5)];\
  2379. uint8_t halfH[SIZE*SIZE];\
  2380. uint8_t halfHV[SIZE*SIZE];\
  2381. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
  2382. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2383. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
  2384. }\
  2385. \
  2386. static void OPNAME ## h264_qpel ## SIZE ## _mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  2387. int16_t tmp[SIZE*(SIZE+5)];\
  2388. uint8_t halfH[SIZE*SIZE];\
  2389. uint8_t halfHV[SIZE*SIZE];\
  2390. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
  2391. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2392. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
  2393. }\
  2394. \
  2395. static void OPNAME ## h264_qpel ## SIZE ## _mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  2396. uint8_t full[SIZE*(SIZE+5)];\
  2397. uint8_t * const full_mid= full + SIZE*2;\
  2398. int16_t tmp[SIZE*(SIZE+5)];\
  2399. uint8_t halfV[SIZE*SIZE];\
  2400. uint8_t halfHV[SIZE*SIZE];\
  2401. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2402. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2403. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2404. OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
  2405. }\
  2406. \
  2407. static void OPNAME ## h264_qpel ## SIZE ## _mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  2408. uint8_t full[SIZE*(SIZE+5)];\
  2409. uint8_t * const full_mid= full + SIZE*2;\
  2410. int16_t tmp[SIZE*(SIZE+5)];\
  2411. uint8_t halfV[SIZE*SIZE];\
  2412. uint8_t halfHV[SIZE*SIZE];\
  2413. copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
  2414. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2415. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2416. OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
  2417. }\
  2418. #define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
  2419. //#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7)
  2420. #define op_put(a, b) a = cm[((b) + 16)>>5]
  2421. #define op2_avg(a, b) a = (((a)+cm[((b) + 512)>>10]+1)>>1)
  2422. #define op2_put(a, b) a = cm[((b) + 512)>>10]
  2423. H264_LOWPASS(put_ , op_put, op2_put)
  2424. H264_LOWPASS(avg_ , op_avg, op2_avg)
  2425. H264_MC(put_, 2)
  2426. H264_MC(put_, 4)
  2427. H264_MC(put_, 8)
  2428. H264_MC(put_, 16)
  2429. H264_MC(avg_, 4)
  2430. H264_MC(avg_, 8)
  2431. H264_MC(avg_, 16)
  2432. #undef op_avg
  2433. #undef op_put
  2434. #undef op2_avg
  2435. #undef op2_put
  2436. #endif
  2437. static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){
  2438. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  2439. int i;
  2440. for(i=0; i<h; i++){
  2441. dst[0]= cm[(9*(src[0] + src[1]) - (src[-1] + src[2]) + 8)>>4];
  2442. dst[1]= cm[(9*(src[1] + src[2]) - (src[ 0] + src[3]) + 8)>>4];
  2443. dst[2]= cm[(9*(src[2] + src[3]) - (src[ 1] + src[4]) + 8)>>4];
  2444. dst[3]= cm[(9*(src[3] + src[4]) - (src[ 2] + src[5]) + 8)>>4];
  2445. dst[4]= cm[(9*(src[4] + src[5]) - (src[ 3] + src[6]) + 8)>>4];
  2446. dst[5]= cm[(9*(src[5] + src[6]) - (src[ 4] + src[7]) + 8)>>4];
  2447. dst[6]= cm[(9*(src[6] + src[7]) - (src[ 5] + src[8]) + 8)>>4];
  2448. dst[7]= cm[(9*(src[7] + src[8]) - (src[ 6] + src[9]) + 8)>>4];
  2449. dst+=dstStride;
  2450. src+=srcStride;
  2451. }
  2452. }
  2453. #if CONFIG_CAVS_DECODER
  2454. /* AVS specific */
  2455. void ff_put_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
  2456. put_pixels8_c(dst, src, stride, 8);
  2457. }
  2458. void ff_avg_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
  2459. avg_pixels8_c(dst, src, stride, 8);
  2460. }
  2461. void ff_put_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
  2462. put_pixels16_c(dst, src, stride, 16);
  2463. }
  2464. void ff_avg_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
  2465. avg_pixels16_c(dst, src, stride, 16);
  2466. }
  2467. #endif /* CONFIG_CAVS_DECODER */
  2468. #if CONFIG_VC1_DECODER
  2469. /* VC-1 specific */
  2470. void ff_put_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
  2471. put_pixels8_c(dst, src, stride, 8);
  2472. }
  2473. void ff_avg_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
  2474. avg_pixels8_c(dst, src, stride, 8);
  2475. }
  2476. #endif /* CONFIG_VC1_DECODER */
  2477. #if CONFIG_RV40_DECODER
  2478. static void put_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){
  2479. put_pixels16_xy2_c(dst, src, stride, 16);
  2480. }
  2481. static void avg_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){
  2482. avg_pixels16_xy2_c(dst, src, stride, 16);
  2483. }
  2484. static void put_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){
  2485. put_pixels8_xy2_c(dst, src, stride, 8);
  2486. }
  2487. static void avg_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){
  2488. avg_pixels8_xy2_c(dst, src, stride, 8);
  2489. }
  2490. #endif /* CONFIG_RV40_DECODER */
  2491. static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){
  2492. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  2493. int i;
  2494. for(i=0; i<w; i++){
  2495. const int src_1= src[ -srcStride];
  2496. const int src0 = src[0 ];
  2497. const int src1 = src[ srcStride];
  2498. const int src2 = src[2*srcStride];
  2499. const int src3 = src[3*srcStride];
  2500. const int src4 = src[4*srcStride];
  2501. const int src5 = src[5*srcStride];
  2502. const int src6 = src[6*srcStride];
  2503. const int src7 = src[7*srcStride];
  2504. const int src8 = src[8*srcStride];
  2505. const int src9 = src[9*srcStride];
  2506. dst[0*dstStride]= cm[(9*(src0 + src1) - (src_1 + src2) + 8)>>4];
  2507. dst[1*dstStride]= cm[(9*(src1 + src2) - (src0 + src3) + 8)>>4];
  2508. dst[2*dstStride]= cm[(9*(src2 + src3) - (src1 + src4) + 8)>>4];
  2509. dst[3*dstStride]= cm[(9*(src3 + src4) - (src2 + src5) + 8)>>4];
  2510. dst[4*dstStride]= cm[(9*(src4 + src5) - (src3 + src6) + 8)>>4];
  2511. dst[5*dstStride]= cm[(9*(src5 + src6) - (src4 + src7) + 8)>>4];
  2512. dst[6*dstStride]= cm[(9*(src6 + src7) - (src5 + src8) + 8)>>4];
  2513. dst[7*dstStride]= cm[(9*(src7 + src8) - (src6 + src9) + 8)>>4];
  2514. src++;
  2515. dst++;
  2516. }
  2517. }
  2518. static void put_mspel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){
  2519. put_pixels8_c(dst, src, stride, 8);
  2520. }
  2521. static void put_mspel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){
  2522. uint8_t half[64];
  2523. wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
  2524. put_pixels8_l2(dst, src, half, stride, stride, 8, 8);
  2525. }
  2526. static void put_mspel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){
  2527. wmv2_mspel8_h_lowpass(dst, src, stride, stride, 8);
  2528. }
  2529. static void put_mspel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){
  2530. uint8_t half[64];
  2531. wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
  2532. put_pixels8_l2(dst, src+1, half, stride, stride, 8, 8);
  2533. }
  2534. static void put_mspel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){
  2535. wmv2_mspel8_v_lowpass(dst, src, stride, stride, 8);
  2536. }
  2537. static void put_mspel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){
  2538. uint8_t halfH[88];
  2539. uint8_t halfV[64];
  2540. uint8_t halfHV[64];
  2541. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  2542. wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8);
  2543. wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
  2544. put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
  2545. }
  2546. static void put_mspel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){
  2547. uint8_t halfH[88];
  2548. uint8_t halfV[64];
  2549. uint8_t halfHV[64];
  2550. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  2551. wmv2_mspel8_v_lowpass(halfV, src+1, 8, stride, 8);
  2552. wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
  2553. put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
  2554. }
  2555. static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){
  2556. uint8_t halfH[88];
  2557. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  2558. wmv2_mspel8_v_lowpass(dst, halfH+8, stride, 8, 8);
  2559. }
  2560. static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale){
  2561. if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
  2562. int x;
  2563. const int strength= ff_h263_loop_filter_strength[qscale];
  2564. for(x=0; x<8; x++){
  2565. int d1, d2, ad1;
  2566. int p0= src[x-2*stride];
  2567. int p1= src[x-1*stride];
  2568. int p2= src[x+0*stride];
  2569. int p3= src[x+1*stride];
  2570. int d = (p0 - p3 + 4*(p2 - p1)) / 8;
  2571. if (d<-2*strength) d1= 0;
  2572. else if(d<- strength) d1=-2*strength - d;
  2573. else if(d< strength) d1= d;
  2574. else if(d< 2*strength) d1= 2*strength - d;
  2575. else d1= 0;
  2576. p1 += d1;
  2577. p2 -= d1;
  2578. if(p1&256) p1= ~(p1>>31);
  2579. if(p2&256) p2= ~(p2>>31);
  2580. src[x-1*stride] = p1;
  2581. src[x+0*stride] = p2;
  2582. ad1= FFABS(d1)>>1;
  2583. d2= av_clip((p0-p3)/4, -ad1, ad1);
  2584. src[x-2*stride] = p0 - d2;
  2585. src[x+ stride] = p3 + d2;
  2586. }
  2587. }
  2588. }
  2589. static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale){
  2590. if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
  2591. int y;
  2592. const int strength= ff_h263_loop_filter_strength[qscale];
  2593. for(y=0; y<8; y++){
  2594. int d1, d2, ad1;
  2595. int p0= src[y*stride-2];
  2596. int p1= src[y*stride-1];
  2597. int p2= src[y*stride+0];
  2598. int p3= src[y*stride+1];
  2599. int d = (p0 - p3 + 4*(p2 - p1)) / 8;
  2600. if (d<-2*strength) d1= 0;
  2601. else if(d<- strength) d1=-2*strength - d;
  2602. else if(d< strength) d1= d;
  2603. else if(d< 2*strength) d1= 2*strength - d;
  2604. else d1= 0;
  2605. p1 += d1;
  2606. p2 -= d1;
  2607. if(p1&256) p1= ~(p1>>31);
  2608. if(p2&256) p2= ~(p2>>31);
  2609. src[y*stride-1] = p1;
  2610. src[y*stride+0] = p2;
  2611. ad1= FFABS(d1)>>1;
  2612. d2= av_clip((p0-p3)/4, -ad1, ad1);
  2613. src[y*stride-2] = p0 - d2;
  2614. src[y*stride+1] = p3 + d2;
  2615. }
  2616. }
  2617. }
  2618. static void h261_loop_filter_c(uint8_t *src, int stride){
  2619. int x,y,xy,yz;
  2620. int temp[64];
  2621. for(x=0; x<8; x++){
  2622. temp[x ] = 4*src[x ];
  2623. temp[x + 7*8] = 4*src[x + 7*stride];
  2624. }
  2625. for(y=1; y<7; y++){
  2626. for(x=0; x<8; x++){
  2627. xy = y * stride + x;
  2628. yz = y * 8 + x;
  2629. temp[yz] = src[xy - stride] + 2*src[xy] + src[xy + stride];
  2630. }
  2631. }
  2632. for(y=0; y<8; y++){
  2633. src[ y*stride] = (temp[ y*8] + 2)>>2;
  2634. src[7+y*stride] = (temp[7+y*8] + 2)>>2;
  2635. for(x=1; x<7; x++){
  2636. xy = y * stride + x;
  2637. yz = y * 8 + x;
  2638. src[xy] = (temp[yz-1] + 2*temp[yz] + temp[yz+1] + 8)>>4;
  2639. }
  2640. }
  2641. }
  2642. static inline int pix_abs16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2643. {
  2644. int s, i;
  2645. s = 0;
  2646. for(i=0;i<h;i++) {
  2647. s += abs(pix1[0] - pix2[0]);
  2648. s += abs(pix1[1] - pix2[1]);
  2649. s += abs(pix1[2] - pix2[2]);
  2650. s += abs(pix1[3] - pix2[3]);
  2651. s += abs(pix1[4] - pix2[4]);
  2652. s += abs(pix1[5] - pix2[5]);
  2653. s += abs(pix1[6] - pix2[6]);
  2654. s += abs(pix1[7] - pix2[7]);
  2655. s += abs(pix1[8] - pix2[8]);
  2656. s += abs(pix1[9] - pix2[9]);
  2657. s += abs(pix1[10] - pix2[10]);
  2658. s += abs(pix1[11] - pix2[11]);
  2659. s += abs(pix1[12] - pix2[12]);
  2660. s += abs(pix1[13] - pix2[13]);
  2661. s += abs(pix1[14] - pix2[14]);
  2662. s += abs(pix1[15] - pix2[15]);
  2663. pix1 += line_size;
  2664. pix2 += line_size;
  2665. }
  2666. return s;
  2667. }
  2668. static int pix_abs16_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2669. {
  2670. int s, i;
  2671. s = 0;
  2672. for(i=0;i<h;i++) {
  2673. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  2674. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  2675. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  2676. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  2677. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  2678. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  2679. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  2680. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  2681. s += abs(pix1[8] - avg2(pix2[8], pix2[9]));
  2682. s += abs(pix1[9] - avg2(pix2[9], pix2[10]));
  2683. s += abs(pix1[10] - avg2(pix2[10], pix2[11]));
  2684. s += abs(pix1[11] - avg2(pix2[11], pix2[12]));
  2685. s += abs(pix1[12] - avg2(pix2[12], pix2[13]));
  2686. s += abs(pix1[13] - avg2(pix2[13], pix2[14]));
  2687. s += abs(pix1[14] - avg2(pix2[14], pix2[15]));
  2688. s += abs(pix1[15] - avg2(pix2[15], pix2[16]));
  2689. pix1 += line_size;
  2690. pix2 += line_size;
  2691. }
  2692. return s;
  2693. }
  2694. static int pix_abs16_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2695. {
  2696. int s, i;
  2697. uint8_t *pix3 = pix2 + line_size;
  2698. s = 0;
  2699. for(i=0;i<h;i++) {
  2700. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  2701. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  2702. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  2703. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  2704. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  2705. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  2706. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  2707. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  2708. s += abs(pix1[8] - avg2(pix2[8], pix3[8]));
  2709. s += abs(pix1[9] - avg2(pix2[9], pix3[9]));
  2710. s += abs(pix1[10] - avg2(pix2[10], pix3[10]));
  2711. s += abs(pix1[11] - avg2(pix2[11], pix3[11]));
  2712. s += abs(pix1[12] - avg2(pix2[12], pix3[12]));
  2713. s += abs(pix1[13] - avg2(pix2[13], pix3[13]));
  2714. s += abs(pix1[14] - avg2(pix2[14], pix3[14]));
  2715. s += abs(pix1[15] - avg2(pix2[15], pix3[15]));
  2716. pix1 += line_size;
  2717. pix2 += line_size;
  2718. pix3 += line_size;
  2719. }
  2720. return s;
  2721. }
  2722. static int pix_abs16_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2723. {
  2724. int s, i;
  2725. uint8_t *pix3 = pix2 + line_size;
  2726. s = 0;
  2727. for(i=0;i<h;i++) {
  2728. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  2729. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  2730. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  2731. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  2732. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  2733. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  2734. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  2735. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  2736. s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9]));
  2737. s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10]));
  2738. s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11]));
  2739. s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12]));
  2740. s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13]));
  2741. s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14]));
  2742. s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15]));
  2743. s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16]));
  2744. pix1 += line_size;
  2745. pix2 += line_size;
  2746. pix3 += line_size;
  2747. }
  2748. return s;
  2749. }
  2750. static inline int pix_abs8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2751. {
  2752. int s, i;
  2753. s = 0;
  2754. for(i=0;i<h;i++) {
  2755. s += abs(pix1[0] - pix2[0]);
  2756. s += abs(pix1[1] - pix2[1]);
  2757. s += abs(pix1[2] - pix2[2]);
  2758. s += abs(pix1[3] - pix2[3]);
  2759. s += abs(pix1[4] - pix2[4]);
  2760. s += abs(pix1[5] - pix2[5]);
  2761. s += abs(pix1[6] - pix2[6]);
  2762. s += abs(pix1[7] - pix2[7]);
  2763. pix1 += line_size;
  2764. pix2 += line_size;
  2765. }
  2766. return s;
  2767. }
  2768. static int pix_abs8_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2769. {
  2770. int s, i;
  2771. s = 0;
  2772. for(i=0;i<h;i++) {
  2773. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  2774. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  2775. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  2776. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  2777. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  2778. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  2779. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  2780. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  2781. pix1 += line_size;
  2782. pix2 += line_size;
  2783. }
  2784. return s;
  2785. }
  2786. static int pix_abs8_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2787. {
  2788. int s, i;
  2789. uint8_t *pix3 = pix2 + line_size;
  2790. s = 0;
  2791. for(i=0;i<h;i++) {
  2792. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  2793. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  2794. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  2795. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  2796. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  2797. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  2798. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  2799. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  2800. pix1 += line_size;
  2801. pix2 += line_size;
  2802. pix3 += line_size;
  2803. }
  2804. return s;
  2805. }
  2806. static int pix_abs8_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2807. {
  2808. int s, i;
  2809. uint8_t *pix3 = pix2 + line_size;
  2810. s = 0;
  2811. for(i=0;i<h;i++) {
  2812. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  2813. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  2814. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  2815. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  2816. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  2817. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  2818. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  2819. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  2820. pix1 += line_size;
  2821. pix2 += line_size;
  2822. pix3 += line_size;
  2823. }
  2824. return s;
  2825. }
  2826. static int nsse16_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
  2827. MpegEncContext *c = v;
  2828. int score1=0;
  2829. int score2=0;
  2830. int x,y;
  2831. for(y=0; y<h; y++){
  2832. for(x=0; x<16; x++){
  2833. score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
  2834. }
  2835. if(y+1<h){
  2836. for(x=0; x<15; x++){
  2837. score2+= FFABS( s1[x ] - s1[x +stride]
  2838. - s1[x+1] + s1[x+1+stride])
  2839. -FFABS( s2[x ] - s2[x +stride]
  2840. - s2[x+1] + s2[x+1+stride]);
  2841. }
  2842. }
  2843. s1+= stride;
  2844. s2+= stride;
  2845. }
  2846. if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
  2847. else return score1 + FFABS(score2)*8;
  2848. }
  2849. static int nsse8_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
  2850. MpegEncContext *c = v;
  2851. int score1=0;
  2852. int score2=0;
  2853. int x,y;
  2854. for(y=0; y<h; y++){
  2855. for(x=0; x<8; x++){
  2856. score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
  2857. }
  2858. if(y+1<h){
  2859. for(x=0; x<7; x++){
  2860. score2+= FFABS( s1[x ] - s1[x +stride]
  2861. - s1[x+1] + s1[x+1+stride])
  2862. -FFABS( s2[x ] - s2[x +stride]
  2863. - s2[x+1] + s2[x+1+stride]);
  2864. }
  2865. }
  2866. s1+= stride;
  2867. s2+= stride;
  2868. }
  2869. if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
  2870. else return score1 + FFABS(score2)*8;
  2871. }
  2872. static int try_8x8basis_c(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){
  2873. int i;
  2874. unsigned int sum=0;
  2875. for(i=0; i<8*8; i++){
  2876. int b= rem[i] + ((basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT));
  2877. int w= weight[i];
  2878. b>>= RECON_SHIFT;
  2879. assert(-512<b && b<512);
  2880. sum += (w*b)*(w*b)>>4;
  2881. }
  2882. return sum>>2;
  2883. }
  2884. static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale){
  2885. int i;
  2886. for(i=0; i<8*8; i++){
  2887. rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT);
  2888. }
  2889. }
  2890. /**
  2891. * permutes an 8x8 block.
  2892. * @param block the block which will be permuted according to the given permutation vector
  2893. * @param permutation the permutation vector
  2894. * @param last the last non zero coefficient in scantable order, used to speed the permutation up
  2895. * @param scantable the used scantable, this is only used to speed the permutation up, the block is not
  2896. * (inverse) permutated to scantable order!
  2897. */
  2898. void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last)
  2899. {
  2900. int i;
  2901. DCTELEM temp[64];
  2902. if(last<=0) return;
  2903. //if(permutation[1]==1) return; //FIXME it is ok but not clean and might fail for some permutations
  2904. for(i=0; i<=last; i++){
  2905. const int j= scantable[i];
  2906. temp[j]= block[j];
  2907. block[j]=0;
  2908. }
  2909. for(i=0; i<=last; i++){
  2910. const int j= scantable[i];
  2911. const int perm_j= permutation[j];
  2912. block[perm_j]= temp[j];
  2913. }
  2914. }
  2915. static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){
  2916. return 0;
  2917. }
  2918. void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){
  2919. int i;
  2920. memset(cmp, 0, sizeof(void*)*6);
  2921. for(i=0; i<6; i++){
  2922. switch(type&0xFF){
  2923. case FF_CMP_SAD:
  2924. cmp[i]= c->sad[i];
  2925. break;
  2926. case FF_CMP_SATD:
  2927. cmp[i]= c->hadamard8_diff[i];
  2928. break;
  2929. case FF_CMP_SSE:
  2930. cmp[i]= c->sse[i];
  2931. break;
  2932. case FF_CMP_DCT:
  2933. cmp[i]= c->dct_sad[i];
  2934. break;
  2935. case FF_CMP_DCT264:
  2936. cmp[i]= c->dct264_sad[i];
  2937. break;
  2938. case FF_CMP_DCTMAX:
  2939. cmp[i]= c->dct_max[i];
  2940. break;
  2941. case FF_CMP_PSNR:
  2942. cmp[i]= c->quant_psnr[i];
  2943. break;
  2944. case FF_CMP_BIT:
  2945. cmp[i]= c->bit[i];
  2946. break;
  2947. case FF_CMP_RD:
  2948. cmp[i]= c->rd[i];
  2949. break;
  2950. case FF_CMP_VSAD:
  2951. cmp[i]= c->vsad[i];
  2952. break;
  2953. case FF_CMP_VSSE:
  2954. cmp[i]= c->vsse[i];
  2955. break;
  2956. case FF_CMP_ZERO:
  2957. cmp[i]= zero_cmp;
  2958. break;
  2959. case FF_CMP_NSSE:
  2960. cmp[i]= c->nsse[i];
  2961. break;
  2962. #if CONFIG_DWT
  2963. case FF_CMP_W53:
  2964. cmp[i]= c->w53[i];
  2965. break;
  2966. case FF_CMP_W97:
  2967. cmp[i]= c->w97[i];
  2968. break;
  2969. #endif
  2970. default:
  2971. av_log(NULL, AV_LOG_ERROR,"internal error in cmp function selection\n");
  2972. }
  2973. }
  2974. }
  2975. static void clear_block_c(DCTELEM *block)
  2976. {
  2977. memset(block, 0, sizeof(DCTELEM)*64);
  2978. }
  2979. /**
  2980. * memset(blocks, 0, sizeof(DCTELEM)*6*64)
  2981. */
  2982. static void clear_blocks_c(DCTELEM *blocks)
  2983. {
  2984. memset(blocks, 0, sizeof(DCTELEM)*6*64);
  2985. }
  2986. static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){
  2987. long i;
  2988. for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
  2989. long a = *(long*)(src+i);
  2990. long b = *(long*)(dst+i);
  2991. *(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80);
  2992. }
  2993. for(; i<w; i++)
  2994. dst[i+0] += src[i+0];
  2995. }
  2996. static void add_bytes_l2_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
  2997. long i;
  2998. for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
  2999. long a = *(long*)(src1+i);
  3000. long b = *(long*)(src2+i);
  3001. *(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80);
  3002. }
  3003. for(; i<w; i++)
  3004. dst[i] = src1[i]+src2[i];
  3005. }
  3006. static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
  3007. long i;
  3008. #if !HAVE_FAST_UNALIGNED
  3009. if((long)src2 & (sizeof(long)-1)){
  3010. for(i=0; i+7<w; i+=8){
  3011. dst[i+0] = src1[i+0]-src2[i+0];
  3012. dst[i+1] = src1[i+1]-src2[i+1];
  3013. dst[i+2] = src1[i+2]-src2[i+2];
  3014. dst[i+3] = src1[i+3]-src2[i+3];
  3015. dst[i+4] = src1[i+4]-src2[i+4];
  3016. dst[i+5] = src1[i+5]-src2[i+5];
  3017. dst[i+6] = src1[i+6]-src2[i+6];
  3018. dst[i+7] = src1[i+7]-src2[i+7];
  3019. }
  3020. }else
  3021. #endif
  3022. for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
  3023. long a = *(long*)(src1+i);
  3024. long b = *(long*)(src2+i);
  3025. *(long*)(dst+i) = ((a|pb_80) - (b&pb_7f)) ^ ((a^b^pb_80)&pb_80);
  3026. }
  3027. for(; i<w; i++)
  3028. dst[i+0] = src1[i+0]-src2[i+0];
  3029. }
  3030. 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){
  3031. int i;
  3032. uint8_t l, lt;
  3033. l= *left;
  3034. lt= *left_top;
  3035. for(i=0; i<w; i++){
  3036. l= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF) + diff[i];
  3037. lt= src1[i];
  3038. dst[i]= l;
  3039. }
  3040. *left= l;
  3041. *left_top= lt;
  3042. }
  3043. 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){
  3044. int i;
  3045. uint8_t l, lt;
  3046. l= *left;
  3047. lt= *left_top;
  3048. for(i=0; i<w; i++){
  3049. const int pred= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF);
  3050. lt= src1[i];
  3051. l= src2[i];
  3052. dst[i]= l - pred;
  3053. }
  3054. *left= l;
  3055. *left_top= lt;
  3056. }
  3057. static int add_hfyu_left_prediction_c(uint8_t *dst, const uint8_t *src, int w, int acc){
  3058. int i;
  3059. for(i=0; i<w-1; i++){
  3060. acc+= src[i];
  3061. dst[i]= acc;
  3062. i++;
  3063. acc+= src[i];
  3064. dst[i]= acc;
  3065. }
  3066. for(; i<w; i++){
  3067. acc+= src[i];
  3068. dst[i]= acc;
  3069. }
  3070. return acc;
  3071. }
  3072. #if HAVE_BIGENDIAN
  3073. #define B 3
  3074. #define G 2
  3075. #define R 1
  3076. #define A 0
  3077. #else
  3078. #define B 0
  3079. #define G 1
  3080. #define R 2
  3081. #define A 3
  3082. #endif
  3083. 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){
  3084. int i;
  3085. int r,g,b,a;
  3086. r= *red;
  3087. g= *green;
  3088. b= *blue;
  3089. a= *alpha;
  3090. for(i=0; i<w; i++){
  3091. b+= src[4*i+B];
  3092. g+= src[4*i+G];
  3093. r+= src[4*i+R];
  3094. a+= src[4*i+A];
  3095. dst[4*i+B]= b;
  3096. dst[4*i+G]= g;
  3097. dst[4*i+R]= r;
  3098. dst[4*i+A]= a;
  3099. }
  3100. *red= r;
  3101. *green= g;
  3102. *blue= b;
  3103. *alpha= a;
  3104. }
  3105. #undef B
  3106. #undef G
  3107. #undef R
  3108. #undef A
  3109. #define BUTTERFLY2(o1,o2,i1,i2) \
  3110. o1= (i1)+(i2);\
  3111. o2= (i1)-(i2);
  3112. #define BUTTERFLY1(x,y) \
  3113. {\
  3114. int a,b;\
  3115. a= x;\
  3116. b= y;\
  3117. x= a+b;\
  3118. y= a-b;\
  3119. }
  3120. #define BUTTERFLYA(x,y) (FFABS((x)+(y)) + FFABS((x)-(y)))
  3121. static int hadamard8_diff8x8_c(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){
  3122. int i;
  3123. int temp[64];
  3124. int sum=0;
  3125. assert(h==8);
  3126. for(i=0; i<8; i++){
  3127. //FIXME try pointer walks
  3128. 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]);
  3129. 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]);
  3130. 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]);
  3131. 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]);
  3132. BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
  3133. BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
  3134. BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
  3135. BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
  3136. BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
  3137. BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
  3138. BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
  3139. BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
  3140. }
  3141. for(i=0; i<8; i++){
  3142. BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
  3143. BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
  3144. BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
  3145. BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
  3146. BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
  3147. BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
  3148. BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
  3149. BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
  3150. sum +=
  3151. BUTTERFLYA(temp[8*0+i], temp[8*4+i])
  3152. +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
  3153. +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
  3154. +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
  3155. }
  3156. #if 0
  3157. static int maxi=0;
  3158. if(sum>maxi){
  3159. maxi=sum;
  3160. printf("MAX:%d\n", maxi);
  3161. }
  3162. #endif
  3163. return sum;
  3164. }
  3165. static int hadamard8_intra8x8_c(/*MpegEncContext*/ void *s, uint8_t *src, uint8_t *dummy, int stride, int h){
  3166. int i;
  3167. int temp[64];
  3168. int sum=0;
  3169. assert(h==8);
  3170. for(i=0; i<8; i++){
  3171. //FIXME try pointer walks
  3172. BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0],src[stride*i+1]);
  3173. BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2],src[stride*i+3]);
  3174. BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4],src[stride*i+5]);
  3175. BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6],src[stride*i+7]);
  3176. BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
  3177. BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
  3178. BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
  3179. BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
  3180. BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
  3181. BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
  3182. BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
  3183. BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
  3184. }
  3185. for(i=0; i<8; i++){
  3186. BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
  3187. BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
  3188. BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
  3189. BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
  3190. BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
  3191. BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
  3192. BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
  3193. BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
  3194. sum +=
  3195. BUTTERFLYA(temp[8*0+i], temp[8*4+i])
  3196. +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
  3197. +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
  3198. +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
  3199. }
  3200. sum -= FFABS(temp[8*0] + temp[8*4]); // -mean
  3201. return sum;
  3202. }
  3203. static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3204. MpegEncContext * const s= (MpegEncContext *)c;
  3205. LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
  3206. assert(h==8);
  3207. s->dsp.diff_pixels(temp, src1, src2, stride);
  3208. s->dsp.fdct(temp);
  3209. return s->dsp.sum_abs_dctelem(temp);
  3210. }
  3211. #if CONFIG_GPL
  3212. #define DCT8_1D {\
  3213. const int s07 = SRC(0) + SRC(7);\
  3214. const int s16 = SRC(1) + SRC(6);\
  3215. const int s25 = SRC(2) + SRC(5);\
  3216. const int s34 = SRC(3) + SRC(4);\
  3217. const int a0 = s07 + s34;\
  3218. const int a1 = s16 + s25;\
  3219. const int a2 = s07 - s34;\
  3220. const int a3 = s16 - s25;\
  3221. const int d07 = SRC(0) - SRC(7);\
  3222. const int d16 = SRC(1) - SRC(6);\
  3223. const int d25 = SRC(2) - SRC(5);\
  3224. const int d34 = SRC(3) - SRC(4);\
  3225. const int a4 = d16 + d25 + (d07 + (d07>>1));\
  3226. const int a5 = d07 - d34 - (d25 + (d25>>1));\
  3227. const int a6 = d07 + d34 - (d16 + (d16>>1));\
  3228. const int a7 = d16 - d25 + (d34 + (d34>>1));\
  3229. DST(0, a0 + a1 ) ;\
  3230. DST(1, a4 + (a7>>2)) ;\
  3231. DST(2, a2 + (a3>>1)) ;\
  3232. DST(3, a5 + (a6>>2)) ;\
  3233. DST(4, a0 - a1 ) ;\
  3234. DST(5, a6 - (a5>>2)) ;\
  3235. DST(6, (a2>>1) - a3 ) ;\
  3236. DST(7, (a4>>2) - a7 ) ;\
  3237. }
  3238. static int dct264_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3239. MpegEncContext * const s= (MpegEncContext *)c;
  3240. DCTELEM dct[8][8];
  3241. int i;
  3242. int sum=0;
  3243. s->dsp.diff_pixels(dct[0], src1, src2, stride);
  3244. #define SRC(x) dct[i][x]
  3245. #define DST(x,v) dct[i][x]= v
  3246. for( i = 0; i < 8; i++ )
  3247. DCT8_1D
  3248. #undef SRC
  3249. #undef DST
  3250. #define SRC(x) dct[x][i]
  3251. #define DST(x,v) sum += FFABS(v)
  3252. for( i = 0; i < 8; i++ )
  3253. DCT8_1D
  3254. #undef SRC
  3255. #undef DST
  3256. return sum;
  3257. }
  3258. #endif
  3259. static int dct_max8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3260. MpegEncContext * const s= (MpegEncContext *)c;
  3261. LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
  3262. int sum=0, i;
  3263. assert(h==8);
  3264. s->dsp.diff_pixels(temp, src1, src2, stride);
  3265. s->dsp.fdct(temp);
  3266. for(i=0; i<64; i++)
  3267. sum= FFMAX(sum, FFABS(temp[i]));
  3268. return sum;
  3269. }
  3270. static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3271. MpegEncContext * const s= (MpegEncContext *)c;
  3272. LOCAL_ALIGNED_16(DCTELEM, temp, [64*2]);
  3273. DCTELEM * const bak = temp+64;
  3274. int sum=0, i;
  3275. assert(h==8);
  3276. s->mb_intra=0;
  3277. s->dsp.diff_pixels(temp, src1, src2, stride);
  3278. memcpy(bak, temp, 64*sizeof(DCTELEM));
  3279. s->block_last_index[0/*FIXME*/]= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  3280. s->dct_unquantize_inter(s, temp, 0, s->qscale);
  3281. ff_simple_idct(temp); //FIXME
  3282. for(i=0; i<64; i++)
  3283. sum+= (temp[i]-bak[i])*(temp[i]-bak[i]);
  3284. return sum;
  3285. }
  3286. static int rd8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3287. MpegEncContext * const s= (MpegEncContext *)c;
  3288. const uint8_t *scantable= s->intra_scantable.permutated;
  3289. LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
  3290. LOCAL_ALIGNED_16(uint8_t, lsrc1, [64]);
  3291. LOCAL_ALIGNED_16(uint8_t, lsrc2, [64]);
  3292. int i, last, run, bits, level, distortion, start_i;
  3293. const int esc_length= s->ac_esc_length;
  3294. uint8_t * length;
  3295. uint8_t * last_length;
  3296. assert(h==8);
  3297. copy_block8(lsrc1, src1, 8, stride, 8);
  3298. copy_block8(lsrc2, src2, 8, stride, 8);
  3299. s->dsp.diff_pixels(temp, lsrc1, lsrc2, 8);
  3300. s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  3301. bits=0;
  3302. if (s->mb_intra) {
  3303. start_i = 1;
  3304. length = s->intra_ac_vlc_length;
  3305. last_length= s->intra_ac_vlc_last_length;
  3306. bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
  3307. } else {
  3308. start_i = 0;
  3309. length = s->inter_ac_vlc_length;
  3310. last_length= s->inter_ac_vlc_last_length;
  3311. }
  3312. if(last>=start_i){
  3313. run=0;
  3314. for(i=start_i; i<last; i++){
  3315. int j= scantable[i];
  3316. level= temp[j];
  3317. if(level){
  3318. level+=64;
  3319. if((level&(~127)) == 0){
  3320. bits+= length[UNI_AC_ENC_INDEX(run, level)];
  3321. }else
  3322. bits+= esc_length;
  3323. run=0;
  3324. }else
  3325. run++;
  3326. }
  3327. i= scantable[last];
  3328. level= temp[i] + 64;
  3329. assert(level - 64);
  3330. if((level&(~127)) == 0){
  3331. bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
  3332. }else
  3333. bits+= esc_length;
  3334. }
  3335. if(last>=0){
  3336. if(s->mb_intra)
  3337. s->dct_unquantize_intra(s, temp, 0, s->qscale);
  3338. else
  3339. s->dct_unquantize_inter(s, temp, 0, s->qscale);
  3340. }
  3341. s->dsp.idct_add(lsrc2, 8, temp);
  3342. distortion= s->dsp.sse[1](NULL, lsrc2, lsrc1, 8, 8);
  3343. return distortion + ((bits*s->qscale*s->qscale*109 + 64)>>7);
  3344. }
  3345. static int bit8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3346. MpegEncContext * const s= (MpegEncContext *)c;
  3347. const uint8_t *scantable= s->intra_scantable.permutated;
  3348. LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
  3349. int i, last, run, bits, level, start_i;
  3350. const int esc_length= s->ac_esc_length;
  3351. uint8_t * length;
  3352. uint8_t * last_length;
  3353. assert(h==8);
  3354. s->dsp.diff_pixels(temp, src1, src2, stride);
  3355. s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  3356. bits=0;
  3357. if (s->mb_intra) {
  3358. start_i = 1;
  3359. length = s->intra_ac_vlc_length;
  3360. last_length= s->intra_ac_vlc_last_length;
  3361. bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
  3362. } else {
  3363. start_i = 0;
  3364. length = s->inter_ac_vlc_length;
  3365. last_length= s->inter_ac_vlc_last_length;
  3366. }
  3367. if(last>=start_i){
  3368. run=0;
  3369. for(i=start_i; i<last; i++){
  3370. int j= scantable[i];
  3371. level= temp[j];
  3372. if(level){
  3373. level+=64;
  3374. if((level&(~127)) == 0){
  3375. bits+= length[UNI_AC_ENC_INDEX(run, level)];
  3376. }else
  3377. bits+= esc_length;
  3378. run=0;
  3379. }else
  3380. run++;
  3381. }
  3382. i= scantable[last];
  3383. level= temp[i] + 64;
  3384. assert(level - 64);
  3385. if((level&(~127)) == 0){
  3386. bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
  3387. }else
  3388. bits+= esc_length;
  3389. }
  3390. return bits;
  3391. }
  3392. #define VSAD_INTRA(size) \
  3393. static int vsad_intra##size##_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){ \
  3394. int score=0; \
  3395. int x,y; \
  3396. \
  3397. for(y=1; y<h; y++){ \
  3398. for(x=0; x<size; x+=4){ \
  3399. score+= FFABS(s[x ] - s[x +stride]) + FFABS(s[x+1] - s[x+1+stride]) \
  3400. +FFABS(s[x+2] - s[x+2+stride]) + FFABS(s[x+3] - s[x+3+stride]); \
  3401. } \
  3402. s+= stride; \
  3403. } \
  3404. \
  3405. return score; \
  3406. }
  3407. VSAD_INTRA(8)
  3408. VSAD_INTRA(16)
  3409. static int vsad16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
  3410. int score=0;
  3411. int x,y;
  3412. for(y=1; y<h; y++){
  3413. for(x=0; x<16; x++){
  3414. score+= FFABS(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
  3415. }
  3416. s1+= stride;
  3417. s2+= stride;
  3418. }
  3419. return score;
  3420. }
  3421. #define SQ(a) ((a)*(a))
  3422. #define VSSE_INTRA(size) \
  3423. static int vsse_intra##size##_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){ \
  3424. int score=0; \
  3425. int x,y; \
  3426. \
  3427. for(y=1; y<h; y++){ \
  3428. for(x=0; x<size; x+=4){ \
  3429. score+= SQ(s[x ] - s[x +stride]) + SQ(s[x+1] - s[x+1+stride]) \
  3430. +SQ(s[x+2] - s[x+2+stride]) + SQ(s[x+3] - s[x+3+stride]); \
  3431. } \
  3432. s+= stride; \
  3433. } \
  3434. \
  3435. return score; \
  3436. }
  3437. VSSE_INTRA(8)
  3438. VSSE_INTRA(16)
  3439. static int vsse16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
  3440. int score=0;
  3441. int x,y;
  3442. for(y=1; y<h; y++){
  3443. for(x=0; x<16; x++){
  3444. score+= SQ(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
  3445. }
  3446. s1+= stride;
  3447. s2+= stride;
  3448. }
  3449. return score;
  3450. }
  3451. static int ssd_int8_vs_int16_c(const int8_t *pix1, const int16_t *pix2,
  3452. int size){
  3453. int score=0;
  3454. int i;
  3455. for(i=0; i<size; i++)
  3456. score += (pix1[i]-pix2[i])*(pix1[i]-pix2[i]);
  3457. return score;
  3458. }
  3459. WRAPPER8_16_SQ(hadamard8_diff8x8_c, hadamard8_diff16_c)
  3460. WRAPPER8_16_SQ(hadamard8_intra8x8_c, hadamard8_intra16_c)
  3461. WRAPPER8_16_SQ(dct_sad8x8_c, dct_sad16_c)
  3462. #if CONFIG_GPL
  3463. WRAPPER8_16_SQ(dct264_sad8x8_c, dct264_sad16_c)
  3464. #endif
  3465. WRAPPER8_16_SQ(dct_max8x8_c, dct_max16_c)
  3466. WRAPPER8_16_SQ(quant_psnr8x8_c, quant_psnr16_c)
  3467. WRAPPER8_16_SQ(rd8x8_c, rd16_c)
  3468. WRAPPER8_16_SQ(bit8x8_c, bit16_c)
  3469. static void vector_fmul_c(float *dst, const float *src, int len){
  3470. int i;
  3471. for(i=0; i<len; i++)
  3472. dst[i] *= src[i];
  3473. }
  3474. static void vector_fmul_reverse_c(float *dst, const float *src0, const float *src1, int len){
  3475. int i;
  3476. src1 += len-1;
  3477. for(i=0; i<len; i++)
  3478. dst[i] = src0[i] * src1[-i];
  3479. }
  3480. static void vector_fmul_add_c(float *dst, const float *src0, const float *src1, const float *src2, int len){
  3481. int i;
  3482. for(i=0; i<len; i++)
  3483. dst[i] = src0[i] * src1[i] + src2[i];
  3484. }
  3485. void ff_vector_fmul_window_c(float *dst, const float *src0, const float *src1, const float *win, float add_bias, int len){
  3486. int i,j;
  3487. dst += len;
  3488. win += len;
  3489. src0+= len;
  3490. for(i=-len, j=len-1; i<0; i++, j--) {
  3491. float s0 = src0[i];
  3492. float s1 = src1[j];
  3493. float wi = win[i];
  3494. float wj = win[j];
  3495. dst[i] = s0*wj - s1*wi + add_bias;
  3496. dst[j] = s0*wi + s1*wj + add_bias;
  3497. }
  3498. }
  3499. static void vector_fmul_scalar_c(float *dst, const float *src, float mul,
  3500. int len)
  3501. {
  3502. int i;
  3503. for (i = 0; i < len; i++)
  3504. dst[i] = src[i] * mul;
  3505. }
  3506. static void vector_fmul_sv_scalar_2_c(float *dst, const float *src,
  3507. const float **sv, float mul, int len)
  3508. {
  3509. int i;
  3510. for (i = 0; i < len; i += 2, sv++) {
  3511. dst[i ] = src[i ] * sv[0][0] * mul;
  3512. dst[i+1] = src[i+1] * sv[0][1] * mul;
  3513. }
  3514. }
  3515. static void vector_fmul_sv_scalar_4_c(float *dst, const float *src,
  3516. const float **sv, float mul, int len)
  3517. {
  3518. int i;
  3519. for (i = 0; i < len; i += 4, sv++) {
  3520. dst[i ] = src[i ] * sv[0][0] * mul;
  3521. dst[i+1] = src[i+1] * sv[0][1] * mul;
  3522. dst[i+2] = src[i+2] * sv[0][2] * mul;
  3523. dst[i+3] = src[i+3] * sv[0][3] * mul;
  3524. }
  3525. }
  3526. static void sv_fmul_scalar_2_c(float *dst, const float **sv, float mul,
  3527. int len)
  3528. {
  3529. int i;
  3530. for (i = 0; i < len; i += 2, sv++) {
  3531. dst[i ] = sv[0][0] * mul;
  3532. dst[i+1] = sv[0][1] * mul;
  3533. }
  3534. }
  3535. static void sv_fmul_scalar_4_c(float *dst, const float **sv, float mul,
  3536. int len)
  3537. {
  3538. int i;
  3539. for (i = 0; i < len; i += 4, sv++) {
  3540. dst[i ] = sv[0][0] * mul;
  3541. dst[i+1] = sv[0][1] * mul;
  3542. dst[i+2] = sv[0][2] * mul;
  3543. dst[i+3] = sv[0][3] * mul;
  3544. }
  3545. }
  3546. static void butterflies_float_c(float *restrict v1, float *restrict v2,
  3547. int len)
  3548. {
  3549. int i;
  3550. for (i = 0; i < len; i++) {
  3551. float t = v1[i] - v2[i];
  3552. v1[i] += v2[i];
  3553. v2[i] = t;
  3554. }
  3555. }
  3556. static float scalarproduct_float_c(const float *v1, const float *v2, int len)
  3557. {
  3558. float p = 0.0;
  3559. int i;
  3560. for (i = 0; i < len; i++)
  3561. p += v1[i] * v2[i];
  3562. return p;
  3563. }
  3564. static void int32_to_float_fmul_scalar_c(float *dst, const int *src, float mul, int len){
  3565. int i;
  3566. for(i=0; i<len; i++)
  3567. dst[i] = src[i] * mul;
  3568. }
  3569. static inline uint32_t clipf_c_one(uint32_t a, uint32_t mini,
  3570. uint32_t maxi, uint32_t maxisign)
  3571. {
  3572. if(a > mini) return mini;
  3573. else if((a^(1<<31)) > maxisign) return maxi;
  3574. else return a;
  3575. }
  3576. static void vector_clipf_c_opposite_sign(float *dst, const float *src, float *min, float *max, int len){
  3577. int i;
  3578. uint32_t mini = *(uint32_t*)min;
  3579. uint32_t maxi = *(uint32_t*)max;
  3580. uint32_t maxisign = maxi ^ (1<<31);
  3581. uint32_t *dsti = (uint32_t*)dst;
  3582. const uint32_t *srci = (const uint32_t*)src;
  3583. for(i=0; i<len; i+=8) {
  3584. dsti[i + 0] = clipf_c_one(srci[i + 0], mini, maxi, maxisign);
  3585. dsti[i + 1] = clipf_c_one(srci[i + 1], mini, maxi, maxisign);
  3586. dsti[i + 2] = clipf_c_one(srci[i + 2], mini, maxi, maxisign);
  3587. dsti[i + 3] = clipf_c_one(srci[i + 3], mini, maxi, maxisign);
  3588. dsti[i + 4] = clipf_c_one(srci[i + 4], mini, maxi, maxisign);
  3589. dsti[i + 5] = clipf_c_one(srci[i + 5], mini, maxi, maxisign);
  3590. dsti[i + 6] = clipf_c_one(srci[i + 6], mini, maxi, maxisign);
  3591. dsti[i + 7] = clipf_c_one(srci[i + 7], mini, maxi, maxisign);
  3592. }
  3593. }
  3594. static void vector_clipf_c(float *dst, const float *src, float min, float max, int len){
  3595. int i;
  3596. if(min < 0 && max > 0) {
  3597. vector_clipf_c_opposite_sign(dst, src, &min, &max, len);
  3598. } else {
  3599. for(i=0; i < len; i+=8) {
  3600. dst[i ] = av_clipf(src[i ], min, max);
  3601. dst[i + 1] = av_clipf(src[i + 1], min, max);
  3602. dst[i + 2] = av_clipf(src[i + 2], min, max);
  3603. dst[i + 3] = av_clipf(src[i + 3], min, max);
  3604. dst[i + 4] = av_clipf(src[i + 4], min, max);
  3605. dst[i + 5] = av_clipf(src[i + 5], min, max);
  3606. dst[i + 6] = av_clipf(src[i + 6], min, max);
  3607. dst[i + 7] = av_clipf(src[i + 7], min, max);
  3608. }
  3609. }
  3610. }
  3611. static av_always_inline int float_to_int16_one(const float *src){
  3612. int_fast32_t tmp = *(const int32_t*)src;
  3613. if(tmp & 0xf0000){
  3614. tmp = (0x43c0ffff - tmp)>>31;
  3615. // is this faster on some gcc/cpu combinations?
  3616. // if(tmp > 0x43c0ffff) tmp = 0xFFFF;
  3617. // else tmp = 0;
  3618. }
  3619. return tmp - 0x8000;
  3620. }
  3621. void ff_float_to_int16_c(int16_t *dst, const float *src, long len){
  3622. int i;
  3623. for(i=0; i<len; i++)
  3624. dst[i] = float_to_int16_one(src+i);
  3625. }
  3626. void ff_float_to_int16_interleave_c(int16_t *dst, const float **src, long len, int channels){
  3627. int i,j,c;
  3628. if(channels==2){
  3629. for(i=0; i<len; i++){
  3630. dst[2*i] = float_to_int16_one(src[0]+i);
  3631. dst[2*i+1] = float_to_int16_one(src[1]+i);
  3632. }
  3633. }else{
  3634. for(c=0; c<channels; c++)
  3635. for(i=0, j=c; i<len; i++, j+=channels)
  3636. dst[j] = float_to_int16_one(src[c]+i);
  3637. }
  3638. }
  3639. static int32_t scalarproduct_int16_c(const int16_t * v1, const int16_t * v2, int order, int shift)
  3640. {
  3641. int res = 0;
  3642. while (order--)
  3643. res += (*v1++ * *v2++) >> shift;
  3644. return res;
  3645. }
  3646. static int32_t scalarproduct_and_madd_int16_c(int16_t *v1, const int16_t *v2, const int16_t *v3, int order, int mul)
  3647. {
  3648. int res = 0;
  3649. while (order--) {
  3650. res += *v1 * *v2++;
  3651. *v1++ += mul * *v3++;
  3652. }
  3653. return res;
  3654. }
  3655. #define W0 2048
  3656. #define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */
  3657. #define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */
  3658. #define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */
  3659. #define W4 2048 /* 2048*sqrt (2)*cos (4*pi/16) */
  3660. #define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */
  3661. #define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */
  3662. #define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */
  3663. static void wmv2_idct_row(short * b)
  3664. {
  3665. int s1,s2;
  3666. int a0,a1,a2,a3,a4,a5,a6,a7;
  3667. /*step 1*/
  3668. a1 = W1*b[1]+W7*b[7];
  3669. a7 = W7*b[1]-W1*b[7];
  3670. a5 = W5*b[5]+W3*b[3];
  3671. a3 = W3*b[5]-W5*b[3];
  3672. a2 = W2*b[2]+W6*b[6];
  3673. a6 = W6*b[2]-W2*b[6];
  3674. a0 = W0*b[0]+W0*b[4];
  3675. a4 = W0*b[0]-W0*b[4];
  3676. /*step 2*/
  3677. s1 = (181*(a1-a5+a7-a3)+128)>>8;//1,3,5,7,
  3678. s2 = (181*(a1-a5-a7+a3)+128)>>8;
  3679. /*step 3*/
  3680. b[0] = (a0+a2+a1+a5 + (1<<7))>>8;
  3681. b[1] = (a4+a6 +s1 + (1<<7))>>8;
  3682. b[2] = (a4-a6 +s2 + (1<<7))>>8;
  3683. b[3] = (a0-a2+a7+a3 + (1<<7))>>8;
  3684. b[4] = (a0-a2-a7-a3 + (1<<7))>>8;
  3685. b[5] = (a4-a6 -s2 + (1<<7))>>8;
  3686. b[6] = (a4+a6 -s1 + (1<<7))>>8;
  3687. b[7] = (a0+a2-a1-a5 + (1<<7))>>8;
  3688. }
  3689. static void wmv2_idct_col(short * b)
  3690. {
  3691. int s1,s2;
  3692. int a0,a1,a2,a3,a4,a5,a6,a7;
  3693. /*step 1, with extended precision*/
  3694. a1 = (W1*b[8*1]+W7*b[8*7] + 4)>>3;
  3695. a7 = (W7*b[8*1]-W1*b[8*7] + 4)>>3;
  3696. a5 = (W5*b[8*5]+W3*b[8*3] + 4)>>3;
  3697. a3 = (W3*b[8*5]-W5*b[8*3] + 4)>>3;
  3698. a2 = (W2*b[8*2]+W6*b[8*6] + 4)>>3;
  3699. a6 = (W6*b[8*2]-W2*b[8*6] + 4)>>3;
  3700. a0 = (W0*b[8*0]+W0*b[8*4] )>>3;
  3701. a4 = (W0*b[8*0]-W0*b[8*4] )>>3;
  3702. /*step 2*/
  3703. s1 = (181*(a1-a5+a7-a3)+128)>>8;
  3704. s2 = (181*(a1-a5-a7+a3)+128)>>8;
  3705. /*step 3*/
  3706. b[8*0] = (a0+a2+a1+a5 + (1<<13))>>14;
  3707. b[8*1] = (a4+a6 +s1 + (1<<13))>>14;
  3708. b[8*2] = (a4-a6 +s2 + (1<<13))>>14;
  3709. b[8*3] = (a0-a2+a7+a3 + (1<<13))>>14;
  3710. b[8*4] = (a0-a2-a7-a3 + (1<<13))>>14;
  3711. b[8*5] = (a4-a6 -s2 + (1<<13))>>14;
  3712. b[8*6] = (a4+a6 -s1 + (1<<13))>>14;
  3713. b[8*7] = (a0+a2-a1-a5 + (1<<13))>>14;
  3714. }
  3715. void ff_wmv2_idct_c(short * block){
  3716. int i;
  3717. for(i=0;i<64;i+=8){
  3718. wmv2_idct_row(block+i);
  3719. }
  3720. for(i=0;i<8;i++){
  3721. wmv2_idct_col(block+i);
  3722. }
  3723. }
  3724. /* XXX: those functions should be suppressed ASAP when all IDCTs are
  3725. converted */
  3726. static void ff_wmv2_idct_put_c(uint8_t *dest, int line_size, DCTELEM *block)
  3727. {
  3728. ff_wmv2_idct_c(block);
  3729. put_pixels_clamped_c(block, dest, line_size);
  3730. }
  3731. static void ff_wmv2_idct_add_c(uint8_t *dest, int line_size, DCTELEM *block)
  3732. {
  3733. ff_wmv2_idct_c(block);
  3734. add_pixels_clamped_c(block, dest, line_size);
  3735. }
  3736. static void ff_jref_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
  3737. {
  3738. j_rev_dct (block);
  3739. put_pixels_clamped_c(block, dest, line_size);
  3740. }
  3741. static void ff_jref_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
  3742. {
  3743. j_rev_dct (block);
  3744. add_pixels_clamped_c(block, dest, line_size);
  3745. }
  3746. static void ff_jref_idct4_put(uint8_t *dest, int line_size, DCTELEM *block)
  3747. {
  3748. j_rev_dct4 (block);
  3749. put_pixels_clamped4_c(block, dest, line_size);
  3750. }
  3751. static void ff_jref_idct4_add(uint8_t *dest, int line_size, DCTELEM *block)
  3752. {
  3753. j_rev_dct4 (block);
  3754. add_pixels_clamped4_c(block, dest, line_size);
  3755. }
  3756. static void ff_jref_idct2_put(uint8_t *dest, int line_size, DCTELEM *block)
  3757. {
  3758. j_rev_dct2 (block);
  3759. put_pixels_clamped2_c(block, dest, line_size);
  3760. }
  3761. static void ff_jref_idct2_add(uint8_t *dest, int line_size, DCTELEM *block)
  3762. {
  3763. j_rev_dct2 (block);
  3764. add_pixels_clamped2_c(block, dest, line_size);
  3765. }
  3766. static void ff_jref_idct1_put(uint8_t *dest, int line_size, DCTELEM *block)
  3767. {
  3768. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  3769. dest[0] = cm[(block[0] + 4)>>3];
  3770. }
  3771. static void ff_jref_idct1_add(uint8_t *dest, int line_size, DCTELEM *block)
  3772. {
  3773. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  3774. dest[0] = cm[dest[0] + ((block[0] + 4)>>3)];
  3775. }
  3776. static void just_return(void *mem av_unused, int stride av_unused, int h av_unused) { return; }
  3777. /* init static data */
  3778. av_cold void dsputil_static_init(void)
  3779. {
  3780. int i;
  3781. for(i=0;i<256;i++) ff_cropTbl[i + MAX_NEG_CROP] = i;
  3782. for(i=0;i<MAX_NEG_CROP;i++) {
  3783. ff_cropTbl[i] = 0;
  3784. ff_cropTbl[i + MAX_NEG_CROP + 256] = 255;
  3785. }
  3786. for(i=0;i<512;i++) {
  3787. ff_squareTbl[i] = (i - 256) * (i - 256);
  3788. }
  3789. for(i=0; i<64; i++) inv_zigzag_direct16[ff_zigzag_direct[i]]= i+1;
  3790. }
  3791. int ff_check_alignment(void){
  3792. static int did_fail=0;
  3793. DECLARE_ALIGNED(16, int, aligned);
  3794. if((intptr_t)&aligned & 15){
  3795. if(!did_fail){
  3796. #if HAVE_MMX || HAVE_ALTIVEC
  3797. av_log(NULL, AV_LOG_ERROR,
  3798. "Compiler did not align stack variables. Libavcodec has been miscompiled\n"
  3799. "and may be very slow or crash. This is not a bug in libavcodec,\n"
  3800. "but in the compiler. You may try recompiling using gcc >= 4.2.\n"
  3801. "Do not report crashes to FFmpeg developers.\n");
  3802. #endif
  3803. did_fail=1;
  3804. }
  3805. return -1;
  3806. }
  3807. return 0;
  3808. }
  3809. av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx)
  3810. {
  3811. int i;
  3812. ff_check_alignment();
  3813. #if CONFIG_ENCODERS
  3814. if(avctx->dct_algo==FF_DCT_FASTINT) {
  3815. c->fdct = fdct_ifast;
  3816. c->fdct248 = fdct_ifast248;
  3817. }
  3818. else if(avctx->dct_algo==FF_DCT_FAAN) {
  3819. c->fdct = ff_faandct;
  3820. c->fdct248 = ff_faandct248;
  3821. }
  3822. else {
  3823. c->fdct = ff_jpeg_fdct_islow; //slow/accurate/default
  3824. c->fdct248 = ff_fdct248_islow;
  3825. }
  3826. #endif //CONFIG_ENCODERS
  3827. if(avctx->lowres==1){
  3828. if(avctx->idct_algo==FF_IDCT_INT || avctx->idct_algo==FF_IDCT_AUTO || !CONFIG_H264_DECODER){
  3829. c->idct_put= ff_jref_idct4_put;
  3830. c->idct_add= ff_jref_idct4_add;
  3831. }else{
  3832. c->idct_put= ff_h264_lowres_idct_put_c;
  3833. c->idct_add= ff_h264_lowres_idct_add_c;
  3834. }
  3835. c->idct = j_rev_dct4;
  3836. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3837. }else if(avctx->lowres==2){
  3838. c->idct_put= ff_jref_idct2_put;
  3839. c->idct_add= ff_jref_idct2_add;
  3840. c->idct = j_rev_dct2;
  3841. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3842. }else if(avctx->lowres==3){
  3843. c->idct_put= ff_jref_idct1_put;
  3844. c->idct_add= ff_jref_idct1_add;
  3845. c->idct = j_rev_dct1;
  3846. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3847. }else{
  3848. if(avctx->idct_algo==FF_IDCT_INT){
  3849. c->idct_put= ff_jref_idct_put;
  3850. c->idct_add= ff_jref_idct_add;
  3851. c->idct = j_rev_dct;
  3852. c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
  3853. }else if((CONFIG_VP3_DECODER || CONFIG_VP5_DECODER || CONFIG_VP6_DECODER ) &&
  3854. avctx->idct_algo==FF_IDCT_VP3){
  3855. c->idct_put= ff_vp3_idct_put_c;
  3856. c->idct_add= ff_vp3_idct_add_c;
  3857. c->idct = ff_vp3_idct_c;
  3858. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3859. }else if(avctx->idct_algo==FF_IDCT_WMV2){
  3860. c->idct_put= ff_wmv2_idct_put_c;
  3861. c->idct_add= ff_wmv2_idct_add_c;
  3862. c->idct = ff_wmv2_idct_c;
  3863. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3864. }else if(avctx->idct_algo==FF_IDCT_FAAN){
  3865. c->idct_put= ff_faanidct_put;
  3866. c->idct_add= ff_faanidct_add;
  3867. c->idct = ff_faanidct;
  3868. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3869. }else if(CONFIG_EATGQ_DECODER && avctx->idct_algo==FF_IDCT_EA) {
  3870. c->idct_put= ff_ea_idct_put_c;
  3871. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3872. }else if(CONFIG_BINK_DECODER && avctx->idct_algo==FF_IDCT_BINK) {
  3873. c->idct = ff_bink_idct_c;
  3874. c->idct_add = ff_bink_idct_add_c;
  3875. c->idct_put = ff_bink_idct_put_c;
  3876. c->idct_permutation_type = FF_NO_IDCT_PERM;
  3877. }else{ //accurate/default
  3878. c->idct_put= ff_simple_idct_put;
  3879. c->idct_add= ff_simple_idct_add;
  3880. c->idct = ff_simple_idct;
  3881. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3882. }
  3883. }
  3884. c->get_pixels = get_pixels_c;
  3885. c->diff_pixels = diff_pixels_c;
  3886. c->put_pixels_clamped = put_pixels_clamped_c;
  3887. c->put_signed_pixels_clamped = put_signed_pixels_clamped_c;
  3888. c->put_pixels_nonclamped = put_pixels_nonclamped_c;
  3889. c->add_pixels_clamped = add_pixels_clamped_c;
  3890. c->add_pixels8 = add_pixels8_c;
  3891. c->add_pixels4 = add_pixels4_c;
  3892. c->sum_abs_dctelem = sum_abs_dctelem_c;
  3893. c->gmc1 = gmc1_c;
  3894. c->gmc = ff_gmc_c;
  3895. c->clear_block = clear_block_c;
  3896. c->clear_blocks = clear_blocks_c;
  3897. c->pix_sum = pix_sum_c;
  3898. c->pix_norm1 = pix_norm1_c;
  3899. c->fill_block_tab[0] = fill_block16_c;
  3900. c->fill_block_tab[1] = fill_block8_c;
  3901. c->scale_block = scale_block_c;
  3902. /* TODO [0] 16 [1] 8 */
  3903. c->pix_abs[0][0] = pix_abs16_c;
  3904. c->pix_abs[0][1] = pix_abs16_x2_c;
  3905. c->pix_abs[0][2] = pix_abs16_y2_c;
  3906. c->pix_abs[0][3] = pix_abs16_xy2_c;
  3907. c->pix_abs[1][0] = pix_abs8_c;
  3908. c->pix_abs[1][1] = pix_abs8_x2_c;
  3909. c->pix_abs[1][2] = pix_abs8_y2_c;
  3910. c->pix_abs[1][3] = pix_abs8_xy2_c;
  3911. #define dspfunc(PFX, IDX, NUM) \
  3912. c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## NUM ## _c; \
  3913. c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## NUM ## _x2_c; \
  3914. c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## NUM ## _y2_c; \
  3915. c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## NUM ## _xy2_c
  3916. dspfunc(put, 0, 16);
  3917. dspfunc(put_no_rnd, 0, 16);
  3918. dspfunc(put, 1, 8);
  3919. dspfunc(put_no_rnd, 1, 8);
  3920. dspfunc(put, 2, 4);
  3921. dspfunc(put, 3, 2);
  3922. dspfunc(avg, 0, 16);
  3923. dspfunc(avg_no_rnd, 0, 16);
  3924. dspfunc(avg, 1, 8);
  3925. dspfunc(avg_no_rnd, 1, 8);
  3926. dspfunc(avg, 2, 4);
  3927. dspfunc(avg, 3, 2);
  3928. #undef dspfunc
  3929. c->put_no_rnd_pixels_l2[0]= put_no_rnd_pixels16_l2_c;
  3930. c->put_no_rnd_pixels_l2[1]= put_no_rnd_pixels8_l2_c;
  3931. c->put_tpel_pixels_tab[ 0] = put_tpel_pixels_mc00_c;
  3932. c->put_tpel_pixels_tab[ 1] = put_tpel_pixels_mc10_c;
  3933. c->put_tpel_pixels_tab[ 2] = put_tpel_pixels_mc20_c;
  3934. c->put_tpel_pixels_tab[ 4] = put_tpel_pixels_mc01_c;
  3935. c->put_tpel_pixels_tab[ 5] = put_tpel_pixels_mc11_c;
  3936. c->put_tpel_pixels_tab[ 6] = put_tpel_pixels_mc21_c;
  3937. c->put_tpel_pixels_tab[ 8] = put_tpel_pixels_mc02_c;
  3938. c->put_tpel_pixels_tab[ 9] = put_tpel_pixels_mc12_c;
  3939. c->put_tpel_pixels_tab[10] = put_tpel_pixels_mc22_c;
  3940. c->avg_tpel_pixels_tab[ 0] = avg_tpel_pixels_mc00_c;
  3941. c->avg_tpel_pixels_tab[ 1] = avg_tpel_pixels_mc10_c;
  3942. c->avg_tpel_pixels_tab[ 2] = avg_tpel_pixels_mc20_c;
  3943. c->avg_tpel_pixels_tab[ 4] = avg_tpel_pixels_mc01_c;
  3944. c->avg_tpel_pixels_tab[ 5] = avg_tpel_pixels_mc11_c;
  3945. c->avg_tpel_pixels_tab[ 6] = avg_tpel_pixels_mc21_c;
  3946. c->avg_tpel_pixels_tab[ 8] = avg_tpel_pixels_mc02_c;
  3947. c->avg_tpel_pixels_tab[ 9] = avg_tpel_pixels_mc12_c;
  3948. c->avg_tpel_pixels_tab[10] = avg_tpel_pixels_mc22_c;
  3949. #define dspfunc(PFX, IDX, NUM) \
  3950. c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \
  3951. c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \
  3952. c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \
  3953. c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \
  3954. c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \
  3955. c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \
  3956. c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \
  3957. c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \
  3958. c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \
  3959. c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \
  3960. c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \
  3961. c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \
  3962. c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \
  3963. c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \
  3964. c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \
  3965. c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
  3966. dspfunc(put_qpel, 0, 16);
  3967. dspfunc(put_no_rnd_qpel, 0, 16);
  3968. dspfunc(avg_qpel, 0, 16);
  3969. /* dspfunc(avg_no_rnd_qpel, 0, 16); */
  3970. dspfunc(put_qpel, 1, 8);
  3971. dspfunc(put_no_rnd_qpel, 1, 8);
  3972. dspfunc(avg_qpel, 1, 8);
  3973. /* dspfunc(avg_no_rnd_qpel, 1, 8); */
  3974. dspfunc(put_h264_qpel, 0, 16);
  3975. dspfunc(put_h264_qpel, 1, 8);
  3976. dspfunc(put_h264_qpel, 2, 4);
  3977. dspfunc(put_h264_qpel, 3, 2);
  3978. dspfunc(avg_h264_qpel, 0, 16);
  3979. dspfunc(avg_h264_qpel, 1, 8);
  3980. dspfunc(avg_h264_qpel, 2, 4);
  3981. #undef dspfunc
  3982. c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_c;
  3983. c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_c;
  3984. c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_c;
  3985. c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_c;
  3986. c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_c;
  3987. c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_c;
  3988. c->put_no_rnd_vc1_chroma_pixels_tab[0]= put_no_rnd_vc1_chroma_mc8_c;
  3989. c->avg_no_rnd_vc1_chroma_pixels_tab[0]= avg_no_rnd_vc1_chroma_mc8_c;
  3990. c->draw_edges = draw_edges_c;
  3991. #if CONFIG_MLP_DECODER || CONFIG_TRUEHD_DECODER
  3992. ff_mlp_init(c, avctx);
  3993. #endif
  3994. #if CONFIG_VC1_DECODER
  3995. ff_vc1dsp_init(c,avctx);
  3996. #endif
  3997. #if CONFIG_WMV2_DECODER || CONFIG_VC1_DECODER
  3998. ff_intrax8dsp_init(c,avctx);
  3999. #endif
  4000. #if CONFIG_RV30_DECODER
  4001. ff_rv30dsp_init(c,avctx);
  4002. #endif
  4003. #if CONFIG_RV40_DECODER
  4004. ff_rv40dsp_init(c,avctx);
  4005. c->put_rv40_qpel_pixels_tab[0][15] = put_rv40_qpel16_mc33_c;
  4006. c->avg_rv40_qpel_pixels_tab[0][15] = avg_rv40_qpel16_mc33_c;
  4007. c->put_rv40_qpel_pixels_tab[1][15] = put_rv40_qpel8_mc33_c;
  4008. c->avg_rv40_qpel_pixels_tab[1][15] = avg_rv40_qpel8_mc33_c;
  4009. #endif
  4010. c->put_mspel_pixels_tab[0]= put_mspel8_mc00_c;
  4011. c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
  4012. c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c;
  4013. c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c;
  4014. c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c;
  4015. c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c;
  4016. c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c;
  4017. c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c;
  4018. #define SET_CMP_FUNC(name) \
  4019. c->name[0]= name ## 16_c;\
  4020. c->name[1]= name ## 8x8_c;
  4021. SET_CMP_FUNC(hadamard8_diff)
  4022. c->hadamard8_diff[4]= hadamard8_intra16_c;
  4023. c->hadamard8_diff[5]= hadamard8_intra8x8_c;
  4024. SET_CMP_FUNC(dct_sad)
  4025. SET_CMP_FUNC(dct_max)
  4026. #if CONFIG_GPL
  4027. SET_CMP_FUNC(dct264_sad)
  4028. #endif
  4029. c->sad[0]= pix_abs16_c;
  4030. c->sad[1]= pix_abs8_c;
  4031. c->sse[0]= sse16_c;
  4032. c->sse[1]= sse8_c;
  4033. c->sse[2]= sse4_c;
  4034. SET_CMP_FUNC(quant_psnr)
  4035. SET_CMP_FUNC(rd)
  4036. SET_CMP_FUNC(bit)
  4037. c->vsad[0]= vsad16_c;
  4038. c->vsad[4]= vsad_intra16_c;
  4039. c->vsad[5]= vsad_intra8_c;
  4040. c->vsse[0]= vsse16_c;
  4041. c->vsse[4]= vsse_intra16_c;
  4042. c->vsse[5]= vsse_intra8_c;
  4043. c->nsse[0]= nsse16_c;
  4044. c->nsse[1]= nsse8_c;
  4045. #if CONFIG_DWT
  4046. ff_dsputil_init_dwt(c);
  4047. #endif
  4048. c->ssd_int8_vs_int16 = ssd_int8_vs_int16_c;
  4049. c->add_bytes= add_bytes_c;
  4050. c->add_bytes_l2= add_bytes_l2_c;
  4051. c->diff_bytes= diff_bytes_c;
  4052. c->add_hfyu_median_prediction= add_hfyu_median_prediction_c;
  4053. c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c;
  4054. c->add_hfyu_left_prediction = add_hfyu_left_prediction_c;
  4055. c->add_hfyu_left_prediction_bgr32 = add_hfyu_left_prediction_bgr32_c;
  4056. c->bswap_buf= bswap_buf;
  4057. #if CONFIG_PNG_DECODER
  4058. c->add_png_paeth_prediction= ff_add_png_paeth_prediction;
  4059. #endif
  4060. if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
  4061. c->h263_h_loop_filter= h263_h_loop_filter_c;
  4062. c->h263_v_loop_filter= h263_v_loop_filter_c;
  4063. }
  4064. if (CONFIG_VP3_DECODER) {
  4065. c->vp3_h_loop_filter= ff_vp3_h_loop_filter_c;
  4066. c->vp3_v_loop_filter= ff_vp3_v_loop_filter_c;
  4067. c->vp3_idct_dc_add= ff_vp3_idct_dc_add_c;
  4068. }
  4069. if (CONFIG_VP6_DECODER) {
  4070. c->vp6_filter_diag4= ff_vp6_filter_diag4_c;
  4071. }
  4072. c->h261_loop_filter= h261_loop_filter_c;
  4073. c->try_8x8basis= try_8x8basis_c;
  4074. c->add_8x8basis= add_8x8basis_c;
  4075. #if CONFIG_VORBIS_DECODER
  4076. c->vorbis_inverse_coupling = vorbis_inverse_coupling;
  4077. #endif
  4078. #if CONFIG_AC3_DECODER
  4079. c->ac3_downmix = ff_ac3_downmix_c;
  4080. #endif
  4081. #if CONFIG_LPC
  4082. c->lpc_compute_autocorr = ff_lpc_compute_autocorr;
  4083. #endif
  4084. c->vector_fmul = vector_fmul_c;
  4085. c->vector_fmul_reverse = vector_fmul_reverse_c;
  4086. c->vector_fmul_add = vector_fmul_add_c;
  4087. c->vector_fmul_window = ff_vector_fmul_window_c;
  4088. c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_c;
  4089. c->vector_clipf = vector_clipf_c;
  4090. c->float_to_int16 = ff_float_to_int16_c;
  4091. c->float_to_int16_interleave = ff_float_to_int16_interleave_c;
  4092. c->scalarproduct_int16 = scalarproduct_int16_c;
  4093. c->scalarproduct_and_madd_int16 = scalarproduct_and_madd_int16_c;
  4094. c->scalarproduct_float = scalarproduct_float_c;
  4095. c->butterflies_float = butterflies_float_c;
  4096. c->vector_fmul_scalar = vector_fmul_scalar_c;
  4097. c->vector_fmul_sv_scalar[0] = vector_fmul_sv_scalar_2_c;
  4098. c->vector_fmul_sv_scalar[1] = vector_fmul_sv_scalar_4_c;
  4099. c->sv_fmul_scalar[0] = sv_fmul_scalar_2_c;
  4100. c->sv_fmul_scalar[1] = sv_fmul_scalar_4_c;
  4101. c->shrink[0]= ff_img_copy_plane;
  4102. c->shrink[1]= ff_shrink22;
  4103. c->shrink[2]= ff_shrink44;
  4104. c->shrink[3]= ff_shrink88;
  4105. c->prefetch= just_return;
  4106. memset(c->put_2tap_qpel_pixels_tab, 0, sizeof(c->put_2tap_qpel_pixels_tab));
  4107. memset(c->avg_2tap_qpel_pixels_tab, 0, sizeof(c->avg_2tap_qpel_pixels_tab));
  4108. if (HAVE_MMX) dsputil_init_mmx (c, avctx);
  4109. if (ARCH_ARM) dsputil_init_arm (c, avctx);
  4110. if (CONFIG_MLIB) dsputil_init_mlib (c, avctx);
  4111. if (HAVE_VIS) dsputil_init_vis (c, avctx);
  4112. if (ARCH_ALPHA) dsputil_init_alpha (c, avctx);
  4113. if (ARCH_PPC) dsputil_init_ppc (c, avctx);
  4114. if (HAVE_MMI) dsputil_init_mmi (c, avctx);
  4115. if (ARCH_SH4) dsputil_init_sh4 (c, avctx);
  4116. if (ARCH_BFIN) dsputil_init_bfin (c, avctx);
  4117. for(i=0; i<64; i++){
  4118. if(!c->put_2tap_qpel_pixels_tab[0][i])
  4119. c->put_2tap_qpel_pixels_tab[0][i]= c->put_h264_qpel_pixels_tab[0][i];
  4120. if(!c->avg_2tap_qpel_pixels_tab[0][i])
  4121. c->avg_2tap_qpel_pixels_tab[0][i]= c->avg_h264_qpel_pixels_tab[0][i];
  4122. }
  4123. c->put_rv30_tpel_pixels_tab[0][0] = c->put_h264_qpel_pixels_tab[0][0];
  4124. c->put_rv30_tpel_pixels_tab[1][0] = c->put_h264_qpel_pixels_tab[1][0];
  4125. c->avg_rv30_tpel_pixels_tab[0][0] = c->avg_h264_qpel_pixels_tab[0][0];
  4126. c->avg_rv30_tpel_pixels_tab[1][0] = c->avg_h264_qpel_pixels_tab[1][0];
  4127. c->put_rv40_qpel_pixels_tab[0][0] = c->put_h264_qpel_pixels_tab[0][0];
  4128. c->put_rv40_qpel_pixels_tab[1][0] = c->put_h264_qpel_pixels_tab[1][0];
  4129. c->avg_rv40_qpel_pixels_tab[0][0] = c->avg_h264_qpel_pixels_tab[0][0];
  4130. c->avg_rv40_qpel_pixels_tab[1][0] = c->avg_h264_qpel_pixels_tab[1][0];
  4131. switch(c->idct_permutation_type){
  4132. case FF_NO_IDCT_PERM:
  4133. for(i=0; i<64; i++)
  4134. c->idct_permutation[i]= i;
  4135. break;
  4136. case FF_LIBMPEG2_IDCT_PERM:
  4137. for(i=0; i<64; i++)
  4138. c->idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
  4139. break;
  4140. case FF_SIMPLE_IDCT_PERM:
  4141. for(i=0; i<64; i++)
  4142. c->idct_permutation[i]= simple_mmx_permutation[i];
  4143. break;
  4144. case FF_TRANSPOSE_IDCT_PERM:
  4145. for(i=0; i<64; i++)
  4146. c->idct_permutation[i]= ((i&7)<<3) | (i>>3);
  4147. break;
  4148. case FF_PARTTRANS_IDCT_PERM:
  4149. for(i=0; i<64; i++)
  4150. c->idct_permutation[i]= (i&0x24) | ((i&3)<<3) | ((i>>3)&3);
  4151. break;
  4152. case FF_SSE2_IDCT_PERM:
  4153. for(i=0; i<64; i++)
  4154. c->idct_permutation[i]= (i&0x38) | idct_sse2_row_perm[i&7];
  4155. break;
  4156. default:
  4157. av_log(avctx, AV_LOG_ERROR, "Internal error, IDCT permutation not set\n");
  4158. }
  4159. }