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.

4199 lines
149KB

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