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.

4993 lines
175KB

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