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.

4928 lines
174KB

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