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.

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