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.

4327 lines
153KB

  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. if(D){\
  1344. for(i=0; i<h; i++){\
  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. }else{\
  1351. const int E= B+C;\
  1352. const int step= C ? stride : 1;\
  1353. for(i=0; i<h; i++){\
  1354. OP(dst[0], (A*src[0] + E*src[step+0]));\
  1355. OP(dst[1], (A*src[1] + E*src[step+1]));\
  1356. dst+= stride;\
  1357. src+= stride;\
  1358. }\
  1359. }\
  1360. }\
  1361. \
  1362. 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){\
  1363. const int A=(8-x)*(8-y);\
  1364. const int B=( x)*(8-y);\
  1365. const int C=(8-x)*( y);\
  1366. const int D=( x)*( y);\
  1367. int i;\
  1368. \
  1369. assert(x<8 && y<8 && x>=0 && y>=0);\
  1370. \
  1371. if(D){\
  1372. for(i=0; i<h; i++){\
  1373. OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
  1374. OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
  1375. OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
  1376. OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
  1377. dst+= stride;\
  1378. src+= stride;\
  1379. }\
  1380. }else{\
  1381. const int E= B+C;\
  1382. const int step= C ? stride : 1;\
  1383. for(i=0; i<h; i++){\
  1384. OP(dst[0], (A*src[0] + E*src[step+0]));\
  1385. OP(dst[1], (A*src[1] + E*src[step+1]));\
  1386. OP(dst[2], (A*src[2] + E*src[step+2]));\
  1387. OP(dst[3], (A*src[3] + E*src[step+3]));\
  1388. dst+= stride;\
  1389. src+= stride;\
  1390. }\
  1391. }\
  1392. }\
  1393. \
  1394. 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){\
  1395. const int A=(8-x)*(8-y);\
  1396. const int B=( x)*(8-y);\
  1397. const int C=(8-x)*( y);\
  1398. const int D=( x)*( y);\
  1399. int i;\
  1400. \
  1401. assert(x<8 && y<8 && x>=0 && y>=0);\
  1402. \
  1403. if(D){\
  1404. for(i=0; i<h; i++){\
  1405. OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
  1406. OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
  1407. OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
  1408. OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
  1409. OP(dst[4], (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5]));\
  1410. OP(dst[5], (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6]));\
  1411. OP(dst[6], (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7]));\
  1412. OP(dst[7], (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8]));\
  1413. dst+= stride;\
  1414. src+= stride;\
  1415. }\
  1416. }else{\
  1417. const int E= B+C;\
  1418. const int step= C ? stride : 1;\
  1419. for(i=0; i<h; i++){\
  1420. OP(dst[0], (A*src[0] + E*src[step+0]));\
  1421. OP(dst[1], (A*src[1] + E*src[step+1]));\
  1422. OP(dst[2], (A*src[2] + E*src[step+2]));\
  1423. OP(dst[3], (A*src[3] + E*src[step+3]));\
  1424. OP(dst[4], (A*src[4] + E*src[step+4]));\
  1425. OP(dst[5], (A*src[5] + E*src[step+5]));\
  1426. OP(dst[6], (A*src[6] + E*src[step+6]));\
  1427. OP(dst[7], (A*src[7] + E*src[step+7]));\
  1428. dst+= stride;\
  1429. src+= stride;\
  1430. }\
  1431. }\
  1432. }
  1433. #define op_avg(a, b) a = (((a)+(((b) + 32)>>6)+1)>>1)
  1434. #define op_put(a, b) a = (((b) + 32)>>6)
  1435. H264_CHROMA_MC(put_ , op_put)
  1436. H264_CHROMA_MC(avg_ , op_avg)
  1437. #undef op_avg
  1438. #undef op_put
  1439. 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){
  1440. const int A=(8-x)*(8-y);
  1441. const int B=( x)*(8-y);
  1442. const int C=(8-x)*( y);
  1443. const int D=( x)*( y);
  1444. int i;
  1445. assert(x<8 && y<8 && x>=0 && y>=0);
  1446. for(i=0; i<h; i++)
  1447. {
  1448. dst[0] = (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6;
  1449. dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6;
  1450. dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6;
  1451. dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6;
  1452. dst[4] = (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6;
  1453. dst[5] = (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6;
  1454. dst[6] = (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6;
  1455. dst[7] = (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6;
  1456. dst+= stride;
  1457. src+= stride;
  1458. }
  1459. }
  1460. #define QPEL_MC(r, OPNAME, RND, OP) \
  1461. static void OPNAME ## mpeg4_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  1462. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  1463. int i;\
  1464. for(i=0; i<h; i++)\
  1465. {\
  1466. OP(dst[0], (src[0]+src[1])*20 - (src[0]+src[2])*6 + (src[1]+src[3])*3 - (src[2]+src[4]));\
  1467. OP(dst[1], (src[1]+src[2])*20 - (src[0]+src[3])*6 + (src[0]+src[4])*3 - (src[1]+src[5]));\
  1468. OP(dst[2], (src[2]+src[3])*20 - (src[1]+src[4])*6 + (src[0]+src[5])*3 - (src[0]+src[6]));\
  1469. OP(dst[3], (src[3]+src[4])*20 - (src[2]+src[5])*6 + (src[1]+src[6])*3 - (src[0]+src[7]));\
  1470. OP(dst[4], (src[4]+src[5])*20 - (src[3]+src[6])*6 + (src[2]+src[7])*3 - (src[1]+src[8]));\
  1471. OP(dst[5], (src[5]+src[6])*20 - (src[4]+src[7])*6 + (src[3]+src[8])*3 - (src[2]+src[8]));\
  1472. OP(dst[6], (src[6]+src[7])*20 - (src[5]+src[8])*6 + (src[4]+src[8])*3 - (src[3]+src[7]));\
  1473. OP(dst[7], (src[7]+src[8])*20 - (src[6]+src[8])*6 + (src[5]+src[7])*3 - (src[4]+src[6]));\
  1474. dst+=dstStride;\
  1475. src+=srcStride;\
  1476. }\
  1477. }\
  1478. \
  1479. static void OPNAME ## mpeg4_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1480. const int w=8;\
  1481. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  1482. int i;\
  1483. for(i=0; i<w; i++)\
  1484. {\
  1485. const int src0= src[0*srcStride];\
  1486. const int src1= src[1*srcStride];\
  1487. const int src2= src[2*srcStride];\
  1488. const int src3= src[3*srcStride];\
  1489. const int src4= src[4*srcStride];\
  1490. const int src5= src[5*srcStride];\
  1491. const int src6= src[6*srcStride];\
  1492. const int src7= src[7*srcStride];\
  1493. const int src8= src[8*srcStride];\
  1494. OP(dst[0*dstStride], (src0+src1)*20 - (src0+src2)*6 + (src1+src3)*3 - (src2+src4));\
  1495. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*6 + (src0+src4)*3 - (src1+src5));\
  1496. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*6 + (src0+src5)*3 - (src0+src6));\
  1497. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*6 + (src1+src6)*3 - (src0+src7));\
  1498. OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*6 + (src2+src7)*3 - (src1+src8));\
  1499. OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*6 + (src3+src8)*3 - (src2+src8));\
  1500. OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*6 + (src4+src8)*3 - (src3+src7));\
  1501. OP(dst[7*dstStride], (src7+src8)*20 - (src6+src8)*6 + (src5+src7)*3 - (src4+src6));\
  1502. dst++;\
  1503. src++;\
  1504. }\
  1505. }\
  1506. \
  1507. static void OPNAME ## mpeg4_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  1508. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  1509. int i;\
  1510. \
  1511. for(i=0; i<h; i++)\
  1512. {\
  1513. OP(dst[ 0], (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]));\
  1514. OP(dst[ 1], (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]));\
  1515. OP(dst[ 2], (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]));\
  1516. OP(dst[ 3], (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]));\
  1517. OP(dst[ 4], (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]));\
  1518. OP(dst[ 5], (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]));\
  1519. OP(dst[ 6], (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]));\
  1520. OP(dst[ 7], (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]));\
  1521. OP(dst[ 8], (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]));\
  1522. OP(dst[ 9], (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]));\
  1523. OP(dst[10], (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]));\
  1524. OP(dst[11], (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]));\
  1525. OP(dst[12], (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]));\
  1526. OP(dst[13], (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]));\
  1527. OP(dst[14], (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]));\
  1528. OP(dst[15], (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]));\
  1529. dst+=dstStride;\
  1530. src+=srcStride;\
  1531. }\
  1532. }\
  1533. \
  1534. static void OPNAME ## mpeg4_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1535. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  1536. int i;\
  1537. const int w=16;\
  1538. for(i=0; i<w; i++)\
  1539. {\
  1540. const int src0= src[0*srcStride];\
  1541. const int src1= src[1*srcStride];\
  1542. const int src2= src[2*srcStride];\
  1543. const int src3= src[3*srcStride];\
  1544. const int src4= src[4*srcStride];\
  1545. const int src5= src[5*srcStride];\
  1546. const int src6= src[6*srcStride];\
  1547. const int src7= src[7*srcStride];\
  1548. const int src8= src[8*srcStride];\
  1549. const int src9= src[9*srcStride];\
  1550. const int src10= src[10*srcStride];\
  1551. const int src11= src[11*srcStride];\
  1552. const int src12= src[12*srcStride];\
  1553. const int src13= src[13*srcStride];\
  1554. const int src14= src[14*srcStride];\
  1555. const int src15= src[15*srcStride];\
  1556. const int src16= src[16*srcStride];\
  1557. OP(dst[ 0*dstStride], (src0 +src1 )*20 - (src0 +src2 )*6 + (src1 +src3 )*3 - (src2 +src4 ));\
  1558. OP(dst[ 1*dstStride], (src1 +src2 )*20 - (src0 +src3 )*6 + (src0 +src4 )*3 - (src1 +src5 ));\
  1559. OP(dst[ 2*dstStride], (src2 +src3 )*20 - (src1 +src4 )*6 + (src0 +src5 )*3 - (src0 +src6 ));\
  1560. OP(dst[ 3*dstStride], (src3 +src4 )*20 - (src2 +src5 )*6 + (src1 +src6 )*3 - (src0 +src7 ));\
  1561. OP(dst[ 4*dstStride], (src4 +src5 )*20 - (src3 +src6 )*6 + (src2 +src7 )*3 - (src1 +src8 ));\
  1562. OP(dst[ 5*dstStride], (src5 +src6 )*20 - (src4 +src7 )*6 + (src3 +src8 )*3 - (src2 +src9 ));\
  1563. OP(dst[ 6*dstStride], (src6 +src7 )*20 - (src5 +src8 )*6 + (src4 +src9 )*3 - (src3 +src10));\
  1564. OP(dst[ 7*dstStride], (src7 +src8 )*20 - (src6 +src9 )*6 + (src5 +src10)*3 - (src4 +src11));\
  1565. OP(dst[ 8*dstStride], (src8 +src9 )*20 - (src7 +src10)*6 + (src6 +src11)*3 - (src5 +src12));\
  1566. OP(dst[ 9*dstStride], (src9 +src10)*20 - (src8 +src11)*6 + (src7 +src12)*3 - (src6 +src13));\
  1567. OP(dst[10*dstStride], (src10+src11)*20 - (src9 +src12)*6 + (src8 +src13)*3 - (src7 +src14));\
  1568. OP(dst[11*dstStride], (src11+src12)*20 - (src10+src13)*6 + (src9 +src14)*3 - (src8 +src15));\
  1569. OP(dst[12*dstStride], (src12+src13)*20 - (src11+src14)*6 + (src10+src15)*3 - (src9 +src16));\
  1570. OP(dst[13*dstStride], (src13+src14)*20 - (src12+src15)*6 + (src11+src16)*3 - (src10+src16));\
  1571. OP(dst[14*dstStride], (src14+src15)*20 - (src13+src16)*6 + (src12+src16)*3 - (src11+src15));\
  1572. OP(dst[15*dstStride], (src15+src16)*20 - (src14+src16)*6 + (src13+src15)*3 - (src12+src14));\
  1573. dst++;\
  1574. src++;\
  1575. }\
  1576. }\
  1577. \
  1578. static void OPNAME ## qpel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
  1579. OPNAME ## pixels8_c(dst, src, stride, 8);\
  1580. }\
  1581. \
  1582. static void OPNAME ## qpel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  1583. uint8_t half[64];\
  1584. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  1585. OPNAME ## pixels8_l2(dst, src, half, stride, stride, 8, 8);\
  1586. }\
  1587. \
  1588. static void OPNAME ## qpel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  1589. OPNAME ## mpeg4_qpel8_h_lowpass(dst, src, stride, stride, 8);\
  1590. }\
  1591. \
  1592. static void OPNAME ## qpel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  1593. uint8_t half[64];\
  1594. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  1595. OPNAME ## pixels8_l2(dst, src+1, half, stride, stride, 8, 8);\
  1596. }\
  1597. \
  1598. static void OPNAME ## qpel8_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  1599. uint8_t full[16*9];\
  1600. uint8_t half[64];\
  1601. copy_block9(full, src, 16, stride, 9);\
  1602. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
  1603. OPNAME ## pixels8_l2(dst, full, half, stride, 16, 8, 8);\
  1604. }\
  1605. \
  1606. static void OPNAME ## qpel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  1607. uint8_t full[16*9];\
  1608. copy_block9(full, src, 16, stride, 9);\
  1609. OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);\
  1610. }\
  1611. \
  1612. static void OPNAME ## qpel8_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  1613. uint8_t full[16*9];\
  1614. uint8_t half[64];\
  1615. copy_block9(full, src, 16, stride, 9);\
  1616. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
  1617. OPNAME ## pixels8_l2(dst, full+16, half, stride, 16, 8, 8);\
  1618. }\
  1619. void ff_ ## OPNAME ## qpel8_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1620. uint8_t full[16*9];\
  1621. uint8_t halfH[72];\
  1622. uint8_t halfV[64];\
  1623. uint8_t halfHV[64];\
  1624. copy_block9(full, src, 16, stride, 9);\
  1625. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1626. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  1627. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1628. OPNAME ## pixels8_l4(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1629. }\
  1630. static void OPNAME ## qpel8_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  1631. uint8_t full[16*9];\
  1632. uint8_t halfH[72];\
  1633. uint8_t halfHV[64];\
  1634. copy_block9(full, src, 16, stride, 9);\
  1635. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1636. put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
  1637. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1638. OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
  1639. }\
  1640. void ff_ ## OPNAME ## qpel8_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1641. uint8_t full[16*9];\
  1642. uint8_t halfH[72];\
  1643. uint8_t halfV[64];\
  1644. uint8_t halfHV[64];\
  1645. copy_block9(full, src, 16, stride, 9);\
  1646. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1647. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  1648. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1649. OPNAME ## pixels8_l4(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1650. }\
  1651. static void OPNAME ## qpel8_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  1652. uint8_t full[16*9];\
  1653. uint8_t halfH[72];\
  1654. uint8_t halfHV[64];\
  1655. copy_block9(full, src, 16, stride, 9);\
  1656. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1657. put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
  1658. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1659. OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
  1660. }\
  1661. void ff_ ## OPNAME ## qpel8_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1662. uint8_t full[16*9];\
  1663. uint8_t halfH[72];\
  1664. uint8_t halfV[64];\
  1665. uint8_t halfHV[64];\
  1666. copy_block9(full, src, 16, stride, 9);\
  1667. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1668. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  1669. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1670. OPNAME ## pixels8_l4(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1671. }\
  1672. static void OPNAME ## qpel8_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  1673. uint8_t full[16*9];\
  1674. uint8_t halfH[72];\
  1675. uint8_t halfHV[64];\
  1676. copy_block9(full, src, 16, stride, 9);\
  1677. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1678. put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
  1679. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1680. OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  1681. }\
  1682. void ff_ ## OPNAME ## qpel8_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1683. uint8_t full[16*9];\
  1684. uint8_t halfH[72];\
  1685. uint8_t halfV[64];\
  1686. uint8_t halfHV[64];\
  1687. copy_block9(full, src, 16, stride, 9);\
  1688. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full , 8, 16, 9);\
  1689. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  1690. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1691. OPNAME ## pixels8_l4(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1692. }\
  1693. static void OPNAME ## qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  1694. uint8_t full[16*9];\
  1695. uint8_t halfH[72];\
  1696. uint8_t halfHV[64];\
  1697. copy_block9(full, src, 16, stride, 9);\
  1698. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1699. put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
  1700. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1701. OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  1702. }\
  1703. static void OPNAME ## qpel8_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  1704. uint8_t halfH[72];\
  1705. uint8_t halfHV[64];\
  1706. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1707. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1708. OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
  1709. }\
  1710. static void OPNAME ## qpel8_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  1711. uint8_t halfH[72];\
  1712. uint8_t halfHV[64];\
  1713. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1714. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1715. OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  1716. }\
  1717. void ff_ ## OPNAME ## qpel8_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1718. uint8_t full[16*9];\
  1719. uint8_t halfH[72];\
  1720. uint8_t halfV[64];\
  1721. uint8_t halfHV[64];\
  1722. copy_block9(full, src, 16, stride, 9);\
  1723. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1724. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  1725. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1726. OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
  1727. }\
  1728. static void OPNAME ## qpel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  1729. uint8_t full[16*9];\
  1730. uint8_t halfH[72];\
  1731. copy_block9(full, src, 16, stride, 9);\
  1732. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1733. put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
  1734. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1735. }\
  1736. void ff_ ## OPNAME ## qpel8_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1737. uint8_t full[16*9];\
  1738. uint8_t halfH[72];\
  1739. uint8_t halfV[64];\
  1740. uint8_t halfHV[64];\
  1741. copy_block9(full, src, 16, stride, 9);\
  1742. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1743. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  1744. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1745. OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
  1746. }\
  1747. static void OPNAME ## qpel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  1748. uint8_t full[16*9];\
  1749. uint8_t halfH[72];\
  1750. copy_block9(full, src, 16, stride, 9);\
  1751. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1752. put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
  1753. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1754. }\
  1755. static void OPNAME ## qpel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  1756. uint8_t halfH[72];\
  1757. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1758. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1759. }\
  1760. static void OPNAME ## qpel16_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
  1761. OPNAME ## pixels16_c(dst, src, stride, 16);\
  1762. }\
  1763. \
  1764. static void OPNAME ## qpel16_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  1765. uint8_t half[256];\
  1766. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  1767. OPNAME ## pixels16_l2(dst, src, half, stride, stride, 16, 16);\
  1768. }\
  1769. \
  1770. static void OPNAME ## qpel16_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  1771. OPNAME ## mpeg4_qpel16_h_lowpass(dst, src, stride, stride, 16);\
  1772. }\
  1773. \
  1774. static void OPNAME ## qpel16_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  1775. uint8_t half[256];\
  1776. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  1777. OPNAME ## pixels16_l2(dst, src+1, half, stride, stride, 16, 16);\
  1778. }\
  1779. \
  1780. static void OPNAME ## qpel16_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  1781. uint8_t full[24*17];\
  1782. uint8_t half[256];\
  1783. copy_block17(full, src, 24, stride, 17);\
  1784. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
  1785. OPNAME ## pixels16_l2(dst, full, half, stride, 24, 16, 16);\
  1786. }\
  1787. \
  1788. static void OPNAME ## qpel16_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  1789. uint8_t full[24*17];\
  1790. copy_block17(full, src, 24, stride, 17);\
  1791. OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);\
  1792. }\
  1793. \
  1794. static void OPNAME ## qpel16_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  1795. uint8_t full[24*17];\
  1796. uint8_t half[256];\
  1797. copy_block17(full, src, 24, stride, 17);\
  1798. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
  1799. OPNAME ## pixels16_l2(dst, full+24, half, stride, 24, 16, 16);\
  1800. }\
  1801. void ff_ ## OPNAME ## qpel16_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1802. uint8_t full[24*17];\
  1803. uint8_t halfH[272];\
  1804. uint8_t halfV[256];\
  1805. uint8_t halfHV[256];\
  1806. copy_block17(full, src, 24, stride, 17);\
  1807. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1808. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1809. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1810. OPNAME ## pixels16_l4(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1811. }\
  1812. static void OPNAME ## qpel16_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  1813. uint8_t full[24*17];\
  1814. uint8_t halfH[272];\
  1815. uint8_t halfHV[256];\
  1816. copy_block17(full, src, 24, stride, 17);\
  1817. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1818. put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
  1819. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1820. OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
  1821. }\
  1822. void ff_ ## OPNAME ## qpel16_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1823. uint8_t full[24*17];\
  1824. uint8_t halfH[272];\
  1825. uint8_t halfV[256];\
  1826. uint8_t halfHV[256];\
  1827. copy_block17(full, src, 24, stride, 17);\
  1828. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1829. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1830. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1831. OPNAME ## pixels16_l4(dst, full+1, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1832. }\
  1833. static void OPNAME ## qpel16_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  1834. uint8_t full[24*17];\
  1835. uint8_t halfH[272];\
  1836. uint8_t halfHV[256];\
  1837. copy_block17(full, src, 24, stride, 17);\
  1838. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1839. put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
  1840. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1841. OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
  1842. }\
  1843. void ff_ ## OPNAME ## qpel16_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1844. uint8_t full[24*17];\
  1845. uint8_t halfH[272];\
  1846. uint8_t halfV[256];\
  1847. uint8_t halfHV[256];\
  1848. copy_block17(full, src, 24, stride, 17);\
  1849. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1850. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1851. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1852. OPNAME ## pixels16_l4(dst, full+24, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1853. }\
  1854. static void OPNAME ## qpel16_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  1855. uint8_t full[24*17];\
  1856. uint8_t halfH[272];\
  1857. uint8_t halfHV[256];\
  1858. copy_block17(full, src, 24, stride, 17);\
  1859. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1860. put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
  1861. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1862. OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1863. }\
  1864. void ff_ ## OPNAME ## qpel16_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1865. uint8_t full[24*17];\
  1866. uint8_t halfH[272];\
  1867. uint8_t halfV[256];\
  1868. uint8_t halfHV[256];\
  1869. copy_block17(full, src, 24, stride, 17);\
  1870. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full , 16, 24, 17);\
  1871. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1872. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1873. OPNAME ## pixels16_l4(dst, full+25, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1874. }\
  1875. static void OPNAME ## qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  1876. uint8_t full[24*17];\
  1877. uint8_t halfH[272];\
  1878. uint8_t halfHV[256];\
  1879. copy_block17(full, src, 24, stride, 17);\
  1880. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1881. put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
  1882. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1883. OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1884. }\
  1885. static void OPNAME ## qpel16_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  1886. uint8_t halfH[272];\
  1887. uint8_t halfHV[256];\
  1888. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1889. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1890. OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
  1891. }\
  1892. static void OPNAME ## qpel16_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  1893. uint8_t halfH[272];\
  1894. uint8_t halfHV[256];\
  1895. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1896. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1897. OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1898. }\
  1899. void ff_ ## OPNAME ## qpel16_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1900. uint8_t full[24*17];\
  1901. uint8_t halfH[272];\
  1902. uint8_t halfV[256];\
  1903. uint8_t halfHV[256];\
  1904. copy_block17(full, src, 24, stride, 17);\
  1905. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1906. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1907. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1908. OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
  1909. }\
  1910. static void OPNAME ## qpel16_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  1911. uint8_t full[24*17];\
  1912. uint8_t halfH[272];\
  1913. copy_block17(full, src, 24, stride, 17);\
  1914. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1915. put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
  1916. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1917. }\
  1918. void ff_ ## OPNAME ## qpel16_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1919. uint8_t full[24*17];\
  1920. uint8_t halfH[272];\
  1921. uint8_t halfV[256];\
  1922. uint8_t halfHV[256];\
  1923. copy_block17(full, src, 24, stride, 17);\
  1924. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1925. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1926. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1927. OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
  1928. }\
  1929. static void OPNAME ## qpel16_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  1930. uint8_t full[24*17];\
  1931. uint8_t halfH[272];\
  1932. copy_block17(full, src, 24, stride, 17);\
  1933. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1934. put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
  1935. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1936. }\
  1937. static void OPNAME ## qpel16_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  1938. uint8_t halfH[272];\
  1939. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1940. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1941. }
  1942. #define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
  1943. #define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1)
  1944. #define op_put(a, b) a = cm[((b) + 16)>>5]
  1945. #define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5]
  1946. QPEL_MC(0, put_ , _ , op_put)
  1947. QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd)
  1948. QPEL_MC(0, avg_ , _ , op_avg)
  1949. //QPEL_MC(1, avg_no_rnd , _ , op_avg)
  1950. #undef op_avg
  1951. #undef op_avg_no_rnd
  1952. #undef op_put
  1953. #undef op_put_no_rnd
  1954. #if 1
  1955. #define H264_LOWPASS(OPNAME, OP, OP2) \
  1956. static av_unused void OPNAME ## h264_qpel2_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1957. const int h=2;\
  1958. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  1959. int i;\
  1960. for(i=0; i<h; i++)\
  1961. {\
  1962. OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
  1963. OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
  1964. dst+=dstStride;\
  1965. src+=srcStride;\
  1966. }\
  1967. }\
  1968. \
  1969. static av_unused void OPNAME ## h264_qpel2_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1970. const int w=2;\
  1971. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  1972. int i;\
  1973. for(i=0; i<w; i++)\
  1974. {\
  1975. const int srcB= src[-2*srcStride];\
  1976. const int srcA= src[-1*srcStride];\
  1977. const int src0= src[0 *srcStride];\
  1978. const int src1= src[1 *srcStride];\
  1979. const int src2= src[2 *srcStride];\
  1980. const int src3= src[3 *srcStride];\
  1981. const int src4= src[4 *srcStride];\
  1982. OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
  1983. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
  1984. dst++;\
  1985. src++;\
  1986. }\
  1987. }\
  1988. \
  1989. static av_unused void OPNAME ## h264_qpel2_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  1990. const int h=2;\
  1991. const int w=2;\
  1992. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  1993. int i;\
  1994. src -= 2*srcStride;\
  1995. for(i=0; i<h+5; i++)\
  1996. {\
  1997. tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
  1998. tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
  1999. tmp+=tmpStride;\
  2000. src+=srcStride;\
  2001. }\
  2002. tmp -= tmpStride*(h+5-2);\
  2003. for(i=0; i<w; i++)\
  2004. {\
  2005. const int tmpB= tmp[-2*tmpStride];\
  2006. const int tmpA= tmp[-1*tmpStride];\
  2007. const int tmp0= tmp[0 *tmpStride];\
  2008. const int tmp1= tmp[1 *tmpStride];\
  2009. const int tmp2= tmp[2 *tmpStride];\
  2010. const int tmp3= tmp[3 *tmpStride];\
  2011. const int tmp4= tmp[4 *tmpStride];\
  2012. OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
  2013. OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
  2014. dst++;\
  2015. tmp++;\
  2016. }\
  2017. }\
  2018. static void OPNAME ## h264_qpel4_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2019. const int h=4;\
  2020. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2021. int i;\
  2022. for(i=0; i<h; i++)\
  2023. {\
  2024. OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
  2025. OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
  2026. OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]));\
  2027. OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]));\
  2028. dst+=dstStride;\
  2029. src+=srcStride;\
  2030. }\
  2031. }\
  2032. \
  2033. static void OPNAME ## h264_qpel4_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2034. const int w=4;\
  2035. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2036. int i;\
  2037. for(i=0; i<w; i++)\
  2038. {\
  2039. const int srcB= src[-2*srcStride];\
  2040. const int srcA= src[-1*srcStride];\
  2041. const int src0= src[0 *srcStride];\
  2042. const int src1= src[1 *srcStride];\
  2043. const int src2= src[2 *srcStride];\
  2044. const int src3= src[3 *srcStride];\
  2045. const int src4= src[4 *srcStride];\
  2046. const int src5= src[5 *srcStride];\
  2047. const int src6= src[6 *srcStride];\
  2048. OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
  2049. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
  2050. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
  2051. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
  2052. dst++;\
  2053. src++;\
  2054. }\
  2055. }\
  2056. \
  2057. static void OPNAME ## h264_qpel4_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  2058. const int h=4;\
  2059. const int w=4;\
  2060. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2061. int i;\
  2062. src -= 2*srcStride;\
  2063. for(i=0; i<h+5; i++)\
  2064. {\
  2065. tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
  2066. tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
  2067. tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]);\
  2068. tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]);\
  2069. tmp+=tmpStride;\
  2070. src+=srcStride;\
  2071. }\
  2072. tmp -= tmpStride*(h+5-2);\
  2073. for(i=0; i<w; i++)\
  2074. {\
  2075. const int tmpB= tmp[-2*tmpStride];\
  2076. const int tmpA= tmp[-1*tmpStride];\
  2077. const int tmp0= tmp[0 *tmpStride];\
  2078. const int tmp1= tmp[1 *tmpStride];\
  2079. const int tmp2= tmp[2 *tmpStride];\
  2080. const int tmp3= tmp[3 *tmpStride];\
  2081. const int tmp4= tmp[4 *tmpStride];\
  2082. const int tmp5= tmp[5 *tmpStride];\
  2083. const int tmp6= tmp[6 *tmpStride];\
  2084. OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
  2085. OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
  2086. OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
  2087. OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
  2088. dst++;\
  2089. tmp++;\
  2090. }\
  2091. }\
  2092. \
  2093. static void OPNAME ## h264_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2094. const int h=8;\
  2095. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2096. int i;\
  2097. for(i=0; i<h; i++)\
  2098. {\
  2099. OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]));\
  2100. OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]));\
  2101. OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]));\
  2102. OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]));\
  2103. OP(dst[4], (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]));\
  2104. OP(dst[5], (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]));\
  2105. OP(dst[6], (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]));\
  2106. OP(dst[7], (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]));\
  2107. dst+=dstStride;\
  2108. src+=srcStride;\
  2109. }\
  2110. }\
  2111. \
  2112. static void OPNAME ## h264_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2113. const int w=8;\
  2114. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2115. int i;\
  2116. for(i=0; i<w; i++)\
  2117. {\
  2118. const int srcB= src[-2*srcStride];\
  2119. const int srcA= src[-1*srcStride];\
  2120. const int src0= src[0 *srcStride];\
  2121. const int src1= src[1 *srcStride];\
  2122. const int src2= src[2 *srcStride];\
  2123. const int src3= src[3 *srcStride];\
  2124. const int src4= src[4 *srcStride];\
  2125. const int src5= src[5 *srcStride];\
  2126. const int src6= src[6 *srcStride];\
  2127. const int src7= src[7 *srcStride];\
  2128. const int src8= src[8 *srcStride];\
  2129. const int src9= src[9 *srcStride];\
  2130. const int src10=src[10*srcStride];\
  2131. OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
  2132. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
  2133. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
  2134. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
  2135. OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*5 + (src2+src7));\
  2136. OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*5 + (src3+src8));\
  2137. OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*5 + (src4+src9));\
  2138. OP(dst[7*dstStride], (src7+src8)*20 - (src6+src9)*5 + (src5+src10));\
  2139. dst++;\
  2140. src++;\
  2141. }\
  2142. }\
  2143. \
  2144. static void OPNAME ## h264_qpel8_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  2145. const int h=8;\
  2146. const int w=8;\
  2147. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\
  2148. int i;\
  2149. src -= 2*srcStride;\
  2150. for(i=0; i<h+5; i++)\
  2151. {\
  2152. tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]);\
  2153. tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]);\
  2154. tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]);\
  2155. tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]);\
  2156. tmp[4]= (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]);\
  2157. tmp[5]= (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]);\
  2158. tmp[6]= (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]);\
  2159. tmp[7]= (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]);\
  2160. tmp+=tmpStride;\
  2161. src+=srcStride;\
  2162. }\
  2163. tmp -= tmpStride*(h+5-2);\
  2164. for(i=0; i<w; i++)\
  2165. {\
  2166. const int tmpB= tmp[-2*tmpStride];\
  2167. const int tmpA= tmp[-1*tmpStride];\
  2168. const int tmp0= tmp[0 *tmpStride];\
  2169. const int tmp1= tmp[1 *tmpStride];\
  2170. const int tmp2= tmp[2 *tmpStride];\
  2171. const int tmp3= tmp[3 *tmpStride];\
  2172. const int tmp4= tmp[4 *tmpStride];\
  2173. const int tmp5= tmp[5 *tmpStride];\
  2174. const int tmp6= tmp[6 *tmpStride];\
  2175. const int tmp7= tmp[7 *tmpStride];\
  2176. const int tmp8= tmp[8 *tmpStride];\
  2177. const int tmp9= tmp[9 *tmpStride];\
  2178. const int tmp10=tmp[10*tmpStride];\
  2179. OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
  2180. OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
  2181. OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
  2182. OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
  2183. OP2(dst[4*dstStride], (tmp4+tmp5)*20 - (tmp3+tmp6)*5 + (tmp2+tmp7));\
  2184. OP2(dst[5*dstStride], (tmp5+tmp6)*20 - (tmp4+tmp7)*5 + (tmp3+tmp8));\
  2185. OP2(dst[6*dstStride], (tmp6+tmp7)*20 - (tmp5+tmp8)*5 + (tmp4+tmp9));\
  2186. OP2(dst[7*dstStride], (tmp7+tmp8)*20 - (tmp6+tmp9)*5 + (tmp5+tmp10));\
  2187. dst++;\
  2188. tmp++;\
  2189. }\
  2190. }\
  2191. \
  2192. static void OPNAME ## h264_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2193. OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
  2194. OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
  2195. src += 8*srcStride;\
  2196. dst += 8*dstStride;\
  2197. OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
  2198. OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
  2199. }\
  2200. \
  2201. static void OPNAME ## h264_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2202. OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
  2203. OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
  2204. src += 8*srcStride;\
  2205. dst += 8*dstStride;\
  2206. OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
  2207. OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
  2208. }\
  2209. \
  2210. static void OPNAME ## h264_qpel16_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  2211. OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
  2212. OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
  2213. src += 8*srcStride;\
  2214. dst += 8*dstStride;\
  2215. OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
  2216. OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
  2217. }\
  2218. #define H264_MC(OPNAME, SIZE) \
  2219. static void OPNAME ## h264_qpel ## SIZE ## _mc00_c (uint8_t *dst, uint8_t *src, int stride){\
  2220. OPNAME ## pixels ## SIZE ## _c(dst, src, stride, SIZE);\
  2221. }\
  2222. \
  2223. static void OPNAME ## h264_qpel ## SIZE ## _mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  2224. uint8_t half[SIZE*SIZE];\
  2225. put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
  2226. OPNAME ## pixels ## SIZE ## _l2(dst, src, half, stride, stride, SIZE, SIZE);\
  2227. }\
  2228. \
  2229. static void OPNAME ## h264_qpel ## SIZE ## _mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  2230. OPNAME ## h264_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride);\
  2231. }\
  2232. \
  2233. static void OPNAME ## h264_qpel ## SIZE ## _mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  2234. uint8_t half[SIZE*SIZE];\
  2235. put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
  2236. OPNAME ## pixels ## SIZE ## _l2(dst, src+1, half, stride, stride, SIZE, SIZE);\
  2237. }\
  2238. \
  2239. static void OPNAME ## h264_qpel ## SIZE ## _mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  2240. uint8_t full[SIZE*(SIZE+5)];\
  2241. uint8_t * const full_mid= full + SIZE*2;\
  2242. uint8_t half[SIZE*SIZE];\
  2243. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2244. put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
  2245. OPNAME ## pixels ## SIZE ## _l2(dst, full_mid, half, stride, SIZE, SIZE, SIZE);\
  2246. }\
  2247. \
  2248. static void OPNAME ## h264_qpel ## SIZE ## _mc02_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. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2252. OPNAME ## h264_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE);\
  2253. }\
  2254. \
  2255. static void OPNAME ## h264_qpel ## SIZE ## _mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  2256. uint8_t full[SIZE*(SIZE+5)];\
  2257. uint8_t * const full_mid= full + SIZE*2;\
  2258. uint8_t half[SIZE*SIZE];\
  2259. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2260. put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
  2261. OPNAME ## pixels ## SIZE ## _l2(dst, full_mid+SIZE, half, stride, SIZE, SIZE, SIZE);\
  2262. }\
  2263. \
  2264. static void OPNAME ## h264_qpel ## SIZE ## _mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  2265. uint8_t full[SIZE*(SIZE+5)];\
  2266. uint8_t * const full_mid= full + SIZE*2;\
  2267. uint8_t halfH[SIZE*SIZE];\
  2268. uint8_t halfV[SIZE*SIZE];\
  2269. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
  2270. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2271. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2272. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2273. }\
  2274. \
  2275. static void OPNAME ## h264_qpel ## SIZE ## _mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  2276. uint8_t full[SIZE*(SIZE+5)];\
  2277. uint8_t * const full_mid= full + SIZE*2;\
  2278. uint8_t halfH[SIZE*SIZE];\
  2279. uint8_t halfV[SIZE*SIZE];\
  2280. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
  2281. copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
  2282. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2283. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2284. }\
  2285. \
  2286. static void OPNAME ## h264_qpel ## SIZE ## _mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  2287. uint8_t full[SIZE*(SIZE+5)];\
  2288. uint8_t * const full_mid= full + SIZE*2;\
  2289. uint8_t halfH[SIZE*SIZE];\
  2290. uint8_t halfV[SIZE*SIZE];\
  2291. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
  2292. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2293. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2294. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2295. }\
  2296. \
  2297. static void OPNAME ## h264_qpel ## SIZE ## _mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  2298. uint8_t full[SIZE*(SIZE+5)];\
  2299. uint8_t * const full_mid= full + SIZE*2;\
  2300. uint8_t halfH[SIZE*SIZE];\
  2301. uint8_t halfV[SIZE*SIZE];\
  2302. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
  2303. copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
  2304. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2305. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2306. }\
  2307. \
  2308. static void OPNAME ## h264_qpel ## SIZE ## _mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  2309. int16_t tmp[SIZE*(SIZE+5)];\
  2310. OPNAME ## h264_qpel ## SIZE ## _hv_lowpass(dst, tmp, src, stride, SIZE, stride);\
  2311. }\
  2312. \
  2313. static void OPNAME ## h264_qpel ## SIZE ## _mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  2314. int16_t tmp[SIZE*(SIZE+5)];\
  2315. uint8_t halfH[SIZE*SIZE];\
  2316. uint8_t halfHV[SIZE*SIZE];\
  2317. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
  2318. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2319. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
  2320. }\
  2321. \
  2322. static void OPNAME ## h264_qpel ## SIZE ## _mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  2323. int16_t tmp[SIZE*(SIZE+5)];\
  2324. uint8_t halfH[SIZE*SIZE];\
  2325. uint8_t halfHV[SIZE*SIZE];\
  2326. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
  2327. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2328. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
  2329. }\
  2330. \
  2331. static void OPNAME ## h264_qpel ## SIZE ## _mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  2332. uint8_t full[SIZE*(SIZE+5)];\
  2333. uint8_t * const full_mid= full + SIZE*2;\
  2334. int16_t tmp[SIZE*(SIZE+5)];\
  2335. uint8_t halfV[SIZE*SIZE];\
  2336. uint8_t halfHV[SIZE*SIZE];\
  2337. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2338. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2339. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2340. OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
  2341. }\
  2342. \
  2343. static void OPNAME ## h264_qpel ## SIZE ## _mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  2344. uint8_t full[SIZE*(SIZE+5)];\
  2345. uint8_t * const full_mid= full + SIZE*2;\
  2346. int16_t tmp[SIZE*(SIZE+5)];\
  2347. uint8_t halfV[SIZE*SIZE];\
  2348. uint8_t halfHV[SIZE*SIZE];\
  2349. copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
  2350. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2351. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2352. OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
  2353. }\
  2354. #define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
  2355. //#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7)
  2356. #define op_put(a, b) a = cm[((b) + 16)>>5]
  2357. #define op2_avg(a, b) a = (((a)+cm[((b) + 512)>>10]+1)>>1)
  2358. #define op2_put(a, b) a = cm[((b) + 512)>>10]
  2359. H264_LOWPASS(put_ , op_put, op2_put)
  2360. H264_LOWPASS(avg_ , op_avg, op2_avg)
  2361. H264_MC(put_, 2)
  2362. H264_MC(put_, 4)
  2363. H264_MC(put_, 8)
  2364. H264_MC(put_, 16)
  2365. H264_MC(avg_, 4)
  2366. H264_MC(avg_, 8)
  2367. H264_MC(avg_, 16)
  2368. #undef op_avg
  2369. #undef op_put
  2370. #undef op2_avg
  2371. #undef op2_put
  2372. #endif
  2373. #define op_scale1(x) block[x] = av_clip_uint8( (block[x]*weight + offset) >> log2_denom )
  2374. #define op_scale2(x) dst[x] = av_clip_uint8( (src[x]*weights + dst[x]*weightd + offset) >> (log2_denom+1))
  2375. #define H264_WEIGHT(W,H) \
  2376. static void weight_h264_pixels ## W ## x ## H ## _c(uint8_t *block, int stride, int log2_denom, int weight, int offset){ \
  2377. int y; \
  2378. offset <<= log2_denom; \
  2379. if(log2_denom) offset += 1<<(log2_denom-1); \
  2380. for(y=0; y<H; y++, block += stride){ \
  2381. op_scale1(0); \
  2382. op_scale1(1); \
  2383. if(W==2) continue; \
  2384. op_scale1(2); \
  2385. op_scale1(3); \
  2386. if(W==4) continue; \
  2387. op_scale1(4); \
  2388. op_scale1(5); \
  2389. op_scale1(6); \
  2390. op_scale1(7); \
  2391. if(W==8) continue; \
  2392. op_scale1(8); \
  2393. op_scale1(9); \
  2394. op_scale1(10); \
  2395. op_scale1(11); \
  2396. op_scale1(12); \
  2397. op_scale1(13); \
  2398. op_scale1(14); \
  2399. op_scale1(15); \
  2400. } \
  2401. } \
  2402. 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){ \
  2403. int y; \
  2404. offset = ((offset + 1) | 1) << log2_denom; \
  2405. for(y=0; y<H; y++, dst += stride, src += stride){ \
  2406. op_scale2(0); \
  2407. op_scale2(1); \
  2408. if(W==2) continue; \
  2409. op_scale2(2); \
  2410. op_scale2(3); \
  2411. if(W==4) continue; \
  2412. op_scale2(4); \
  2413. op_scale2(5); \
  2414. op_scale2(6); \
  2415. op_scale2(7); \
  2416. if(W==8) continue; \
  2417. op_scale2(8); \
  2418. op_scale2(9); \
  2419. op_scale2(10); \
  2420. op_scale2(11); \
  2421. op_scale2(12); \
  2422. op_scale2(13); \
  2423. op_scale2(14); \
  2424. op_scale2(15); \
  2425. } \
  2426. }
  2427. H264_WEIGHT(16,16)
  2428. H264_WEIGHT(16,8)
  2429. H264_WEIGHT(8,16)
  2430. H264_WEIGHT(8,8)
  2431. H264_WEIGHT(8,4)
  2432. H264_WEIGHT(4,8)
  2433. H264_WEIGHT(4,4)
  2434. H264_WEIGHT(4,2)
  2435. H264_WEIGHT(2,4)
  2436. H264_WEIGHT(2,2)
  2437. #undef op_scale1
  2438. #undef op_scale2
  2439. #undef H264_WEIGHT
  2440. static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){
  2441. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  2442. int i;
  2443. for(i=0; i<h; i++){
  2444. dst[0]= cm[(9*(src[0] + src[1]) - (src[-1] + src[2]) + 8)>>4];
  2445. dst[1]= cm[(9*(src[1] + src[2]) - (src[ 0] + src[3]) + 8)>>4];
  2446. dst[2]= cm[(9*(src[2] + src[3]) - (src[ 1] + src[4]) + 8)>>4];
  2447. dst[3]= cm[(9*(src[3] + src[4]) - (src[ 2] + src[5]) + 8)>>4];
  2448. dst[4]= cm[(9*(src[4] + src[5]) - (src[ 3] + src[6]) + 8)>>4];
  2449. dst[5]= cm[(9*(src[5] + src[6]) - (src[ 4] + src[7]) + 8)>>4];
  2450. dst[6]= cm[(9*(src[6] + src[7]) - (src[ 5] + src[8]) + 8)>>4];
  2451. dst[7]= cm[(9*(src[7] + src[8]) - (src[ 6] + src[9]) + 8)>>4];
  2452. dst+=dstStride;
  2453. src+=srcStride;
  2454. }
  2455. }
  2456. #ifdef CONFIG_CAVS_DECODER
  2457. /* AVS specific */
  2458. void ff_cavsdsp_init(DSPContext* c, AVCodecContext *avctx);
  2459. void ff_put_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
  2460. put_pixels8_c(dst, src, stride, 8);
  2461. }
  2462. void ff_avg_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
  2463. avg_pixels8_c(dst, src, stride, 8);
  2464. }
  2465. void ff_put_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
  2466. put_pixels16_c(dst, src, stride, 16);
  2467. }
  2468. void ff_avg_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
  2469. avg_pixels16_c(dst, src, stride, 16);
  2470. }
  2471. #endif /* CONFIG_CAVS_DECODER */
  2472. #if defined(CONFIG_VC1_DECODER) || defined(CONFIG_WMV3_DECODER)
  2473. /* VC-1 specific */
  2474. void ff_vc1dsp_init(DSPContext* c, AVCodecContext *avctx);
  2475. void ff_put_vc1_mspel_mc00_c(uint8_t *dst, uint8_t *src, int stride, int rnd) {
  2476. put_pixels8_c(dst, src, stride, 8);
  2477. }
  2478. #endif /* CONFIG_VC1_DECODER||CONFIG_WMV3_DECODER */
  2479. void ff_intrax8dsp_init(DSPContext* c, AVCodecContext *avctx);
  2480. /* H264 specific */
  2481. void ff_h264dspenc_init(DSPContext* c, AVCodecContext *avctx);
  2482. static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){
  2483. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  2484. int i;
  2485. for(i=0; i<w; i++){
  2486. const int src_1= src[ -srcStride];
  2487. const int src0 = src[0 ];
  2488. const int src1 = src[ srcStride];
  2489. const int src2 = src[2*srcStride];
  2490. const int src3 = src[3*srcStride];
  2491. const int src4 = src[4*srcStride];
  2492. const int src5 = src[5*srcStride];
  2493. const int src6 = src[6*srcStride];
  2494. const int src7 = src[7*srcStride];
  2495. const int src8 = src[8*srcStride];
  2496. const int src9 = src[9*srcStride];
  2497. dst[0*dstStride]= cm[(9*(src0 + src1) - (src_1 + src2) + 8)>>4];
  2498. dst[1*dstStride]= cm[(9*(src1 + src2) - (src0 + src3) + 8)>>4];
  2499. dst[2*dstStride]= cm[(9*(src2 + src3) - (src1 + src4) + 8)>>4];
  2500. dst[3*dstStride]= cm[(9*(src3 + src4) - (src2 + src5) + 8)>>4];
  2501. dst[4*dstStride]= cm[(9*(src4 + src5) - (src3 + src6) + 8)>>4];
  2502. dst[5*dstStride]= cm[(9*(src5 + src6) - (src4 + src7) + 8)>>4];
  2503. dst[6*dstStride]= cm[(9*(src6 + src7) - (src5 + src8) + 8)>>4];
  2504. dst[7*dstStride]= cm[(9*(src7 + src8) - (src6 + src9) + 8)>>4];
  2505. src++;
  2506. dst++;
  2507. }
  2508. }
  2509. static void put_mspel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){
  2510. put_pixels8_c(dst, src, stride, 8);
  2511. }
  2512. static void put_mspel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){
  2513. uint8_t half[64];
  2514. wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
  2515. put_pixels8_l2(dst, src, half, stride, stride, 8, 8);
  2516. }
  2517. static void put_mspel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){
  2518. wmv2_mspel8_h_lowpass(dst, src, stride, stride, 8);
  2519. }
  2520. static void put_mspel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){
  2521. uint8_t half[64];
  2522. wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
  2523. put_pixels8_l2(dst, src+1, half, stride, stride, 8, 8);
  2524. }
  2525. static void put_mspel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){
  2526. wmv2_mspel8_v_lowpass(dst, src, stride, stride, 8);
  2527. }
  2528. static void put_mspel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){
  2529. uint8_t halfH[88];
  2530. uint8_t halfV[64];
  2531. uint8_t halfHV[64];
  2532. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  2533. wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8);
  2534. wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
  2535. put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
  2536. }
  2537. static void put_mspel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){
  2538. uint8_t halfH[88];
  2539. uint8_t halfV[64];
  2540. uint8_t halfHV[64];
  2541. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  2542. wmv2_mspel8_v_lowpass(halfV, src+1, 8, stride, 8);
  2543. wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
  2544. put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
  2545. }
  2546. static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){
  2547. uint8_t halfH[88];
  2548. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  2549. wmv2_mspel8_v_lowpass(dst, halfH+8, stride, 8, 8);
  2550. }
  2551. static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale){
  2552. if(ENABLE_ANY_H263) {
  2553. int x;
  2554. const int strength= ff_h263_loop_filter_strength[qscale];
  2555. for(x=0; x<8; x++){
  2556. int d1, d2, ad1;
  2557. int p0= src[x-2*stride];
  2558. int p1= src[x-1*stride];
  2559. int p2= src[x+0*stride];
  2560. int p3= src[x+1*stride];
  2561. int d = (p0 - p3 + 4*(p2 - p1)) / 8;
  2562. if (d<-2*strength) d1= 0;
  2563. else if(d<- strength) d1=-2*strength - d;
  2564. else if(d< strength) d1= d;
  2565. else if(d< 2*strength) d1= 2*strength - d;
  2566. else d1= 0;
  2567. p1 += d1;
  2568. p2 -= d1;
  2569. if(p1&256) p1= ~(p1>>31);
  2570. if(p2&256) p2= ~(p2>>31);
  2571. src[x-1*stride] = p1;
  2572. src[x+0*stride] = p2;
  2573. ad1= FFABS(d1)>>1;
  2574. d2= av_clip((p0-p3)/4, -ad1, ad1);
  2575. src[x-2*stride] = p0 - d2;
  2576. src[x+ stride] = p3 + d2;
  2577. }
  2578. }
  2579. }
  2580. static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale){
  2581. if(ENABLE_ANY_H263) {
  2582. int y;
  2583. const int strength= ff_h263_loop_filter_strength[qscale];
  2584. for(y=0; y<8; y++){
  2585. int d1, d2, ad1;
  2586. int p0= src[y*stride-2];
  2587. int p1= src[y*stride-1];
  2588. int p2= src[y*stride+0];
  2589. int p3= src[y*stride+1];
  2590. int d = (p0 - p3 + 4*(p2 - p1)) / 8;
  2591. if (d<-2*strength) d1= 0;
  2592. else if(d<- strength) d1=-2*strength - d;
  2593. else if(d< strength) d1= d;
  2594. else if(d< 2*strength) d1= 2*strength - d;
  2595. else d1= 0;
  2596. p1 += d1;
  2597. p2 -= d1;
  2598. if(p1&256) p1= ~(p1>>31);
  2599. if(p2&256) p2= ~(p2>>31);
  2600. src[y*stride-1] = p1;
  2601. src[y*stride+0] = p2;
  2602. ad1= FFABS(d1)>>1;
  2603. d2= av_clip((p0-p3)/4, -ad1, ad1);
  2604. src[y*stride-2] = p0 - d2;
  2605. src[y*stride+1] = p3 + d2;
  2606. }
  2607. }
  2608. }
  2609. static void h261_loop_filter_c(uint8_t *src, int stride){
  2610. int x,y,xy,yz;
  2611. int temp[64];
  2612. for(x=0; x<8; x++){
  2613. temp[x ] = 4*src[x ];
  2614. temp[x + 7*8] = 4*src[x + 7*stride];
  2615. }
  2616. for(y=1; y<7; y++){
  2617. for(x=0; x<8; x++){
  2618. xy = y * stride + x;
  2619. yz = y * 8 + x;
  2620. temp[yz] = src[xy - stride] + 2*src[xy] + src[xy + stride];
  2621. }
  2622. }
  2623. for(y=0; y<8; y++){
  2624. src[ y*stride] = (temp[ y*8] + 2)>>2;
  2625. src[7+y*stride] = (temp[7+y*8] + 2)>>2;
  2626. for(x=1; x<7; x++){
  2627. xy = y * stride + x;
  2628. yz = y * 8 + x;
  2629. src[xy] = (temp[yz-1] + 2*temp[yz] + temp[yz+1] + 8)>>4;
  2630. }
  2631. }
  2632. }
  2633. static inline void h264_loop_filter_luma_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta, int8_t *tc0)
  2634. {
  2635. int i, d;
  2636. for( i = 0; i < 4; i++ ) {
  2637. if( tc0[i] < 0 ) {
  2638. pix += 4*ystride;
  2639. continue;
  2640. }
  2641. for( d = 0; d < 4; d++ ) {
  2642. const int p0 = pix[-1*xstride];
  2643. const int p1 = pix[-2*xstride];
  2644. const int p2 = pix[-3*xstride];
  2645. const int q0 = pix[0];
  2646. const int q1 = pix[1*xstride];
  2647. const int q2 = pix[2*xstride];
  2648. if( FFABS( p0 - q0 ) < alpha &&
  2649. FFABS( p1 - p0 ) < beta &&
  2650. FFABS( q1 - q0 ) < beta ) {
  2651. int tc = tc0[i];
  2652. int i_delta;
  2653. if( FFABS( p2 - p0 ) < beta ) {
  2654. pix[-2*xstride] = p1 + av_clip( (( p2 + ( ( p0 + q0 + 1 ) >> 1 ) ) >> 1) - p1, -tc0[i], tc0[i] );
  2655. tc++;
  2656. }
  2657. if( FFABS( q2 - q0 ) < beta ) {
  2658. pix[ xstride] = q1 + av_clip( (( q2 + ( ( p0 + q0 + 1 ) >> 1 ) ) >> 1) - q1, -tc0[i], tc0[i] );
  2659. tc++;
  2660. }
  2661. i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
  2662. pix[-xstride] = av_clip_uint8( p0 + i_delta ); /* p0' */
  2663. pix[0] = av_clip_uint8( q0 - i_delta ); /* q0' */
  2664. }
  2665. pix += ystride;
  2666. }
  2667. }
  2668. }
  2669. static void h264_v_loop_filter_luma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
  2670. {
  2671. h264_loop_filter_luma_c(pix, stride, 1, alpha, beta, tc0);
  2672. }
  2673. static void h264_h_loop_filter_luma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
  2674. {
  2675. h264_loop_filter_luma_c(pix, 1, stride, alpha, beta, tc0);
  2676. }
  2677. static inline void h264_loop_filter_chroma_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta, int8_t *tc0)
  2678. {
  2679. int i, d;
  2680. for( i = 0; i < 4; i++ ) {
  2681. const int tc = tc0[i];
  2682. if( tc <= 0 ) {
  2683. pix += 2*ystride;
  2684. continue;
  2685. }
  2686. for( d = 0; d < 2; d++ ) {
  2687. const int p0 = pix[-1*xstride];
  2688. const int p1 = pix[-2*xstride];
  2689. const int q0 = pix[0];
  2690. const int q1 = pix[1*xstride];
  2691. if( FFABS( p0 - q0 ) < alpha &&
  2692. FFABS( p1 - p0 ) < beta &&
  2693. FFABS( q1 - q0 ) < beta ) {
  2694. int delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
  2695. pix[-xstride] = av_clip_uint8( p0 + delta ); /* p0' */
  2696. pix[0] = av_clip_uint8( q0 - delta ); /* q0' */
  2697. }
  2698. pix += ystride;
  2699. }
  2700. }
  2701. }
  2702. static void h264_v_loop_filter_chroma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
  2703. {
  2704. h264_loop_filter_chroma_c(pix, stride, 1, alpha, beta, tc0);
  2705. }
  2706. static void h264_h_loop_filter_chroma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
  2707. {
  2708. h264_loop_filter_chroma_c(pix, 1, stride, alpha, beta, tc0);
  2709. }
  2710. static inline void h264_loop_filter_chroma_intra_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta)
  2711. {
  2712. int d;
  2713. for( d = 0; d < 8; d++ ) {
  2714. const int p0 = pix[-1*xstride];
  2715. const int p1 = pix[-2*xstride];
  2716. const int q0 = pix[0];
  2717. const int q1 = pix[1*xstride];
  2718. if( FFABS( p0 - q0 ) < alpha &&
  2719. FFABS( p1 - p0 ) < beta &&
  2720. FFABS( q1 - q0 ) < beta ) {
  2721. pix[-xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */
  2722. pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */
  2723. }
  2724. pix += ystride;
  2725. }
  2726. }
  2727. static void h264_v_loop_filter_chroma_intra_c(uint8_t *pix, int stride, int alpha, int beta)
  2728. {
  2729. h264_loop_filter_chroma_intra_c(pix, stride, 1, alpha, beta);
  2730. }
  2731. static void h264_h_loop_filter_chroma_intra_c(uint8_t *pix, int stride, int alpha, int beta)
  2732. {
  2733. h264_loop_filter_chroma_intra_c(pix, 1, stride, alpha, beta);
  2734. }
  2735. static inline int pix_abs16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2736. {
  2737. int s, i;
  2738. s = 0;
  2739. for(i=0;i<h;i++) {
  2740. s += abs(pix1[0] - pix2[0]);
  2741. s += abs(pix1[1] - pix2[1]);
  2742. s += abs(pix1[2] - pix2[2]);
  2743. s += abs(pix1[3] - pix2[3]);
  2744. s += abs(pix1[4] - pix2[4]);
  2745. s += abs(pix1[5] - pix2[5]);
  2746. s += abs(pix1[6] - pix2[6]);
  2747. s += abs(pix1[7] - pix2[7]);
  2748. s += abs(pix1[8] - pix2[8]);
  2749. s += abs(pix1[9] - pix2[9]);
  2750. s += abs(pix1[10] - pix2[10]);
  2751. s += abs(pix1[11] - pix2[11]);
  2752. s += abs(pix1[12] - pix2[12]);
  2753. s += abs(pix1[13] - pix2[13]);
  2754. s += abs(pix1[14] - pix2[14]);
  2755. s += abs(pix1[15] - pix2[15]);
  2756. pix1 += line_size;
  2757. pix2 += line_size;
  2758. }
  2759. return s;
  2760. }
  2761. static int pix_abs16_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2762. {
  2763. int s, i;
  2764. s = 0;
  2765. for(i=0;i<h;i++) {
  2766. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  2767. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  2768. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  2769. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  2770. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  2771. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  2772. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  2773. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  2774. s += abs(pix1[8] - avg2(pix2[8], pix2[9]));
  2775. s += abs(pix1[9] - avg2(pix2[9], pix2[10]));
  2776. s += abs(pix1[10] - avg2(pix2[10], pix2[11]));
  2777. s += abs(pix1[11] - avg2(pix2[11], pix2[12]));
  2778. s += abs(pix1[12] - avg2(pix2[12], pix2[13]));
  2779. s += abs(pix1[13] - avg2(pix2[13], pix2[14]));
  2780. s += abs(pix1[14] - avg2(pix2[14], pix2[15]));
  2781. s += abs(pix1[15] - avg2(pix2[15], pix2[16]));
  2782. pix1 += line_size;
  2783. pix2 += line_size;
  2784. }
  2785. return s;
  2786. }
  2787. static int pix_abs16_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2788. {
  2789. int s, i;
  2790. uint8_t *pix3 = pix2 + line_size;
  2791. s = 0;
  2792. for(i=0;i<h;i++) {
  2793. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  2794. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  2795. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  2796. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  2797. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  2798. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  2799. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  2800. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  2801. s += abs(pix1[8] - avg2(pix2[8], pix3[8]));
  2802. s += abs(pix1[9] - avg2(pix2[9], pix3[9]));
  2803. s += abs(pix1[10] - avg2(pix2[10], pix3[10]));
  2804. s += abs(pix1[11] - avg2(pix2[11], pix3[11]));
  2805. s += abs(pix1[12] - avg2(pix2[12], pix3[12]));
  2806. s += abs(pix1[13] - avg2(pix2[13], pix3[13]));
  2807. s += abs(pix1[14] - avg2(pix2[14], pix3[14]));
  2808. s += abs(pix1[15] - avg2(pix2[15], pix3[15]));
  2809. pix1 += line_size;
  2810. pix2 += line_size;
  2811. pix3 += line_size;
  2812. }
  2813. return s;
  2814. }
  2815. static int pix_abs16_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2816. {
  2817. int s, i;
  2818. uint8_t *pix3 = pix2 + line_size;
  2819. s = 0;
  2820. for(i=0;i<h;i++) {
  2821. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  2822. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  2823. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  2824. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  2825. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  2826. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  2827. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  2828. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  2829. s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9]));
  2830. s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10]));
  2831. s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11]));
  2832. s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12]));
  2833. s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13]));
  2834. s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14]));
  2835. s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15]));
  2836. s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16]));
  2837. pix1 += line_size;
  2838. pix2 += line_size;
  2839. pix3 += line_size;
  2840. }
  2841. return s;
  2842. }
  2843. static inline int pix_abs8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2844. {
  2845. int s, i;
  2846. s = 0;
  2847. for(i=0;i<h;i++) {
  2848. s += abs(pix1[0] - pix2[0]);
  2849. s += abs(pix1[1] - pix2[1]);
  2850. s += abs(pix1[2] - pix2[2]);
  2851. s += abs(pix1[3] - pix2[3]);
  2852. s += abs(pix1[4] - pix2[4]);
  2853. s += abs(pix1[5] - pix2[5]);
  2854. s += abs(pix1[6] - pix2[6]);
  2855. s += abs(pix1[7] - pix2[7]);
  2856. pix1 += line_size;
  2857. pix2 += line_size;
  2858. }
  2859. return s;
  2860. }
  2861. static int pix_abs8_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2862. {
  2863. int s, i;
  2864. s = 0;
  2865. for(i=0;i<h;i++) {
  2866. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  2867. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  2868. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  2869. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  2870. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  2871. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  2872. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  2873. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  2874. pix1 += line_size;
  2875. pix2 += line_size;
  2876. }
  2877. return s;
  2878. }
  2879. static int pix_abs8_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2880. {
  2881. int s, i;
  2882. uint8_t *pix3 = pix2 + line_size;
  2883. s = 0;
  2884. for(i=0;i<h;i++) {
  2885. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  2886. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  2887. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  2888. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  2889. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  2890. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  2891. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  2892. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  2893. pix1 += line_size;
  2894. pix2 += line_size;
  2895. pix3 += line_size;
  2896. }
  2897. return s;
  2898. }
  2899. static int pix_abs8_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2900. {
  2901. int s, i;
  2902. uint8_t *pix3 = pix2 + line_size;
  2903. s = 0;
  2904. for(i=0;i<h;i++) {
  2905. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  2906. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  2907. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  2908. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  2909. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  2910. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  2911. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  2912. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  2913. pix1 += line_size;
  2914. pix2 += line_size;
  2915. pix3 += line_size;
  2916. }
  2917. return s;
  2918. }
  2919. static int nsse16_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
  2920. MpegEncContext *c = v;
  2921. int score1=0;
  2922. int score2=0;
  2923. int x,y;
  2924. for(y=0; y<h; y++){
  2925. for(x=0; x<16; x++){
  2926. score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
  2927. }
  2928. if(y+1<h){
  2929. for(x=0; x<15; x++){
  2930. score2+= FFABS( s1[x ] - s1[x +stride]
  2931. - s1[x+1] + s1[x+1+stride])
  2932. -FFABS( s2[x ] - s2[x +stride]
  2933. - s2[x+1] + s2[x+1+stride]);
  2934. }
  2935. }
  2936. s1+= stride;
  2937. s2+= stride;
  2938. }
  2939. if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
  2940. else return score1 + FFABS(score2)*8;
  2941. }
  2942. static int nsse8_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
  2943. MpegEncContext *c = v;
  2944. int score1=0;
  2945. int score2=0;
  2946. int x,y;
  2947. for(y=0; y<h; y++){
  2948. for(x=0; x<8; x++){
  2949. score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
  2950. }
  2951. if(y+1<h){
  2952. for(x=0; x<7; x++){
  2953. score2+= FFABS( s1[x ] - s1[x +stride]
  2954. - s1[x+1] + s1[x+1+stride])
  2955. -FFABS( s2[x ] - s2[x +stride]
  2956. - s2[x+1] + s2[x+1+stride]);
  2957. }
  2958. }
  2959. s1+= stride;
  2960. s2+= stride;
  2961. }
  2962. if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
  2963. else return score1 + FFABS(score2)*8;
  2964. }
  2965. static int try_8x8basis_c(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){
  2966. int i;
  2967. unsigned int sum=0;
  2968. for(i=0; i<8*8; i++){
  2969. int b= rem[i] + ((basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT));
  2970. int w= weight[i];
  2971. b>>= RECON_SHIFT;
  2972. assert(-512<b && b<512);
  2973. sum += (w*b)*(w*b)>>4;
  2974. }
  2975. return sum>>2;
  2976. }
  2977. static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale){
  2978. int i;
  2979. for(i=0; i<8*8; i++){
  2980. rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT);
  2981. }
  2982. }
  2983. /**
  2984. * permutes an 8x8 block.
  2985. * @param block the block which will be permuted according to the given permutation vector
  2986. * @param permutation the permutation vector
  2987. * @param last the last non zero coefficient in scantable order, used to speed the permutation up
  2988. * @param scantable the used scantable, this is only used to speed the permutation up, the block is not
  2989. * (inverse) permutated to scantable order!
  2990. */
  2991. void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last)
  2992. {
  2993. int i;
  2994. DCTELEM temp[64];
  2995. if(last<=0) return;
  2996. //if(permutation[1]==1) return; //FIXME it is ok but not clean and might fail for some permutations
  2997. for(i=0; i<=last; i++){
  2998. const int j= scantable[i];
  2999. temp[j]= block[j];
  3000. block[j]=0;
  3001. }
  3002. for(i=0; i<=last; i++){
  3003. const int j= scantable[i];
  3004. const int perm_j= permutation[j];
  3005. block[perm_j]= temp[j];
  3006. }
  3007. }
  3008. static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){
  3009. return 0;
  3010. }
  3011. void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){
  3012. int i;
  3013. memset(cmp, 0, sizeof(void*)*5);
  3014. for(i=0; i<5; i++){
  3015. switch(type&0xFF){
  3016. case FF_CMP_SAD:
  3017. cmp[i]= c->sad[i];
  3018. break;
  3019. case FF_CMP_SATD:
  3020. cmp[i]= c->hadamard8_diff[i];
  3021. break;
  3022. case FF_CMP_SSE:
  3023. cmp[i]= c->sse[i];
  3024. break;
  3025. case FF_CMP_DCT:
  3026. cmp[i]= c->dct_sad[i];
  3027. break;
  3028. case FF_CMP_DCT264:
  3029. cmp[i]= c->dct264_sad[i];
  3030. break;
  3031. case FF_CMP_DCTMAX:
  3032. cmp[i]= c->dct_max[i];
  3033. break;
  3034. case FF_CMP_PSNR:
  3035. cmp[i]= c->quant_psnr[i];
  3036. break;
  3037. case FF_CMP_BIT:
  3038. cmp[i]= c->bit[i];
  3039. break;
  3040. case FF_CMP_RD:
  3041. cmp[i]= c->rd[i];
  3042. break;
  3043. case FF_CMP_VSAD:
  3044. cmp[i]= c->vsad[i];
  3045. break;
  3046. case FF_CMP_VSSE:
  3047. cmp[i]= c->vsse[i];
  3048. break;
  3049. case FF_CMP_ZERO:
  3050. cmp[i]= zero_cmp;
  3051. break;
  3052. case FF_CMP_NSSE:
  3053. cmp[i]= c->nsse[i];
  3054. break;
  3055. #ifdef CONFIG_SNOW_ENCODER
  3056. case FF_CMP_W53:
  3057. cmp[i]= c->w53[i];
  3058. break;
  3059. case FF_CMP_W97:
  3060. cmp[i]= c->w97[i];
  3061. break;
  3062. #endif
  3063. default:
  3064. av_log(NULL, AV_LOG_ERROR,"internal error in cmp function selection\n");
  3065. }
  3066. }
  3067. }
  3068. /**
  3069. * memset(blocks, 0, sizeof(DCTELEM)*6*64)
  3070. */
  3071. static void clear_blocks_c(DCTELEM *blocks)
  3072. {
  3073. memset(blocks, 0, sizeof(DCTELEM)*6*64);
  3074. }
  3075. static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){
  3076. int i;
  3077. for(i=0; i+7<w; i+=8){
  3078. dst[i+0] += src[i+0];
  3079. dst[i+1] += src[i+1];
  3080. dst[i+2] += src[i+2];
  3081. dst[i+3] += src[i+3];
  3082. dst[i+4] += src[i+4];
  3083. dst[i+5] += src[i+5];
  3084. dst[i+6] += src[i+6];
  3085. dst[i+7] += src[i+7];
  3086. }
  3087. for(; i<w; i++)
  3088. dst[i+0] += src[i+0];
  3089. }
  3090. static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
  3091. int i;
  3092. for(i=0; i+7<w; i+=8){
  3093. dst[i+0] = src1[i+0]-src2[i+0];
  3094. dst[i+1] = src1[i+1]-src2[i+1];
  3095. dst[i+2] = src1[i+2]-src2[i+2];
  3096. dst[i+3] = src1[i+3]-src2[i+3];
  3097. dst[i+4] = src1[i+4]-src2[i+4];
  3098. dst[i+5] = src1[i+5]-src2[i+5];
  3099. dst[i+6] = src1[i+6]-src2[i+6];
  3100. dst[i+7] = src1[i+7]-src2[i+7];
  3101. }
  3102. for(; i<w; i++)
  3103. dst[i+0] = src1[i+0]-src2[i+0];
  3104. }
  3105. static void sub_hfyu_median_prediction_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top){
  3106. int i;
  3107. uint8_t l, lt;
  3108. l= *left;
  3109. lt= *left_top;
  3110. for(i=0; i<w; i++){
  3111. const int pred= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF);
  3112. lt= src1[i];
  3113. l= src2[i];
  3114. dst[i]= l - pred;
  3115. }
  3116. *left= l;
  3117. *left_top= lt;
  3118. }
  3119. #define BUTTERFLY2(o1,o2,i1,i2) \
  3120. o1= (i1)+(i2);\
  3121. o2= (i1)-(i2);
  3122. #define BUTTERFLY1(x,y) \
  3123. {\
  3124. int a,b;\
  3125. a= x;\
  3126. b= y;\
  3127. x= a+b;\
  3128. y= a-b;\
  3129. }
  3130. #define BUTTERFLYA(x,y) (FFABS((x)+(y)) + FFABS((x)-(y)))
  3131. static int hadamard8_diff8x8_c(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){
  3132. int i;
  3133. int temp[64];
  3134. int sum=0;
  3135. assert(h==8);
  3136. for(i=0; i<8; i++){
  3137. //FIXME try pointer walks
  3138. 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]);
  3139. 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]);
  3140. 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]);
  3141. 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]);
  3142. BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
  3143. BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
  3144. BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
  3145. BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
  3146. BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
  3147. BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
  3148. BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
  3149. BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
  3150. }
  3151. for(i=0; i<8; i++){
  3152. BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
  3153. BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
  3154. BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
  3155. BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
  3156. BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
  3157. BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
  3158. BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
  3159. BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
  3160. sum +=
  3161. BUTTERFLYA(temp[8*0+i], temp[8*4+i])
  3162. +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
  3163. +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
  3164. +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
  3165. }
  3166. #if 0
  3167. static int maxi=0;
  3168. if(sum>maxi){
  3169. maxi=sum;
  3170. printf("MAX:%d\n", maxi);
  3171. }
  3172. #endif
  3173. return sum;
  3174. }
  3175. static int hadamard8_intra8x8_c(/*MpegEncContext*/ void *s, uint8_t *src, uint8_t *dummy, int stride, int h){
  3176. int i;
  3177. int temp[64];
  3178. int sum=0;
  3179. assert(h==8);
  3180. for(i=0; i<8; i++){
  3181. //FIXME try pointer walks
  3182. BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0],src[stride*i+1]);
  3183. BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2],src[stride*i+3]);
  3184. BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4],src[stride*i+5]);
  3185. BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6],src[stride*i+7]);
  3186. BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
  3187. BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
  3188. BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
  3189. BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
  3190. BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
  3191. BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
  3192. BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
  3193. BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
  3194. }
  3195. for(i=0; i<8; i++){
  3196. BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
  3197. BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
  3198. BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
  3199. BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
  3200. BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
  3201. BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
  3202. BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
  3203. BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
  3204. sum +=
  3205. BUTTERFLYA(temp[8*0+i], temp[8*4+i])
  3206. +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
  3207. +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
  3208. +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
  3209. }
  3210. sum -= FFABS(temp[8*0] + temp[8*4]); // -mean
  3211. return sum;
  3212. }
  3213. static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3214. MpegEncContext * const s= (MpegEncContext *)c;
  3215. DECLARE_ALIGNED_16(uint64_t, aligned_temp[sizeof(DCTELEM)*64/8]);
  3216. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  3217. assert(h==8);
  3218. s->dsp.diff_pixels(temp, src1, src2, stride);
  3219. s->dsp.fdct(temp);
  3220. return s->dsp.sum_abs_dctelem(temp);
  3221. }
  3222. #ifdef CONFIG_GPL
  3223. #define DCT8_1D {\
  3224. const int s07 = SRC(0) + SRC(7);\
  3225. const int s16 = SRC(1) + SRC(6);\
  3226. const int s25 = SRC(2) + SRC(5);\
  3227. const int s34 = SRC(3) + SRC(4);\
  3228. const int a0 = s07 + s34;\
  3229. const int a1 = s16 + s25;\
  3230. const int a2 = s07 - s34;\
  3231. const int a3 = s16 - s25;\
  3232. const int d07 = SRC(0) - SRC(7);\
  3233. const int d16 = SRC(1) - SRC(6);\
  3234. const int d25 = SRC(2) - SRC(5);\
  3235. const int d34 = SRC(3) - SRC(4);\
  3236. const int a4 = d16 + d25 + (d07 + (d07>>1));\
  3237. const int a5 = d07 - d34 - (d25 + (d25>>1));\
  3238. const int a6 = d07 + d34 - (d16 + (d16>>1));\
  3239. const int a7 = d16 - d25 + (d34 + (d34>>1));\
  3240. DST(0, a0 + a1 ) ;\
  3241. DST(1, a4 + (a7>>2)) ;\
  3242. DST(2, a2 + (a3>>1)) ;\
  3243. DST(3, a5 + (a6>>2)) ;\
  3244. DST(4, a0 - a1 ) ;\
  3245. DST(5, a6 - (a5>>2)) ;\
  3246. DST(6, (a2>>1) - a3 ) ;\
  3247. DST(7, (a4>>2) - a7 ) ;\
  3248. }
  3249. static int dct264_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3250. MpegEncContext * const s= (MpegEncContext *)c;
  3251. DCTELEM dct[8][8];
  3252. int i;
  3253. int sum=0;
  3254. s->dsp.diff_pixels(dct[0], src1, src2, stride);
  3255. #define SRC(x) dct[i][x]
  3256. #define DST(x,v) dct[i][x]= v
  3257. for( i = 0; i < 8; i++ )
  3258. DCT8_1D
  3259. #undef SRC
  3260. #undef DST
  3261. #define SRC(x) dct[x][i]
  3262. #define DST(x,v) sum += FFABS(v)
  3263. for( i = 0; i < 8; i++ )
  3264. DCT8_1D
  3265. #undef SRC
  3266. #undef DST
  3267. return sum;
  3268. }
  3269. #endif
  3270. static int dct_max8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3271. MpegEncContext * const s= (MpegEncContext *)c;
  3272. DECLARE_ALIGNED_8(uint64_t, aligned_temp[sizeof(DCTELEM)*64/8]);
  3273. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  3274. int sum=0, i;
  3275. assert(h==8);
  3276. s->dsp.diff_pixels(temp, src1, src2, stride);
  3277. s->dsp.fdct(temp);
  3278. for(i=0; i<64; i++)
  3279. sum= FFMAX(sum, FFABS(temp[i]));
  3280. return sum;
  3281. }
  3282. static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3283. MpegEncContext * const s= (MpegEncContext *)c;
  3284. DECLARE_ALIGNED_8 (uint64_t, aligned_temp[sizeof(DCTELEM)*64*2/8]);
  3285. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  3286. DCTELEM * const bak = ((DCTELEM*)aligned_temp)+64;
  3287. int sum=0, i;
  3288. assert(h==8);
  3289. s->mb_intra=0;
  3290. s->dsp.diff_pixels(temp, src1, src2, stride);
  3291. memcpy(bak, temp, 64*sizeof(DCTELEM));
  3292. s->block_last_index[0/*FIXME*/]= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  3293. s->dct_unquantize_inter(s, temp, 0, s->qscale);
  3294. ff_simple_idct(temp); //FIXME
  3295. for(i=0; i<64; i++)
  3296. sum+= (temp[i]-bak[i])*(temp[i]-bak[i]);
  3297. return sum;
  3298. }
  3299. static int rd8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3300. MpegEncContext * const s= (MpegEncContext *)c;
  3301. const uint8_t *scantable= s->intra_scantable.permutated;
  3302. DECLARE_ALIGNED_8 (uint64_t, aligned_temp[sizeof(DCTELEM)*64/8]);
  3303. DECLARE_ALIGNED_8 (uint64_t, aligned_bak[stride]);
  3304. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  3305. uint8_t * const bak= (uint8_t*)aligned_bak;
  3306. int i, last, run, bits, level, distoration, start_i;
  3307. const int esc_length= s->ac_esc_length;
  3308. uint8_t * length;
  3309. uint8_t * last_length;
  3310. assert(h==8);
  3311. for(i=0; i<8; i++){
  3312. ((uint32_t*)(bak + i*stride))[0]= ((uint32_t*)(src2 + i*stride))[0];
  3313. ((uint32_t*)(bak + i*stride))[1]= ((uint32_t*)(src2 + i*stride))[1];
  3314. }
  3315. s->dsp.diff_pixels(temp, src1, src2, stride);
  3316. s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  3317. bits=0;
  3318. if (s->mb_intra) {
  3319. start_i = 1;
  3320. length = s->intra_ac_vlc_length;
  3321. last_length= s->intra_ac_vlc_last_length;
  3322. bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
  3323. } else {
  3324. start_i = 0;
  3325. length = s->inter_ac_vlc_length;
  3326. last_length= s->inter_ac_vlc_last_length;
  3327. }
  3328. if(last>=start_i){
  3329. run=0;
  3330. for(i=start_i; i<last; i++){
  3331. int j= scantable[i];
  3332. level= temp[j];
  3333. if(level){
  3334. level+=64;
  3335. if((level&(~127)) == 0){
  3336. bits+= length[UNI_AC_ENC_INDEX(run, level)];
  3337. }else
  3338. bits+= esc_length;
  3339. run=0;
  3340. }else
  3341. run++;
  3342. }
  3343. i= scantable[last];
  3344. level= temp[i] + 64;
  3345. assert(level - 64);
  3346. if((level&(~127)) == 0){
  3347. bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
  3348. }else
  3349. bits+= esc_length;
  3350. }
  3351. if(last>=0){
  3352. if(s->mb_intra)
  3353. s->dct_unquantize_intra(s, temp, 0, s->qscale);
  3354. else
  3355. s->dct_unquantize_inter(s, temp, 0, s->qscale);
  3356. }
  3357. s->dsp.idct_add(bak, stride, temp);
  3358. distoration= s->dsp.sse[1](NULL, bak, src1, stride, 8);
  3359. return distoration + ((bits*s->qscale*s->qscale*109 + 64)>>7);
  3360. }
  3361. static int bit8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3362. MpegEncContext * const s= (MpegEncContext *)c;
  3363. const uint8_t *scantable= s->intra_scantable.permutated;
  3364. DECLARE_ALIGNED_8 (uint64_t, aligned_temp[sizeof(DCTELEM)*64/8]);
  3365. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  3366. int i, last, run, bits, level, start_i;
  3367. const int esc_length= s->ac_esc_length;
  3368. uint8_t * length;
  3369. uint8_t * last_length;
  3370. assert(h==8);
  3371. s->dsp.diff_pixels(temp, src1, src2, stride);
  3372. s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  3373. bits=0;
  3374. if (s->mb_intra) {
  3375. start_i = 1;
  3376. length = s->intra_ac_vlc_length;
  3377. last_length= s->intra_ac_vlc_last_length;
  3378. bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
  3379. } else {
  3380. start_i = 0;
  3381. length = s->inter_ac_vlc_length;
  3382. last_length= s->inter_ac_vlc_last_length;
  3383. }
  3384. if(last>=start_i){
  3385. run=0;
  3386. for(i=start_i; i<last; i++){
  3387. int j= scantable[i];
  3388. level= temp[j];
  3389. if(level){
  3390. level+=64;
  3391. if((level&(~127)) == 0){
  3392. bits+= length[UNI_AC_ENC_INDEX(run, level)];
  3393. }else
  3394. bits+= esc_length;
  3395. run=0;
  3396. }else
  3397. run++;
  3398. }
  3399. i= scantable[last];
  3400. level= temp[i] + 64;
  3401. assert(level - 64);
  3402. if((level&(~127)) == 0){
  3403. bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
  3404. }else
  3405. bits+= esc_length;
  3406. }
  3407. return bits;
  3408. }
  3409. static int vsad_intra16_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, 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+=4){
  3414. score+= FFABS(s[x ] - s[x +stride]) + FFABS(s[x+1] - s[x+1+stride])
  3415. +FFABS(s[x+2] - s[x+2+stride]) + FFABS(s[x+3] - s[x+3+stride]);
  3416. }
  3417. s+= stride;
  3418. }
  3419. return score;
  3420. }
  3421. static int vsad16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
  3422. int score=0;
  3423. int x,y;
  3424. for(y=1; y<h; y++){
  3425. for(x=0; x<16; x++){
  3426. score+= FFABS(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
  3427. }
  3428. s1+= stride;
  3429. s2+= stride;
  3430. }
  3431. return score;
  3432. }
  3433. #define SQ(a) ((a)*(a))
  3434. static int vsse_intra16_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){
  3435. int score=0;
  3436. int x,y;
  3437. for(y=1; y<h; y++){
  3438. for(x=0; x<16; x+=4){
  3439. score+= SQ(s[x ] - s[x +stride]) + SQ(s[x+1] - s[x+1+stride])
  3440. +SQ(s[x+2] - s[x+2+stride]) + SQ(s[x+3] - s[x+3+stride]);
  3441. }
  3442. s+= stride;
  3443. }
  3444. return score;
  3445. }
  3446. static int vsse16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
  3447. int score=0;
  3448. int x,y;
  3449. for(y=1; y<h; y++){
  3450. for(x=0; x<16; x++){
  3451. score+= SQ(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
  3452. }
  3453. s1+= stride;
  3454. s2+= stride;
  3455. }
  3456. return score;
  3457. }
  3458. static int ssd_int8_vs_int16_c(const int8_t *pix1, const int16_t *pix2,
  3459. int size){
  3460. int score=0;
  3461. int i;
  3462. for(i=0; i<size; i++)
  3463. score += (pix1[i]-pix2[i])*(pix1[i]-pix2[i]);
  3464. return score;
  3465. }
  3466. WRAPPER8_16_SQ(hadamard8_diff8x8_c, hadamard8_diff16_c)
  3467. WRAPPER8_16_SQ(hadamard8_intra8x8_c, hadamard8_intra16_c)
  3468. WRAPPER8_16_SQ(dct_sad8x8_c, dct_sad16_c)
  3469. #ifdef CONFIG_GPL
  3470. WRAPPER8_16_SQ(dct264_sad8x8_c, dct264_sad16_c)
  3471. #endif
  3472. WRAPPER8_16_SQ(dct_max8x8_c, dct_max16_c)
  3473. WRAPPER8_16_SQ(quant_psnr8x8_c, quant_psnr16_c)
  3474. WRAPPER8_16_SQ(rd8x8_c, rd16_c)
  3475. WRAPPER8_16_SQ(bit8x8_c, bit16_c)
  3476. static void vector_fmul_c(float *dst, const float *src, int len){
  3477. int i;
  3478. for(i=0; i<len; i++)
  3479. dst[i] *= src[i];
  3480. }
  3481. static void vector_fmul_reverse_c(float *dst, const float *src0, const float *src1, int len){
  3482. int i;
  3483. src1 += len-1;
  3484. for(i=0; i<len; i++)
  3485. dst[i] = src0[i] * src1[-i];
  3486. }
  3487. void ff_vector_fmul_add_add_c(float *dst, const float *src0, const float *src1, const float *src2, int src3, int len, int step){
  3488. int i;
  3489. for(i=0; i<len; i++)
  3490. dst[i*step] = src0[i] * src1[i] + src2[i] + src3;
  3491. }
  3492. void ff_float_to_int16_c(int16_t *dst, const float *src, int len){
  3493. int i;
  3494. for(i=0; i<len; i++) {
  3495. int_fast32_t tmp = ((int32_t*)src)[i];
  3496. if(tmp & 0xf0000){
  3497. tmp = (0x43c0ffff - tmp)>>31;
  3498. // is this faster on some gcc/cpu combinations?
  3499. // if(tmp > 0x43c0ffff) tmp = 0xFFFF;
  3500. // else tmp = 0;
  3501. }
  3502. dst[i] = tmp - 0x8000;
  3503. }
  3504. }
  3505. #define W0 2048
  3506. #define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */
  3507. #define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */
  3508. #define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */
  3509. #define W4 2048 /* 2048*sqrt (2)*cos (4*pi/16) */
  3510. #define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */
  3511. #define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */
  3512. #define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */
  3513. static void wmv2_idct_row(short * b)
  3514. {
  3515. int s1,s2;
  3516. int a0,a1,a2,a3,a4,a5,a6,a7;
  3517. /*step 1*/
  3518. a1 = W1*b[1]+W7*b[7];
  3519. a7 = W7*b[1]-W1*b[7];
  3520. a5 = W5*b[5]+W3*b[3];
  3521. a3 = W3*b[5]-W5*b[3];
  3522. a2 = W2*b[2]+W6*b[6];
  3523. a6 = W6*b[2]-W2*b[6];
  3524. a0 = W0*b[0]+W0*b[4];
  3525. a4 = W0*b[0]-W0*b[4];
  3526. /*step 2*/
  3527. s1 = (181*(a1-a5+a7-a3)+128)>>8;//1,3,5,7,
  3528. s2 = (181*(a1-a5-a7+a3)+128)>>8;
  3529. /*step 3*/
  3530. b[0] = (a0+a2+a1+a5 + (1<<7))>>8;
  3531. b[1] = (a4+a6 +s1 + (1<<7))>>8;
  3532. b[2] = (a4-a6 +s2 + (1<<7))>>8;
  3533. b[3] = (a0-a2+a7+a3 + (1<<7))>>8;
  3534. b[4] = (a0-a2-a7-a3 + (1<<7))>>8;
  3535. b[5] = (a4-a6 -s2 + (1<<7))>>8;
  3536. b[6] = (a4+a6 -s1 + (1<<7))>>8;
  3537. b[7] = (a0+a2-a1-a5 + (1<<7))>>8;
  3538. }
  3539. static void wmv2_idct_col(short * b)
  3540. {
  3541. int s1,s2;
  3542. int a0,a1,a2,a3,a4,a5,a6,a7;
  3543. /*step 1, with extended precision*/
  3544. a1 = (W1*b[8*1]+W7*b[8*7] + 4)>>3;
  3545. a7 = (W7*b[8*1]-W1*b[8*7] + 4)>>3;
  3546. a5 = (W5*b[8*5]+W3*b[8*3] + 4)>>3;
  3547. a3 = (W3*b[8*5]-W5*b[8*3] + 4)>>3;
  3548. a2 = (W2*b[8*2]+W6*b[8*6] + 4)>>3;
  3549. a6 = (W6*b[8*2]-W2*b[8*6] + 4)>>3;
  3550. a0 = (W0*b[8*0]+W0*b[8*4] )>>3;
  3551. a4 = (W0*b[8*0]-W0*b[8*4] )>>3;
  3552. /*step 2*/
  3553. s1 = (181*(a1-a5+a7-a3)+128)>>8;
  3554. s2 = (181*(a1-a5-a7+a3)+128)>>8;
  3555. /*step 3*/
  3556. b[8*0] = (a0+a2+a1+a5 + (1<<13))>>14;
  3557. b[8*1] = (a4+a6 +s1 + (1<<13))>>14;
  3558. b[8*2] = (a4-a6 +s2 + (1<<13))>>14;
  3559. b[8*3] = (a0-a2+a7+a3 + (1<<13))>>14;
  3560. b[8*4] = (a0-a2-a7-a3 + (1<<13))>>14;
  3561. b[8*5] = (a4-a6 -s2 + (1<<13))>>14;
  3562. b[8*6] = (a4+a6 -s1 + (1<<13))>>14;
  3563. b[8*7] = (a0+a2-a1-a5 + (1<<13))>>14;
  3564. }
  3565. void ff_wmv2_idct_c(short * block){
  3566. int i;
  3567. for(i=0;i<64;i+=8){
  3568. wmv2_idct_row(block+i);
  3569. }
  3570. for(i=0;i<8;i++){
  3571. wmv2_idct_col(block+i);
  3572. }
  3573. }
  3574. /* XXX: those functions should be suppressed ASAP when all IDCTs are
  3575. converted */
  3576. static void ff_wmv2_idct_put_c(uint8_t *dest, int line_size, DCTELEM *block)
  3577. {
  3578. ff_wmv2_idct_c(block);
  3579. put_pixels_clamped_c(block, dest, line_size);
  3580. }
  3581. static void ff_wmv2_idct_add_c(uint8_t *dest, int line_size, DCTELEM *block)
  3582. {
  3583. ff_wmv2_idct_c(block);
  3584. add_pixels_clamped_c(block, dest, line_size);
  3585. }
  3586. static void ff_jref_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
  3587. {
  3588. j_rev_dct (block);
  3589. put_pixels_clamped_c(block, dest, line_size);
  3590. }
  3591. static void ff_jref_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
  3592. {
  3593. j_rev_dct (block);
  3594. add_pixels_clamped_c(block, dest, line_size);
  3595. }
  3596. static void ff_jref_idct4_put(uint8_t *dest, int line_size, DCTELEM *block)
  3597. {
  3598. j_rev_dct4 (block);
  3599. put_pixels_clamped4_c(block, dest, line_size);
  3600. }
  3601. static void ff_jref_idct4_add(uint8_t *dest, int line_size, DCTELEM *block)
  3602. {
  3603. j_rev_dct4 (block);
  3604. add_pixels_clamped4_c(block, dest, line_size);
  3605. }
  3606. static void ff_jref_idct2_put(uint8_t *dest, int line_size, DCTELEM *block)
  3607. {
  3608. j_rev_dct2 (block);
  3609. put_pixels_clamped2_c(block, dest, line_size);
  3610. }
  3611. static void ff_jref_idct2_add(uint8_t *dest, int line_size, DCTELEM *block)
  3612. {
  3613. j_rev_dct2 (block);
  3614. add_pixels_clamped2_c(block, dest, line_size);
  3615. }
  3616. static void ff_jref_idct1_put(uint8_t *dest, int line_size, DCTELEM *block)
  3617. {
  3618. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  3619. dest[0] = cm[(block[0] + 4)>>3];
  3620. }
  3621. static void ff_jref_idct1_add(uint8_t *dest, int line_size, DCTELEM *block)
  3622. {
  3623. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  3624. dest[0] = cm[dest[0] + ((block[0] + 4)>>3)];
  3625. }
  3626. static void just_return(void *mem av_unused, int stride av_unused, int h av_unused) { return; }
  3627. /* init static data */
  3628. void dsputil_static_init(void)
  3629. {
  3630. int i;
  3631. for(i=0;i<256;i++) ff_cropTbl[i + MAX_NEG_CROP] = i;
  3632. for(i=0;i<MAX_NEG_CROP;i++) {
  3633. ff_cropTbl[i] = 0;
  3634. ff_cropTbl[i + MAX_NEG_CROP + 256] = 255;
  3635. }
  3636. for(i=0;i<512;i++) {
  3637. ff_squareTbl[i] = (i - 256) * (i - 256);
  3638. }
  3639. for(i=0; i<64; i++) inv_zigzag_direct16[ff_zigzag_direct[i]]= i+1;
  3640. }
  3641. int ff_check_alignment(void){
  3642. static int did_fail=0;
  3643. DECLARE_ALIGNED_16(int, aligned);
  3644. if((long)&aligned & 15){
  3645. if(!did_fail){
  3646. #if defined(HAVE_MMX) || defined(HAVE_ALTIVEC)
  3647. av_log(NULL, AV_LOG_ERROR,
  3648. "Compiler did not align stack variables. Libavcodec has been miscompiled\n"
  3649. "and may be very slow or crash. This is not a bug in libavcodec,\n"
  3650. "but in the compiler. You may try recompiling using gcc >= 4.2.\n"
  3651. "Do not report crashes to FFmpeg developers.\n");
  3652. #endif
  3653. did_fail=1;
  3654. }
  3655. return -1;
  3656. }
  3657. return 0;
  3658. }
  3659. void dsputil_init(DSPContext* c, AVCodecContext *avctx)
  3660. {
  3661. int i;
  3662. ff_check_alignment();
  3663. #ifdef CONFIG_ENCODERS
  3664. if(avctx->dct_algo==FF_DCT_FASTINT) {
  3665. c->fdct = fdct_ifast;
  3666. c->fdct248 = fdct_ifast248;
  3667. }
  3668. else if(avctx->dct_algo==FF_DCT_FAAN) {
  3669. c->fdct = ff_faandct;
  3670. c->fdct248 = ff_faandct248;
  3671. }
  3672. else {
  3673. c->fdct = ff_jpeg_fdct_islow; //slow/accurate/default
  3674. c->fdct248 = ff_fdct248_islow;
  3675. }
  3676. #endif //CONFIG_ENCODERS
  3677. if(avctx->lowres==1){
  3678. if(avctx->idct_algo==FF_IDCT_INT || avctx->idct_algo==FF_IDCT_AUTO || !ENABLE_H264_DECODER){
  3679. c->idct_put= ff_jref_idct4_put;
  3680. c->idct_add= ff_jref_idct4_add;
  3681. }else{
  3682. c->idct_put= ff_h264_lowres_idct_put_c;
  3683. c->idct_add= ff_h264_lowres_idct_add_c;
  3684. }
  3685. c->idct = j_rev_dct4;
  3686. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3687. }else if(avctx->lowres==2){
  3688. c->idct_put= ff_jref_idct2_put;
  3689. c->idct_add= ff_jref_idct2_add;
  3690. c->idct = j_rev_dct2;
  3691. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3692. }else if(avctx->lowres==3){
  3693. c->idct_put= ff_jref_idct1_put;
  3694. c->idct_add= ff_jref_idct1_add;
  3695. c->idct = j_rev_dct1;
  3696. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3697. }else{
  3698. if(avctx->idct_algo==FF_IDCT_INT){
  3699. c->idct_put= ff_jref_idct_put;
  3700. c->idct_add= ff_jref_idct_add;
  3701. c->idct = j_rev_dct;
  3702. c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
  3703. }else if((ENABLE_VP3_DECODER || ENABLE_VP5_DECODER || ENABLE_VP6_DECODER || ENABLE_THEORA_DECODER ) &&
  3704. avctx->idct_algo==FF_IDCT_VP3){
  3705. c->idct_put= ff_vp3_idct_put_c;
  3706. c->idct_add= ff_vp3_idct_add_c;
  3707. c->idct = ff_vp3_idct_c;
  3708. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3709. }else if(avctx->idct_algo==FF_IDCT_WMV2){
  3710. c->idct_put= ff_wmv2_idct_put_c;
  3711. c->idct_add= ff_wmv2_idct_add_c;
  3712. c->idct = ff_wmv2_idct_c;
  3713. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3714. }else{ //accurate/default
  3715. c->idct_put= ff_simple_idct_put;
  3716. c->idct_add= ff_simple_idct_add;
  3717. c->idct = ff_simple_idct;
  3718. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3719. }
  3720. }
  3721. if (ENABLE_H264_DECODER) {
  3722. c->h264_idct_add= ff_h264_idct_add_c;
  3723. c->h264_idct8_add= ff_h264_idct8_add_c;
  3724. c->h264_idct_dc_add= ff_h264_idct_dc_add_c;
  3725. c->h264_idct8_dc_add= ff_h264_idct8_dc_add_c;
  3726. }
  3727. c->get_pixels = get_pixels_c;
  3728. c->diff_pixels = diff_pixels_c;
  3729. c->put_pixels_clamped = put_pixels_clamped_c;
  3730. c->put_signed_pixels_clamped = put_signed_pixels_clamped_c;
  3731. c->add_pixels_clamped = add_pixels_clamped_c;
  3732. c->add_pixels8 = add_pixels8_c;
  3733. c->add_pixels4 = add_pixels4_c;
  3734. c->sum_abs_dctelem = sum_abs_dctelem_c;
  3735. c->gmc1 = gmc1_c;
  3736. c->gmc = ff_gmc_c;
  3737. c->clear_blocks = clear_blocks_c;
  3738. c->pix_sum = pix_sum_c;
  3739. c->pix_norm1 = pix_norm1_c;
  3740. /* TODO [0] 16 [1] 8 */
  3741. c->pix_abs[0][0] = pix_abs16_c;
  3742. c->pix_abs[0][1] = pix_abs16_x2_c;
  3743. c->pix_abs[0][2] = pix_abs16_y2_c;
  3744. c->pix_abs[0][3] = pix_abs16_xy2_c;
  3745. c->pix_abs[1][0] = pix_abs8_c;
  3746. c->pix_abs[1][1] = pix_abs8_x2_c;
  3747. c->pix_abs[1][2] = pix_abs8_y2_c;
  3748. c->pix_abs[1][3] = pix_abs8_xy2_c;
  3749. #define dspfunc(PFX, IDX, NUM) \
  3750. c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## NUM ## _c; \
  3751. c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## NUM ## _x2_c; \
  3752. c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## NUM ## _y2_c; \
  3753. c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## NUM ## _xy2_c
  3754. dspfunc(put, 0, 16);
  3755. dspfunc(put_no_rnd, 0, 16);
  3756. dspfunc(put, 1, 8);
  3757. dspfunc(put_no_rnd, 1, 8);
  3758. dspfunc(put, 2, 4);
  3759. dspfunc(put, 3, 2);
  3760. dspfunc(avg, 0, 16);
  3761. dspfunc(avg_no_rnd, 0, 16);
  3762. dspfunc(avg, 1, 8);
  3763. dspfunc(avg_no_rnd, 1, 8);
  3764. dspfunc(avg, 2, 4);
  3765. dspfunc(avg, 3, 2);
  3766. #undef dspfunc
  3767. c->put_no_rnd_pixels_l2[0]= put_no_rnd_pixels16_l2_c;
  3768. c->put_no_rnd_pixels_l2[1]= put_no_rnd_pixels8_l2_c;
  3769. c->put_tpel_pixels_tab[ 0] = put_tpel_pixels_mc00_c;
  3770. c->put_tpel_pixels_tab[ 1] = put_tpel_pixels_mc10_c;
  3771. c->put_tpel_pixels_tab[ 2] = put_tpel_pixels_mc20_c;
  3772. c->put_tpel_pixels_tab[ 4] = put_tpel_pixels_mc01_c;
  3773. c->put_tpel_pixels_tab[ 5] = put_tpel_pixels_mc11_c;
  3774. c->put_tpel_pixels_tab[ 6] = put_tpel_pixels_mc21_c;
  3775. c->put_tpel_pixels_tab[ 8] = put_tpel_pixels_mc02_c;
  3776. c->put_tpel_pixels_tab[ 9] = put_tpel_pixels_mc12_c;
  3777. c->put_tpel_pixels_tab[10] = put_tpel_pixels_mc22_c;
  3778. c->avg_tpel_pixels_tab[ 0] = avg_tpel_pixels_mc00_c;
  3779. c->avg_tpel_pixels_tab[ 1] = avg_tpel_pixels_mc10_c;
  3780. c->avg_tpel_pixels_tab[ 2] = avg_tpel_pixels_mc20_c;
  3781. c->avg_tpel_pixels_tab[ 4] = avg_tpel_pixels_mc01_c;
  3782. c->avg_tpel_pixels_tab[ 5] = avg_tpel_pixels_mc11_c;
  3783. c->avg_tpel_pixels_tab[ 6] = avg_tpel_pixels_mc21_c;
  3784. c->avg_tpel_pixels_tab[ 8] = avg_tpel_pixels_mc02_c;
  3785. c->avg_tpel_pixels_tab[ 9] = avg_tpel_pixels_mc12_c;
  3786. c->avg_tpel_pixels_tab[10] = avg_tpel_pixels_mc22_c;
  3787. #define dspfunc(PFX, IDX, NUM) \
  3788. c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \
  3789. c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \
  3790. c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \
  3791. c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \
  3792. c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \
  3793. c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \
  3794. c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \
  3795. c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \
  3796. c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \
  3797. c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \
  3798. c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \
  3799. c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \
  3800. c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \
  3801. c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \
  3802. c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \
  3803. c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
  3804. dspfunc(put_qpel, 0, 16);
  3805. dspfunc(put_no_rnd_qpel, 0, 16);
  3806. dspfunc(avg_qpel, 0, 16);
  3807. /* dspfunc(avg_no_rnd_qpel, 0, 16); */
  3808. dspfunc(put_qpel, 1, 8);
  3809. dspfunc(put_no_rnd_qpel, 1, 8);
  3810. dspfunc(avg_qpel, 1, 8);
  3811. /* dspfunc(avg_no_rnd_qpel, 1, 8); */
  3812. dspfunc(put_h264_qpel, 0, 16);
  3813. dspfunc(put_h264_qpel, 1, 8);
  3814. dspfunc(put_h264_qpel, 2, 4);
  3815. dspfunc(put_h264_qpel, 3, 2);
  3816. dspfunc(avg_h264_qpel, 0, 16);
  3817. dspfunc(avg_h264_qpel, 1, 8);
  3818. dspfunc(avg_h264_qpel, 2, 4);
  3819. #undef dspfunc
  3820. c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_c;
  3821. c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_c;
  3822. c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_c;
  3823. c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_c;
  3824. c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_c;
  3825. c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_c;
  3826. c->put_no_rnd_h264_chroma_pixels_tab[0]= put_no_rnd_h264_chroma_mc8_c;
  3827. c->weight_h264_pixels_tab[0]= weight_h264_pixels16x16_c;
  3828. c->weight_h264_pixels_tab[1]= weight_h264_pixels16x8_c;
  3829. c->weight_h264_pixels_tab[2]= weight_h264_pixels8x16_c;
  3830. c->weight_h264_pixels_tab[3]= weight_h264_pixels8x8_c;
  3831. c->weight_h264_pixels_tab[4]= weight_h264_pixels8x4_c;
  3832. c->weight_h264_pixels_tab[5]= weight_h264_pixels4x8_c;
  3833. c->weight_h264_pixels_tab[6]= weight_h264_pixels4x4_c;
  3834. c->weight_h264_pixels_tab[7]= weight_h264_pixels4x2_c;
  3835. c->weight_h264_pixels_tab[8]= weight_h264_pixels2x4_c;
  3836. c->weight_h264_pixels_tab[9]= weight_h264_pixels2x2_c;
  3837. c->biweight_h264_pixels_tab[0]= biweight_h264_pixels16x16_c;
  3838. c->biweight_h264_pixels_tab[1]= biweight_h264_pixels16x8_c;
  3839. c->biweight_h264_pixels_tab[2]= biweight_h264_pixels8x16_c;
  3840. c->biweight_h264_pixels_tab[3]= biweight_h264_pixels8x8_c;
  3841. c->biweight_h264_pixels_tab[4]= biweight_h264_pixels8x4_c;
  3842. c->biweight_h264_pixels_tab[5]= biweight_h264_pixels4x8_c;
  3843. c->biweight_h264_pixels_tab[6]= biweight_h264_pixels4x4_c;
  3844. c->biweight_h264_pixels_tab[7]= biweight_h264_pixels4x2_c;
  3845. c->biweight_h264_pixels_tab[8]= biweight_h264_pixels2x4_c;
  3846. c->biweight_h264_pixels_tab[9]= biweight_h264_pixels2x2_c;
  3847. #ifdef CONFIG_CAVS_DECODER
  3848. ff_cavsdsp_init(c,avctx);
  3849. #endif
  3850. #if defined(CONFIG_VC1_DECODER) || defined(CONFIG_WMV3_DECODER)
  3851. ff_vc1dsp_init(c,avctx);
  3852. #endif
  3853. #if defined(CONFIG_WMV2_DECODER) || defined(CONFIG_VC1_DECODER) || defined(CONFIG_WMV3_DECODER)
  3854. ff_intrax8dsp_init(c,avctx);
  3855. #endif
  3856. #if defined(CONFIG_H264_ENCODER)
  3857. ff_h264dspenc_init(c,avctx);
  3858. #endif
  3859. c->put_mspel_pixels_tab[0]= put_mspel8_mc00_c;
  3860. c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
  3861. c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c;
  3862. c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c;
  3863. c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c;
  3864. c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c;
  3865. c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c;
  3866. c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c;
  3867. #define SET_CMP_FUNC(name) \
  3868. c->name[0]= name ## 16_c;\
  3869. c->name[1]= name ## 8x8_c;
  3870. SET_CMP_FUNC(hadamard8_diff)
  3871. c->hadamard8_diff[4]= hadamard8_intra16_c;
  3872. SET_CMP_FUNC(dct_sad)
  3873. SET_CMP_FUNC(dct_max)
  3874. #ifdef CONFIG_GPL
  3875. SET_CMP_FUNC(dct264_sad)
  3876. #endif
  3877. c->sad[0]= pix_abs16_c;
  3878. c->sad[1]= pix_abs8_c;
  3879. c->sse[0]= sse16_c;
  3880. c->sse[1]= sse8_c;
  3881. c->sse[2]= sse4_c;
  3882. SET_CMP_FUNC(quant_psnr)
  3883. SET_CMP_FUNC(rd)
  3884. SET_CMP_FUNC(bit)
  3885. c->vsad[0]= vsad16_c;
  3886. c->vsad[4]= vsad_intra16_c;
  3887. c->vsse[0]= vsse16_c;
  3888. c->vsse[4]= vsse_intra16_c;
  3889. c->nsse[0]= nsse16_c;
  3890. c->nsse[1]= nsse8_c;
  3891. #ifdef CONFIG_SNOW_ENCODER
  3892. c->w53[0]= w53_16_c;
  3893. c->w53[1]= w53_8_c;
  3894. c->w97[0]= w97_16_c;
  3895. c->w97[1]= w97_8_c;
  3896. #endif
  3897. c->ssd_int8_vs_int16 = ssd_int8_vs_int16_c;
  3898. c->add_bytes= add_bytes_c;
  3899. c->diff_bytes= diff_bytes_c;
  3900. c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c;
  3901. c->bswap_buf= bswap_buf;
  3902. c->h264_v_loop_filter_luma= h264_v_loop_filter_luma_c;
  3903. c->h264_h_loop_filter_luma= h264_h_loop_filter_luma_c;
  3904. c->h264_v_loop_filter_chroma= h264_v_loop_filter_chroma_c;
  3905. c->h264_h_loop_filter_chroma= h264_h_loop_filter_chroma_c;
  3906. c->h264_v_loop_filter_chroma_intra= h264_v_loop_filter_chroma_intra_c;
  3907. c->h264_h_loop_filter_chroma_intra= h264_h_loop_filter_chroma_intra_c;
  3908. c->h264_loop_filter_strength= NULL;
  3909. if (ENABLE_ANY_H263) {
  3910. c->h263_h_loop_filter= h263_h_loop_filter_c;
  3911. c->h263_v_loop_filter= h263_v_loop_filter_c;
  3912. }
  3913. c->h261_loop_filter= h261_loop_filter_c;
  3914. c->try_8x8basis= try_8x8basis_c;
  3915. c->add_8x8basis= add_8x8basis_c;
  3916. #ifdef CONFIG_SNOW_DECODER
  3917. c->vertical_compose97i = ff_snow_vertical_compose97i;
  3918. c->horizontal_compose97i = ff_snow_horizontal_compose97i;
  3919. c->inner_add_yblock = ff_snow_inner_add_yblock;
  3920. #endif
  3921. #ifdef CONFIG_VORBIS_DECODER
  3922. c->vorbis_inverse_coupling = vorbis_inverse_coupling;
  3923. #endif
  3924. #ifdef CONFIG_FLAC_ENCODER
  3925. c->flac_compute_autocorr = ff_flac_compute_autocorr;
  3926. #endif
  3927. c->vector_fmul = vector_fmul_c;
  3928. c->vector_fmul_reverse = vector_fmul_reverse_c;
  3929. c->vector_fmul_add_add = ff_vector_fmul_add_add_c;
  3930. c->float_to_int16 = ff_float_to_int16_c;
  3931. c->shrink[0]= ff_img_copy_plane;
  3932. c->shrink[1]= ff_shrink22;
  3933. c->shrink[2]= ff_shrink44;
  3934. c->shrink[3]= ff_shrink88;
  3935. c->prefetch= just_return;
  3936. memset(c->put_2tap_qpel_pixels_tab, 0, sizeof(c->put_2tap_qpel_pixels_tab));
  3937. memset(c->avg_2tap_qpel_pixels_tab, 0, sizeof(c->avg_2tap_qpel_pixels_tab));
  3938. if (ENABLE_MMX) dsputil_init_mmx (c, avctx);
  3939. if (ENABLE_ARMV4L) dsputil_init_armv4l(c, avctx);
  3940. if (ENABLE_MLIB) dsputil_init_mlib (c, avctx);
  3941. if (ENABLE_VIS) dsputil_init_vis (c, avctx);
  3942. if (ENABLE_ALPHA) dsputil_init_alpha (c, avctx);
  3943. if (ENABLE_POWERPC) dsputil_init_ppc (c, avctx);
  3944. if (ENABLE_MMI) dsputil_init_mmi (c, avctx);
  3945. if (ENABLE_SH4) dsputil_init_sh4 (c, avctx);
  3946. if (ENABLE_BFIN) dsputil_init_bfin (c, avctx);
  3947. for(i=0; i<64; i++){
  3948. if(!c->put_2tap_qpel_pixels_tab[0][i])
  3949. c->put_2tap_qpel_pixels_tab[0][i]= c->put_h264_qpel_pixels_tab[0][i];
  3950. if(!c->avg_2tap_qpel_pixels_tab[0][i])
  3951. c->avg_2tap_qpel_pixels_tab[0][i]= c->avg_h264_qpel_pixels_tab[0][i];
  3952. }
  3953. switch(c->idct_permutation_type){
  3954. case FF_NO_IDCT_PERM:
  3955. for(i=0; i<64; i++)
  3956. c->idct_permutation[i]= i;
  3957. break;
  3958. case FF_LIBMPEG2_IDCT_PERM:
  3959. for(i=0; i<64; i++)
  3960. c->idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
  3961. break;
  3962. case FF_SIMPLE_IDCT_PERM:
  3963. for(i=0; i<64; i++)
  3964. c->idct_permutation[i]= simple_mmx_permutation[i];
  3965. break;
  3966. case FF_TRANSPOSE_IDCT_PERM:
  3967. for(i=0; i<64; i++)
  3968. c->idct_permutation[i]= ((i&7)<<3) | (i>>3);
  3969. break;
  3970. case FF_PARTTRANS_IDCT_PERM:
  3971. for(i=0; i<64; i++)
  3972. c->idct_permutation[i]= (i&0x24) | ((i&3)<<3) | ((i>>3)&3);
  3973. break;
  3974. default:
  3975. av_log(avctx, AV_LOG_ERROR, "Internal error, IDCT permutation not set\n");
  3976. }
  3977. }