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.

4353 lines
154KB

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