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.

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