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.

4603 lines
162KB

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