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.

4352 lines
154KB

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