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.

4359 lines
155KB

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