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.

4520 lines
158KB

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