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.

4449 lines
154KB

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