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.

4414 lines
156KB

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