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.

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