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.

4921 lines
173KB

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