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.

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