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.

4515 lines
159KB

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