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.

4185 lines
148KB

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