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.

4562 lines
160KB

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