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.

4484 lines
158KB

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