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.

4195 lines
147KB

  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 inline void copy_block2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  1390. {
  1391. int i;
  1392. for(i=0; i<h; i++)
  1393. {
  1394. ST16(dst , LD16(src ));
  1395. dst+=dstStride;
  1396. src+=srcStride;
  1397. }
  1398. }
  1399. static inline void copy_block4(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  1400. {
  1401. int i;
  1402. for(i=0; i<h; i++)
  1403. {
  1404. ST32(dst , LD32(src ));
  1405. dst+=dstStride;
  1406. src+=srcStride;
  1407. }
  1408. }
  1409. static inline void copy_block8(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  1410. {
  1411. int i;
  1412. for(i=0; i<h; i++)
  1413. {
  1414. ST32(dst , LD32(src ));
  1415. ST32(dst+4 , LD32(src+4 ));
  1416. dst+=dstStride;
  1417. src+=srcStride;
  1418. }
  1419. }
  1420. static inline void copy_block16(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. ST32(dst+4 , LD32(src+4 ));
  1427. ST32(dst+8 , LD32(src+8 ));
  1428. ST32(dst+12, LD32(src+12));
  1429. dst+=dstStride;
  1430. src+=srcStride;
  1431. }
  1432. }
  1433. static inline void copy_block17(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  1434. {
  1435. int i;
  1436. for(i=0; i<h; i++)
  1437. {
  1438. ST32(dst , LD32(src ));
  1439. ST32(dst+4 , LD32(src+4 ));
  1440. ST32(dst+8 , LD32(src+8 ));
  1441. ST32(dst+12, LD32(src+12));
  1442. dst[16]= src[16];
  1443. dst+=dstStride;
  1444. src+=srcStride;
  1445. }
  1446. }
  1447. static inline void copy_block9(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  1448. {
  1449. int i;
  1450. for(i=0; i<h; i++)
  1451. {
  1452. ST32(dst , LD32(src ));
  1453. ST32(dst+4 , LD32(src+4 ));
  1454. dst[8]= src[8];
  1455. dst+=dstStride;
  1456. src+=srcStride;
  1457. }
  1458. }
  1459. #define QPEL_MC(r, OPNAME, RND, OP) \
  1460. static void OPNAME ## mpeg4_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  1461. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1462. int i;\
  1463. for(i=0; i<h; i++)\
  1464. {\
  1465. OP(dst[0], (src[0]+src[1])*20 - (src[0]+src[2])*6 + (src[1]+src[3])*3 - (src[2]+src[4]));\
  1466. OP(dst[1], (src[1]+src[2])*20 - (src[0]+src[3])*6 + (src[0]+src[4])*3 - (src[1]+src[5]));\
  1467. OP(dst[2], (src[2]+src[3])*20 - (src[1]+src[4])*6 + (src[0]+src[5])*3 - (src[0]+src[6]));\
  1468. OP(dst[3], (src[3]+src[4])*20 - (src[2]+src[5])*6 + (src[1]+src[6])*3 - (src[0]+src[7]));\
  1469. OP(dst[4], (src[4]+src[5])*20 - (src[3]+src[6])*6 + (src[2]+src[7])*3 - (src[1]+src[8]));\
  1470. OP(dst[5], (src[5]+src[6])*20 - (src[4]+src[7])*6 + (src[3]+src[8])*3 - (src[2]+src[8]));\
  1471. OP(dst[6], (src[6]+src[7])*20 - (src[5]+src[8])*6 + (src[4]+src[8])*3 - (src[3]+src[7]));\
  1472. OP(dst[7], (src[7]+src[8])*20 - (src[6]+src[8])*6 + (src[5]+src[7])*3 - (src[4]+src[6]));\
  1473. dst+=dstStride;\
  1474. src+=srcStride;\
  1475. }\
  1476. }\
  1477. \
  1478. static void OPNAME ## mpeg4_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1479. const int w=8;\
  1480. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1481. int i;\
  1482. for(i=0; i<w; i++)\
  1483. {\
  1484. const int src0= src[0*srcStride];\
  1485. const int src1= src[1*srcStride];\
  1486. const int src2= src[2*srcStride];\
  1487. const int src3= src[3*srcStride];\
  1488. const int src4= src[4*srcStride];\
  1489. const int src5= src[5*srcStride];\
  1490. const int src6= src[6*srcStride];\
  1491. const int src7= src[7*srcStride];\
  1492. const int src8= src[8*srcStride];\
  1493. OP(dst[0*dstStride], (src0+src1)*20 - (src0+src2)*6 + (src1+src3)*3 - (src2+src4));\
  1494. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*6 + (src0+src4)*3 - (src1+src5));\
  1495. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*6 + (src0+src5)*3 - (src0+src6));\
  1496. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*6 + (src1+src6)*3 - (src0+src7));\
  1497. OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*6 + (src2+src7)*3 - (src1+src8));\
  1498. OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*6 + (src3+src8)*3 - (src2+src8));\
  1499. OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*6 + (src4+src8)*3 - (src3+src7));\
  1500. OP(dst[7*dstStride], (src7+src8)*20 - (src6+src8)*6 + (src5+src7)*3 - (src4+src6));\
  1501. dst++;\
  1502. src++;\
  1503. }\
  1504. }\
  1505. \
  1506. static void OPNAME ## mpeg4_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  1507. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1508. int i;\
  1509. \
  1510. for(i=0; i<h; i++)\
  1511. {\
  1512. OP(dst[ 0], (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]));\
  1513. OP(dst[ 1], (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]));\
  1514. OP(dst[ 2], (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]));\
  1515. OP(dst[ 3], (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]));\
  1516. OP(dst[ 4], (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]));\
  1517. OP(dst[ 5], (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]));\
  1518. OP(dst[ 6], (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]));\
  1519. OP(dst[ 7], (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]));\
  1520. OP(dst[ 8], (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]));\
  1521. OP(dst[ 9], (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]));\
  1522. OP(dst[10], (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]));\
  1523. OP(dst[11], (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]));\
  1524. OP(dst[12], (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]));\
  1525. OP(dst[13], (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]));\
  1526. OP(dst[14], (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]));\
  1527. OP(dst[15], (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]));\
  1528. dst+=dstStride;\
  1529. src+=srcStride;\
  1530. }\
  1531. }\
  1532. \
  1533. static void OPNAME ## mpeg4_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1534. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1535. int i;\
  1536. const int w=16;\
  1537. for(i=0; i<w; i++)\
  1538. {\
  1539. const int src0= src[0*srcStride];\
  1540. const int src1= src[1*srcStride];\
  1541. const int src2= src[2*srcStride];\
  1542. const int src3= src[3*srcStride];\
  1543. const int src4= src[4*srcStride];\
  1544. const int src5= src[5*srcStride];\
  1545. const int src6= src[6*srcStride];\
  1546. const int src7= src[7*srcStride];\
  1547. const int src8= src[8*srcStride];\
  1548. const int src9= src[9*srcStride];\
  1549. const int src10= src[10*srcStride];\
  1550. const int src11= src[11*srcStride];\
  1551. const int src12= src[12*srcStride];\
  1552. const int src13= src[13*srcStride];\
  1553. const int src14= src[14*srcStride];\
  1554. const int src15= src[15*srcStride];\
  1555. const int src16= src[16*srcStride];\
  1556. OP(dst[ 0*dstStride], (src0 +src1 )*20 - (src0 +src2 )*6 + (src1 +src3 )*3 - (src2 +src4 ));\
  1557. OP(dst[ 1*dstStride], (src1 +src2 )*20 - (src0 +src3 )*6 + (src0 +src4 )*3 - (src1 +src5 ));\
  1558. OP(dst[ 2*dstStride], (src2 +src3 )*20 - (src1 +src4 )*6 + (src0 +src5 )*3 - (src0 +src6 ));\
  1559. OP(dst[ 3*dstStride], (src3 +src4 )*20 - (src2 +src5 )*6 + (src1 +src6 )*3 - (src0 +src7 ));\
  1560. OP(dst[ 4*dstStride], (src4 +src5 )*20 - (src3 +src6 )*6 + (src2 +src7 )*3 - (src1 +src8 ));\
  1561. OP(dst[ 5*dstStride], (src5 +src6 )*20 - (src4 +src7 )*6 + (src3 +src8 )*3 - (src2 +src9 ));\
  1562. OP(dst[ 6*dstStride], (src6 +src7 )*20 - (src5 +src8 )*6 + (src4 +src9 )*3 - (src3 +src10));\
  1563. OP(dst[ 7*dstStride], (src7 +src8 )*20 - (src6 +src9 )*6 + (src5 +src10)*3 - (src4 +src11));\
  1564. OP(dst[ 8*dstStride], (src8 +src9 )*20 - (src7 +src10)*6 + (src6 +src11)*3 - (src5 +src12));\
  1565. OP(dst[ 9*dstStride], (src9 +src10)*20 - (src8 +src11)*6 + (src7 +src12)*3 - (src6 +src13));\
  1566. OP(dst[10*dstStride], (src10+src11)*20 - (src9 +src12)*6 + (src8 +src13)*3 - (src7 +src14));\
  1567. OP(dst[11*dstStride], (src11+src12)*20 - (src10+src13)*6 + (src9 +src14)*3 - (src8 +src15));\
  1568. OP(dst[12*dstStride], (src12+src13)*20 - (src11+src14)*6 + (src10+src15)*3 - (src9 +src16));\
  1569. OP(dst[13*dstStride], (src13+src14)*20 - (src12+src15)*6 + (src11+src16)*3 - (src10+src16));\
  1570. OP(dst[14*dstStride], (src14+src15)*20 - (src13+src16)*6 + (src12+src16)*3 - (src11+src15));\
  1571. OP(dst[15*dstStride], (src15+src16)*20 - (src14+src16)*6 + (src13+src15)*3 - (src12+src14));\
  1572. dst++;\
  1573. src++;\
  1574. }\
  1575. }\
  1576. \
  1577. static void OPNAME ## qpel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
  1578. OPNAME ## pixels8_c(dst, src, stride, 8);\
  1579. }\
  1580. \
  1581. static void OPNAME ## qpel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  1582. uint8_t half[64];\
  1583. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  1584. OPNAME ## pixels8_l2(dst, src, half, stride, stride, 8, 8);\
  1585. }\
  1586. \
  1587. static void OPNAME ## qpel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  1588. OPNAME ## mpeg4_qpel8_h_lowpass(dst, src, stride, stride, 8);\
  1589. }\
  1590. \
  1591. static void OPNAME ## qpel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  1592. uint8_t half[64];\
  1593. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  1594. OPNAME ## pixels8_l2(dst, src+1, half, stride, stride, 8, 8);\
  1595. }\
  1596. \
  1597. static void OPNAME ## qpel8_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  1598. uint8_t full[16*9];\
  1599. uint8_t half[64];\
  1600. copy_block9(full, src, 16, stride, 9);\
  1601. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
  1602. OPNAME ## pixels8_l2(dst, full, half, stride, 16, 8, 8);\
  1603. }\
  1604. \
  1605. static void OPNAME ## qpel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  1606. uint8_t full[16*9];\
  1607. copy_block9(full, src, 16, stride, 9);\
  1608. OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);\
  1609. }\
  1610. \
  1611. static void OPNAME ## qpel8_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  1612. uint8_t full[16*9];\
  1613. uint8_t half[64];\
  1614. copy_block9(full, src, 16, stride, 9);\
  1615. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
  1616. OPNAME ## pixels8_l2(dst, full+16, half, stride, 16, 8, 8);\
  1617. }\
  1618. void ff_ ## OPNAME ## qpel8_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1619. uint8_t full[16*9];\
  1620. uint8_t halfH[72];\
  1621. uint8_t halfV[64];\
  1622. uint8_t halfHV[64];\
  1623. copy_block9(full, src, 16, stride, 9);\
  1624. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1625. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  1626. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1627. OPNAME ## pixels8_l4(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1628. }\
  1629. static void OPNAME ## qpel8_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  1630. uint8_t full[16*9];\
  1631. uint8_t halfH[72];\
  1632. uint8_t halfHV[64];\
  1633. copy_block9(full, src, 16, stride, 9);\
  1634. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1635. put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
  1636. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1637. OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
  1638. }\
  1639. void ff_ ## OPNAME ## qpel8_mc31_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+1, 8, 16);\
  1647. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1648. OPNAME ## pixels8_l4(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1649. }\
  1650. static void OPNAME ## qpel8_mc31_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+1, 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_mc13_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, 8, 16);\
  1668. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1669. OPNAME ## pixels8_l4(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1670. }\
  1671. static void OPNAME ## qpel8_mc13_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, 8, 8, 16, 9);\
  1678. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1679. OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  1680. }\
  1681. void ff_ ## OPNAME ## qpel8_mc33_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+1, 8, 16);\
  1689. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1690. OPNAME ## pixels8_l4(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1691. }\
  1692. static void OPNAME ## qpel8_mc33_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+1, 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. static void OPNAME ## qpel8_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  1703. uint8_t halfH[72];\
  1704. uint8_t halfHV[64];\
  1705. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1706. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1707. OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
  1708. }\
  1709. static void OPNAME ## qpel8_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  1710. uint8_t halfH[72];\
  1711. uint8_t halfHV[64];\
  1712. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1713. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1714. OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  1715. }\
  1716. void ff_ ## OPNAME ## qpel8_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1717. uint8_t full[16*9];\
  1718. uint8_t halfH[72];\
  1719. uint8_t halfV[64];\
  1720. uint8_t halfHV[64];\
  1721. copy_block9(full, src, 16, stride, 9);\
  1722. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1723. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  1724. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1725. OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
  1726. }\
  1727. static void OPNAME ## qpel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  1728. uint8_t full[16*9];\
  1729. uint8_t halfH[72];\
  1730. copy_block9(full, src, 16, stride, 9);\
  1731. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1732. put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
  1733. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1734. }\
  1735. void ff_ ## OPNAME ## qpel8_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1736. uint8_t full[16*9];\
  1737. uint8_t halfH[72];\
  1738. uint8_t halfV[64];\
  1739. uint8_t halfHV[64];\
  1740. copy_block9(full, src, 16, stride, 9);\
  1741. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1742. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  1743. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1744. OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
  1745. }\
  1746. static void OPNAME ## qpel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  1747. uint8_t full[16*9];\
  1748. uint8_t halfH[72];\
  1749. copy_block9(full, src, 16, stride, 9);\
  1750. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1751. put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
  1752. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1753. }\
  1754. static void OPNAME ## qpel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  1755. uint8_t halfH[72];\
  1756. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1757. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1758. }\
  1759. static void OPNAME ## qpel16_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
  1760. OPNAME ## pixels16_c(dst, src, stride, 16);\
  1761. }\
  1762. \
  1763. static void OPNAME ## qpel16_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  1764. uint8_t half[256];\
  1765. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  1766. OPNAME ## pixels16_l2(dst, src, half, stride, stride, 16, 16);\
  1767. }\
  1768. \
  1769. static void OPNAME ## qpel16_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  1770. OPNAME ## mpeg4_qpel16_h_lowpass(dst, src, stride, stride, 16);\
  1771. }\
  1772. \
  1773. static void OPNAME ## qpel16_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  1774. uint8_t half[256];\
  1775. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  1776. OPNAME ## pixels16_l2(dst, src+1, half, stride, stride, 16, 16);\
  1777. }\
  1778. \
  1779. static void OPNAME ## qpel16_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  1780. uint8_t full[24*17];\
  1781. uint8_t half[256];\
  1782. copy_block17(full, src, 24, stride, 17);\
  1783. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
  1784. OPNAME ## pixels16_l2(dst, full, half, stride, 24, 16, 16);\
  1785. }\
  1786. \
  1787. static void OPNAME ## qpel16_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  1788. uint8_t full[24*17];\
  1789. copy_block17(full, src, 24, stride, 17);\
  1790. OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);\
  1791. }\
  1792. \
  1793. static void OPNAME ## qpel16_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  1794. uint8_t full[24*17];\
  1795. uint8_t half[256];\
  1796. copy_block17(full, src, 24, stride, 17);\
  1797. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
  1798. OPNAME ## pixels16_l2(dst, full+24, half, stride, 24, 16, 16);\
  1799. }\
  1800. void ff_ ## OPNAME ## qpel16_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1801. uint8_t full[24*17];\
  1802. uint8_t halfH[272];\
  1803. uint8_t halfV[256];\
  1804. uint8_t halfHV[256];\
  1805. copy_block17(full, src, 24, stride, 17);\
  1806. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1807. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1808. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1809. OPNAME ## pixels16_l4(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1810. }\
  1811. static void OPNAME ## qpel16_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  1812. uint8_t full[24*17];\
  1813. uint8_t halfH[272];\
  1814. uint8_t halfHV[256];\
  1815. copy_block17(full, src, 24, stride, 17);\
  1816. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1817. put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
  1818. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1819. OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
  1820. }\
  1821. void ff_ ## OPNAME ## qpel16_mc31_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+1, 16, 24);\
  1829. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1830. OPNAME ## pixels16_l4(dst, full+1, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1831. }\
  1832. static void OPNAME ## qpel16_mc31_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+1, 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_mc13_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, 16, 24);\
  1850. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1851. OPNAME ## pixels16_l4(dst, full+24, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1852. }\
  1853. static void OPNAME ## qpel16_mc13_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, 16, 16, 24, 17);\
  1860. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1861. OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1862. }\
  1863. void ff_ ## OPNAME ## qpel16_mc33_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+1, 16, 24);\
  1871. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1872. OPNAME ## pixels16_l4(dst, full+25, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1873. }\
  1874. static void OPNAME ## qpel16_mc33_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+1, 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. static void OPNAME ## qpel16_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  1885. uint8_t halfH[272];\
  1886. uint8_t halfHV[256];\
  1887. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1888. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1889. OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
  1890. }\
  1891. static void OPNAME ## qpel16_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  1892. uint8_t halfH[272];\
  1893. uint8_t halfHV[256];\
  1894. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1895. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1896. OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1897. }\
  1898. void ff_ ## OPNAME ## qpel16_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1899. uint8_t full[24*17];\
  1900. uint8_t halfH[272];\
  1901. uint8_t halfV[256];\
  1902. uint8_t halfHV[256];\
  1903. copy_block17(full, src, 24, stride, 17);\
  1904. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1905. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1906. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1907. OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
  1908. }\
  1909. static void OPNAME ## qpel16_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  1910. uint8_t full[24*17];\
  1911. uint8_t halfH[272];\
  1912. copy_block17(full, src, 24, stride, 17);\
  1913. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1914. put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
  1915. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1916. }\
  1917. void ff_ ## OPNAME ## qpel16_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1918. uint8_t full[24*17];\
  1919. uint8_t halfH[272];\
  1920. uint8_t halfV[256];\
  1921. uint8_t halfHV[256];\
  1922. copy_block17(full, src, 24, stride, 17);\
  1923. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1924. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1925. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1926. OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
  1927. }\
  1928. static void OPNAME ## qpel16_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  1929. uint8_t full[24*17];\
  1930. uint8_t halfH[272];\
  1931. copy_block17(full, src, 24, stride, 17);\
  1932. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1933. put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
  1934. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1935. }\
  1936. static void OPNAME ## qpel16_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  1937. uint8_t halfH[272];\
  1938. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1939. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1940. }
  1941. #define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
  1942. #define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1)
  1943. #define op_put(a, b) a = cm[((b) + 16)>>5]
  1944. #define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5]
  1945. QPEL_MC(0, put_ , _ , op_put)
  1946. QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd)
  1947. QPEL_MC(0, avg_ , _ , op_avg)
  1948. //QPEL_MC(1, avg_no_rnd , _ , op_avg)
  1949. #undef op_avg
  1950. #undef op_avg_no_rnd
  1951. #undef op_put
  1952. #undef op_put_no_rnd
  1953. #if 1
  1954. #define H264_LOWPASS(OPNAME, OP, OP2) \
  1955. static void OPNAME ## h264_qpel2_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1956. const int h=2;\
  1957. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1958. int i;\
  1959. for(i=0; i<h; i++)\
  1960. {\
  1961. OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
  1962. OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
  1963. dst+=dstStride;\
  1964. src+=srcStride;\
  1965. }\
  1966. }\
  1967. \
  1968. static void OPNAME ## h264_qpel2_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  1969. const int w=2;\
  1970. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1971. int i;\
  1972. for(i=0; i<w; i++)\
  1973. {\
  1974. const int srcB= src[-2*srcStride];\
  1975. const int srcA= src[-1*srcStride];\
  1976. const int src0= src[0 *srcStride];\
  1977. const int src1= src[1 *srcStride];\
  1978. const int src2= src[2 *srcStride];\
  1979. const int src3= src[3 *srcStride];\
  1980. const int src4= src[4 *srcStride];\
  1981. OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
  1982. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
  1983. dst++;\
  1984. src++;\
  1985. }\
  1986. }\
  1987. \
  1988. static void OPNAME ## h264_qpel2_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  1989. const int h=2;\
  1990. const int w=2;\
  1991. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  1992. int i;\
  1993. src -= 2*srcStride;\
  1994. for(i=0; i<h+5; i++)\
  1995. {\
  1996. tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
  1997. tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
  1998. tmp+=tmpStride;\
  1999. src+=srcStride;\
  2000. }\
  2001. tmp -= tmpStride*(h+5-2);\
  2002. for(i=0; i<w; i++)\
  2003. {\
  2004. const int tmpB= tmp[-2*tmpStride];\
  2005. const int tmpA= tmp[-1*tmpStride];\
  2006. const int tmp0= tmp[0 *tmpStride];\
  2007. const int tmp1= tmp[1 *tmpStride];\
  2008. const int tmp2= tmp[2 *tmpStride];\
  2009. const int tmp3= tmp[3 *tmpStride];\
  2010. const int tmp4= tmp[4 *tmpStride];\
  2011. OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
  2012. OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
  2013. dst++;\
  2014. tmp++;\
  2015. }\
  2016. }\
  2017. static void OPNAME ## h264_qpel4_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2018. const int h=4;\
  2019. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  2020. int i;\
  2021. for(i=0; i<h; i++)\
  2022. {\
  2023. OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
  2024. OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
  2025. OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]));\
  2026. OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]));\
  2027. dst+=dstStride;\
  2028. src+=srcStride;\
  2029. }\
  2030. }\
  2031. \
  2032. static void OPNAME ## h264_qpel4_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2033. const int w=4;\
  2034. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  2035. int i;\
  2036. for(i=0; i<w; i++)\
  2037. {\
  2038. const int srcB= src[-2*srcStride];\
  2039. const int srcA= src[-1*srcStride];\
  2040. const int src0= src[0 *srcStride];\
  2041. const int src1= src[1 *srcStride];\
  2042. const int src2= src[2 *srcStride];\
  2043. const int src3= src[3 *srcStride];\
  2044. const int src4= src[4 *srcStride];\
  2045. const int src5= src[5 *srcStride];\
  2046. const int src6= src[6 *srcStride];\
  2047. OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
  2048. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
  2049. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
  2050. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
  2051. dst++;\
  2052. src++;\
  2053. }\
  2054. }\
  2055. \
  2056. static void OPNAME ## h264_qpel4_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  2057. const int h=4;\
  2058. const int w=4;\
  2059. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  2060. int i;\
  2061. src -= 2*srcStride;\
  2062. for(i=0; i<h+5; i++)\
  2063. {\
  2064. tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
  2065. tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
  2066. tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]);\
  2067. tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]);\
  2068. tmp+=tmpStride;\
  2069. src+=srcStride;\
  2070. }\
  2071. tmp -= tmpStride*(h+5-2);\
  2072. for(i=0; i<w; i++)\
  2073. {\
  2074. const int tmpB= tmp[-2*tmpStride];\
  2075. const int tmpA= tmp[-1*tmpStride];\
  2076. const int tmp0= tmp[0 *tmpStride];\
  2077. const int tmp1= tmp[1 *tmpStride];\
  2078. const int tmp2= tmp[2 *tmpStride];\
  2079. const int tmp3= tmp[3 *tmpStride];\
  2080. const int tmp4= tmp[4 *tmpStride];\
  2081. const int tmp5= tmp[5 *tmpStride];\
  2082. const int tmp6= tmp[6 *tmpStride];\
  2083. OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
  2084. OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
  2085. OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
  2086. OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
  2087. dst++;\
  2088. tmp++;\
  2089. }\
  2090. }\
  2091. \
  2092. static void OPNAME ## h264_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2093. const int h=8;\
  2094. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  2095. int i;\
  2096. for(i=0; i<h; i++)\
  2097. {\
  2098. OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]));\
  2099. OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]));\
  2100. OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]));\
  2101. OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]));\
  2102. OP(dst[4], (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]));\
  2103. OP(dst[5], (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]));\
  2104. OP(dst[6], (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]));\
  2105. OP(dst[7], (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]));\
  2106. dst+=dstStride;\
  2107. src+=srcStride;\
  2108. }\
  2109. }\
  2110. \
  2111. static void OPNAME ## h264_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2112. const int w=8;\
  2113. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  2114. int i;\
  2115. for(i=0; i<w; i++)\
  2116. {\
  2117. const int srcB= src[-2*srcStride];\
  2118. const int srcA= src[-1*srcStride];\
  2119. const int src0= src[0 *srcStride];\
  2120. const int src1= src[1 *srcStride];\
  2121. const int src2= src[2 *srcStride];\
  2122. const int src3= src[3 *srcStride];\
  2123. const int src4= src[4 *srcStride];\
  2124. const int src5= src[5 *srcStride];\
  2125. const int src6= src[6 *srcStride];\
  2126. const int src7= src[7 *srcStride];\
  2127. const int src8= src[8 *srcStride];\
  2128. const int src9= src[9 *srcStride];\
  2129. const int src10=src[10*srcStride];\
  2130. OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
  2131. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
  2132. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
  2133. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
  2134. OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*5 + (src2+src7));\
  2135. OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*5 + (src3+src8));\
  2136. OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*5 + (src4+src9));\
  2137. OP(dst[7*dstStride], (src7+src8)*20 - (src6+src9)*5 + (src5+src10));\
  2138. dst++;\
  2139. src++;\
  2140. }\
  2141. }\
  2142. \
  2143. static void OPNAME ## h264_qpel8_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  2144. const int h=8;\
  2145. const int w=8;\
  2146. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  2147. int i;\
  2148. src -= 2*srcStride;\
  2149. for(i=0; i<h+5; i++)\
  2150. {\
  2151. tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]);\
  2152. tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]);\
  2153. tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]);\
  2154. tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]);\
  2155. tmp[4]= (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]);\
  2156. tmp[5]= (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]);\
  2157. tmp[6]= (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]);\
  2158. tmp[7]= (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]);\
  2159. tmp+=tmpStride;\
  2160. src+=srcStride;\
  2161. }\
  2162. tmp -= tmpStride*(h+5-2);\
  2163. for(i=0; i<w; i++)\
  2164. {\
  2165. const int tmpB= tmp[-2*tmpStride];\
  2166. const int tmpA= tmp[-1*tmpStride];\
  2167. const int tmp0= tmp[0 *tmpStride];\
  2168. const int tmp1= tmp[1 *tmpStride];\
  2169. const int tmp2= tmp[2 *tmpStride];\
  2170. const int tmp3= tmp[3 *tmpStride];\
  2171. const int tmp4= tmp[4 *tmpStride];\
  2172. const int tmp5= tmp[5 *tmpStride];\
  2173. const int tmp6= tmp[6 *tmpStride];\
  2174. const int tmp7= tmp[7 *tmpStride];\
  2175. const int tmp8= tmp[8 *tmpStride];\
  2176. const int tmp9= tmp[9 *tmpStride];\
  2177. const int tmp10=tmp[10*tmpStride];\
  2178. OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
  2179. OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
  2180. OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
  2181. OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
  2182. OP2(dst[4*dstStride], (tmp4+tmp5)*20 - (tmp3+tmp6)*5 + (tmp2+tmp7));\
  2183. OP2(dst[5*dstStride], (tmp5+tmp6)*20 - (tmp4+tmp7)*5 + (tmp3+tmp8));\
  2184. OP2(dst[6*dstStride], (tmp6+tmp7)*20 - (tmp5+tmp8)*5 + (tmp4+tmp9));\
  2185. OP2(dst[7*dstStride], (tmp7+tmp8)*20 - (tmp6+tmp9)*5 + (tmp5+tmp10));\
  2186. dst++;\
  2187. tmp++;\
  2188. }\
  2189. }\
  2190. \
  2191. static void OPNAME ## h264_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2192. OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
  2193. OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
  2194. src += 8*srcStride;\
  2195. dst += 8*dstStride;\
  2196. OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
  2197. OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
  2198. }\
  2199. \
  2200. static void OPNAME ## h264_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  2201. OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
  2202. OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
  2203. src += 8*srcStride;\
  2204. dst += 8*dstStride;\
  2205. OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
  2206. OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
  2207. }\
  2208. \
  2209. static void OPNAME ## h264_qpel16_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
  2210. OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
  2211. OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
  2212. src += 8*srcStride;\
  2213. dst += 8*dstStride;\
  2214. OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
  2215. OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
  2216. }\
  2217. #define H264_MC(OPNAME, SIZE) \
  2218. static void OPNAME ## h264_qpel ## SIZE ## _mc00_c (uint8_t *dst, uint8_t *src, int stride){\
  2219. OPNAME ## pixels ## SIZE ## _c(dst, src, stride, SIZE);\
  2220. }\
  2221. \
  2222. static void OPNAME ## h264_qpel ## SIZE ## _mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  2223. uint8_t half[SIZE*SIZE];\
  2224. put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
  2225. OPNAME ## pixels ## SIZE ## _l2(dst, src, half, stride, stride, SIZE, SIZE);\
  2226. }\
  2227. \
  2228. static void OPNAME ## h264_qpel ## SIZE ## _mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  2229. OPNAME ## h264_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride);\
  2230. }\
  2231. \
  2232. static void OPNAME ## h264_qpel ## SIZE ## _mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  2233. uint8_t half[SIZE*SIZE];\
  2234. put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
  2235. OPNAME ## pixels ## SIZE ## _l2(dst, src+1, half, stride, stride, SIZE, SIZE);\
  2236. }\
  2237. \
  2238. static void OPNAME ## h264_qpel ## SIZE ## _mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  2239. uint8_t full[SIZE*(SIZE+5)];\
  2240. uint8_t * const full_mid= full + SIZE*2;\
  2241. uint8_t half[SIZE*SIZE];\
  2242. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2243. put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
  2244. OPNAME ## pixels ## SIZE ## _l2(dst, full_mid, half, stride, SIZE, SIZE, SIZE);\
  2245. }\
  2246. \
  2247. static void OPNAME ## h264_qpel ## SIZE ## _mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  2248. uint8_t full[SIZE*(SIZE+5)];\
  2249. uint8_t * const full_mid= full + SIZE*2;\
  2250. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2251. OPNAME ## h264_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE);\
  2252. }\
  2253. \
  2254. static void OPNAME ## h264_qpel ## SIZE ## _mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  2255. uint8_t full[SIZE*(SIZE+5)];\
  2256. uint8_t * const full_mid= full + SIZE*2;\
  2257. uint8_t half[SIZE*SIZE];\
  2258. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2259. put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
  2260. OPNAME ## pixels ## SIZE ## _l2(dst, full_mid+SIZE, half, stride, SIZE, SIZE, SIZE);\
  2261. }\
  2262. \
  2263. static void OPNAME ## h264_qpel ## SIZE ## _mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  2264. uint8_t full[SIZE*(SIZE+5)];\
  2265. uint8_t * const full_mid= full + SIZE*2;\
  2266. uint8_t halfH[SIZE*SIZE];\
  2267. uint8_t halfV[SIZE*SIZE];\
  2268. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
  2269. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2270. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2271. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2272. }\
  2273. \
  2274. static void OPNAME ## h264_qpel ## SIZE ## _mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  2275. uint8_t full[SIZE*(SIZE+5)];\
  2276. uint8_t * const full_mid= full + SIZE*2;\
  2277. uint8_t halfH[SIZE*SIZE];\
  2278. uint8_t halfV[SIZE*SIZE];\
  2279. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
  2280. copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
  2281. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2282. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2283. }\
  2284. \
  2285. static void OPNAME ## h264_qpel ## SIZE ## _mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  2286. uint8_t full[SIZE*(SIZE+5)];\
  2287. uint8_t * const full_mid= full + SIZE*2;\
  2288. uint8_t halfH[SIZE*SIZE];\
  2289. uint8_t halfV[SIZE*SIZE];\
  2290. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
  2291. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2292. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2293. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2294. }\
  2295. \
  2296. static void OPNAME ## h264_qpel ## SIZE ## _mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  2297. uint8_t full[SIZE*(SIZE+5)];\
  2298. uint8_t * const full_mid= full + SIZE*2;\
  2299. uint8_t halfH[SIZE*SIZE];\
  2300. uint8_t halfV[SIZE*SIZE];\
  2301. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
  2302. copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
  2303. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2304. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
  2305. }\
  2306. \
  2307. static void OPNAME ## h264_qpel ## SIZE ## _mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  2308. int16_t tmp[SIZE*(SIZE+5)];\
  2309. OPNAME ## h264_qpel ## SIZE ## _hv_lowpass(dst, tmp, src, stride, SIZE, stride);\
  2310. }\
  2311. \
  2312. static void OPNAME ## h264_qpel ## SIZE ## _mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  2313. int16_t tmp[SIZE*(SIZE+5)];\
  2314. uint8_t halfH[SIZE*SIZE];\
  2315. uint8_t halfHV[SIZE*SIZE];\
  2316. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
  2317. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2318. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
  2319. }\
  2320. \
  2321. static void OPNAME ## h264_qpel ## SIZE ## _mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  2322. int16_t tmp[SIZE*(SIZE+5)];\
  2323. uint8_t halfH[SIZE*SIZE];\
  2324. uint8_t halfHV[SIZE*SIZE];\
  2325. put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
  2326. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2327. OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
  2328. }\
  2329. \
  2330. static void OPNAME ## h264_qpel ## SIZE ## _mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  2331. uint8_t full[SIZE*(SIZE+5)];\
  2332. uint8_t * const full_mid= full + SIZE*2;\
  2333. int16_t tmp[SIZE*(SIZE+5)];\
  2334. uint8_t halfV[SIZE*SIZE];\
  2335. uint8_t halfHV[SIZE*SIZE];\
  2336. copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
  2337. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2338. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2339. OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
  2340. }\
  2341. \
  2342. static void OPNAME ## h264_qpel ## SIZE ## _mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  2343. uint8_t full[SIZE*(SIZE+5)];\
  2344. uint8_t * const full_mid= full + SIZE*2;\
  2345. int16_t tmp[SIZE*(SIZE+5)];\
  2346. uint8_t halfV[SIZE*SIZE];\
  2347. uint8_t halfHV[SIZE*SIZE];\
  2348. copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
  2349. put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
  2350. put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
  2351. OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
  2352. }\
  2353. #define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
  2354. //#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7)
  2355. #define op_put(a, b) a = cm[((b) + 16)>>5]
  2356. #define op2_avg(a, b) a = (((a)+cm[((b) + 512)>>10]+1)>>1)
  2357. #define op2_put(a, b) a = cm[((b) + 512)>>10]
  2358. H264_LOWPASS(put_ , op_put, op2_put)
  2359. H264_LOWPASS(avg_ , op_avg, op2_avg)
  2360. H264_MC(put_, 2)
  2361. H264_MC(put_, 4)
  2362. H264_MC(put_, 8)
  2363. H264_MC(put_, 16)
  2364. H264_MC(avg_, 4)
  2365. H264_MC(avg_, 8)
  2366. H264_MC(avg_, 16)
  2367. #undef op_avg
  2368. #undef op_put
  2369. #undef op2_avg
  2370. #undef op2_put
  2371. #endif
  2372. #define op_scale1(x) block[x] = clip_uint8( (block[x]*weight + offset) >> log2_denom )
  2373. #define op_scale2(x) dst[x] = clip_uint8( (src[x]*weights + dst[x]*weightd + offset) >> (log2_denom+1))
  2374. #define H264_WEIGHT(W,H) \
  2375. static void weight_h264_pixels ## W ## x ## H ## _c(uint8_t *block, int stride, int log2_denom, int weight, int offset){ \
  2376. int y; \
  2377. offset <<= log2_denom; \
  2378. if(log2_denom) offset += 1<<(log2_denom-1); \
  2379. for(y=0; y<H; y++, block += stride){ \
  2380. op_scale1(0); \
  2381. op_scale1(1); \
  2382. if(W==2) continue; \
  2383. op_scale1(2); \
  2384. op_scale1(3); \
  2385. if(W==4) continue; \
  2386. op_scale1(4); \
  2387. op_scale1(5); \
  2388. op_scale1(6); \
  2389. op_scale1(7); \
  2390. if(W==8) continue; \
  2391. op_scale1(8); \
  2392. op_scale1(9); \
  2393. op_scale1(10); \
  2394. op_scale1(11); \
  2395. op_scale1(12); \
  2396. op_scale1(13); \
  2397. op_scale1(14); \
  2398. op_scale1(15); \
  2399. } \
  2400. } \
  2401. 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){ \
  2402. int y; \
  2403. offset = ((offset + 1) | 1) << log2_denom; \
  2404. for(y=0; y<H; y++, dst += stride, src += stride){ \
  2405. op_scale2(0); \
  2406. op_scale2(1); \
  2407. if(W==2) continue; \
  2408. op_scale2(2); \
  2409. op_scale2(3); \
  2410. if(W==4) continue; \
  2411. op_scale2(4); \
  2412. op_scale2(5); \
  2413. op_scale2(6); \
  2414. op_scale2(7); \
  2415. if(W==8) continue; \
  2416. op_scale2(8); \
  2417. op_scale2(9); \
  2418. op_scale2(10); \
  2419. op_scale2(11); \
  2420. op_scale2(12); \
  2421. op_scale2(13); \
  2422. op_scale2(14); \
  2423. op_scale2(15); \
  2424. } \
  2425. }
  2426. H264_WEIGHT(16,16)
  2427. H264_WEIGHT(16,8)
  2428. H264_WEIGHT(8,16)
  2429. H264_WEIGHT(8,8)
  2430. H264_WEIGHT(8,4)
  2431. H264_WEIGHT(4,8)
  2432. H264_WEIGHT(4,4)
  2433. H264_WEIGHT(4,2)
  2434. H264_WEIGHT(2,4)
  2435. H264_WEIGHT(2,2)
  2436. #undef op_scale1
  2437. #undef op_scale2
  2438. #undef H264_WEIGHT
  2439. static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){
  2440. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  2441. int i;
  2442. for(i=0; i<h; i++){
  2443. dst[0]= cm[(9*(src[0] + src[1]) - (src[-1] + src[2]) + 8)>>4];
  2444. dst[1]= cm[(9*(src[1] + src[2]) - (src[ 0] + src[3]) + 8)>>4];
  2445. dst[2]= cm[(9*(src[2] + src[3]) - (src[ 1] + src[4]) + 8)>>4];
  2446. dst[3]= cm[(9*(src[3] + src[4]) - (src[ 2] + src[5]) + 8)>>4];
  2447. dst[4]= cm[(9*(src[4] + src[5]) - (src[ 3] + src[6]) + 8)>>4];
  2448. dst[5]= cm[(9*(src[5] + src[6]) - (src[ 4] + src[7]) + 8)>>4];
  2449. dst[6]= cm[(9*(src[6] + src[7]) - (src[ 5] + src[8]) + 8)>>4];
  2450. dst[7]= cm[(9*(src[7] + src[8]) - (src[ 6] + src[9]) + 8)>>4];
  2451. dst+=dstStride;
  2452. src+=srcStride;
  2453. }
  2454. }
  2455. #ifdef CONFIG_CAVS_DECODER
  2456. /* AVS specific */
  2457. void ff_cavsdsp_init(DSPContext* c, AVCodecContext *avctx);
  2458. void ff_put_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
  2459. put_pixels8_c(dst, src, stride, 8);
  2460. }
  2461. void ff_avg_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
  2462. avg_pixels8_c(dst, src, stride, 8);
  2463. }
  2464. void ff_put_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
  2465. put_pixels16_c(dst, src, stride, 16);
  2466. }
  2467. void ff_avg_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
  2468. avg_pixels16_c(dst, src, stride, 16);
  2469. }
  2470. #endif /* CONFIG_CAVS_DECODER */
  2471. #if defined(CONFIG_VC1_DECODER) || defined(CONFIG_WMV3_DECODER)
  2472. /* VC-1 specific */
  2473. void ff_vc1dsp_init(DSPContext* c, AVCodecContext *avctx);
  2474. void ff_put_vc1_mspel_mc00_c(uint8_t *dst, uint8_t *src, int stride, int rnd) {
  2475. put_pixels8_c(dst, src, stride, 8);
  2476. }
  2477. #endif /* CONFIG_VC1_DECODER||CONFIG_WMV3_DECODER */
  2478. static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){
  2479. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  2480. int i;
  2481. for(i=0; i<w; i++){
  2482. const int src_1= src[ -srcStride];
  2483. const int src0 = src[0 ];
  2484. const int src1 = src[ srcStride];
  2485. const int src2 = src[2*srcStride];
  2486. const int src3 = src[3*srcStride];
  2487. const int src4 = src[4*srcStride];
  2488. const int src5 = src[5*srcStride];
  2489. const int src6 = src[6*srcStride];
  2490. const int src7 = src[7*srcStride];
  2491. const int src8 = src[8*srcStride];
  2492. const int src9 = src[9*srcStride];
  2493. dst[0*dstStride]= cm[(9*(src0 + src1) - (src_1 + src2) + 8)>>4];
  2494. dst[1*dstStride]= cm[(9*(src1 + src2) - (src0 + src3) + 8)>>4];
  2495. dst[2*dstStride]= cm[(9*(src2 + src3) - (src1 + src4) + 8)>>4];
  2496. dst[3*dstStride]= cm[(9*(src3 + src4) - (src2 + src5) + 8)>>4];
  2497. dst[4*dstStride]= cm[(9*(src4 + src5) - (src3 + src6) + 8)>>4];
  2498. dst[5*dstStride]= cm[(9*(src5 + src6) - (src4 + src7) + 8)>>4];
  2499. dst[6*dstStride]= cm[(9*(src6 + src7) - (src5 + src8) + 8)>>4];
  2500. dst[7*dstStride]= cm[(9*(src7 + src8) - (src6 + src9) + 8)>>4];
  2501. src++;
  2502. dst++;
  2503. }
  2504. }
  2505. static void put_mspel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){
  2506. put_pixels8_c(dst, src, stride, 8);
  2507. }
  2508. static void put_mspel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){
  2509. uint8_t half[64];
  2510. wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
  2511. put_pixels8_l2(dst, src, half, stride, stride, 8, 8);
  2512. }
  2513. static void put_mspel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){
  2514. wmv2_mspel8_h_lowpass(dst, src, stride, stride, 8);
  2515. }
  2516. static void put_mspel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){
  2517. uint8_t half[64];
  2518. wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
  2519. put_pixels8_l2(dst, src+1, half, stride, stride, 8, 8);
  2520. }
  2521. static void put_mspel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){
  2522. wmv2_mspel8_v_lowpass(dst, src, stride, stride, 8);
  2523. }
  2524. static void put_mspel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){
  2525. uint8_t halfH[88];
  2526. uint8_t halfV[64];
  2527. uint8_t halfHV[64];
  2528. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  2529. wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8);
  2530. wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
  2531. put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
  2532. }
  2533. static void put_mspel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){
  2534. uint8_t halfH[88];
  2535. uint8_t halfV[64];
  2536. uint8_t halfHV[64];
  2537. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  2538. wmv2_mspel8_v_lowpass(halfV, src+1, 8, stride, 8);
  2539. wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
  2540. put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
  2541. }
  2542. static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){
  2543. uint8_t halfH[88];
  2544. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  2545. wmv2_mspel8_v_lowpass(dst, halfH+8, stride, 8, 8);
  2546. }
  2547. static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale){
  2548. int x;
  2549. const int strength= ff_h263_loop_filter_strength[qscale];
  2550. for(x=0; x<8; x++){
  2551. int d1, d2, ad1;
  2552. int p0= src[x-2*stride];
  2553. int p1= src[x-1*stride];
  2554. int p2= src[x+0*stride];
  2555. int p3= src[x+1*stride];
  2556. int d = (p0 - p3 + 4*(p2 - p1)) / 8;
  2557. if (d<-2*strength) d1= 0;
  2558. else if(d<- strength) d1=-2*strength - d;
  2559. else if(d< strength) d1= d;
  2560. else if(d< 2*strength) d1= 2*strength - d;
  2561. else d1= 0;
  2562. p1 += d1;
  2563. p2 -= d1;
  2564. if(p1&256) p1= ~(p1>>31);
  2565. if(p2&256) p2= ~(p2>>31);
  2566. src[x-1*stride] = p1;
  2567. src[x+0*stride] = p2;
  2568. ad1= ABS(d1)>>1;
  2569. d2= clip((p0-p3)/4, -ad1, ad1);
  2570. src[x-2*stride] = p0 - d2;
  2571. src[x+ stride] = p3 + d2;
  2572. }
  2573. }
  2574. static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale){
  2575. int y;
  2576. const int strength= ff_h263_loop_filter_strength[qscale];
  2577. for(y=0; y<8; y++){
  2578. int d1, d2, ad1;
  2579. int p0= src[y*stride-2];
  2580. int p1= src[y*stride-1];
  2581. int p2= src[y*stride+0];
  2582. int p3= src[y*stride+1];
  2583. int d = (p0 - p3 + 4*(p2 - p1)) / 8;
  2584. if (d<-2*strength) d1= 0;
  2585. else if(d<- strength) d1=-2*strength - d;
  2586. else if(d< strength) d1= d;
  2587. else if(d< 2*strength) d1= 2*strength - d;
  2588. else d1= 0;
  2589. p1 += d1;
  2590. p2 -= d1;
  2591. if(p1&256) p1= ~(p1>>31);
  2592. if(p2&256) p2= ~(p2>>31);
  2593. src[y*stride-1] = p1;
  2594. src[y*stride+0] = p2;
  2595. ad1= ABS(d1)>>1;
  2596. d2= clip((p0-p3)/4, -ad1, ad1);
  2597. src[y*stride-2] = p0 - d2;
  2598. src[y*stride+1] = p3 + d2;
  2599. }
  2600. }
  2601. static void h261_loop_filter_c(uint8_t *src, int stride){
  2602. int x,y,xy,yz;
  2603. int temp[64];
  2604. for(x=0; x<8; x++){
  2605. temp[x ] = 4*src[x ];
  2606. temp[x + 7*8] = 4*src[x + 7*stride];
  2607. }
  2608. for(y=1; y<7; y++){
  2609. for(x=0; x<8; x++){
  2610. xy = y * stride + x;
  2611. yz = y * 8 + x;
  2612. temp[yz] = src[xy - stride] + 2*src[xy] + src[xy + stride];
  2613. }
  2614. }
  2615. for(y=0; y<8; y++){
  2616. src[ y*stride] = (temp[ y*8] + 2)>>2;
  2617. src[7+y*stride] = (temp[7+y*8] + 2)>>2;
  2618. for(x=1; x<7; x++){
  2619. xy = y * stride + x;
  2620. yz = y * 8 + x;
  2621. src[xy] = (temp[yz-1] + 2*temp[yz] + temp[yz+1] + 8)>>4;
  2622. }
  2623. }
  2624. }
  2625. static inline void h264_loop_filter_luma_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta, int8_t *tc0)
  2626. {
  2627. int i, d;
  2628. for( i = 0; i < 4; i++ ) {
  2629. if( tc0[i] < 0 ) {
  2630. pix += 4*ystride;
  2631. continue;
  2632. }
  2633. for( d = 0; d < 4; d++ ) {
  2634. const int p0 = pix[-1*xstride];
  2635. const int p1 = pix[-2*xstride];
  2636. const int p2 = pix[-3*xstride];
  2637. const int q0 = pix[0];
  2638. const int q1 = pix[1*xstride];
  2639. const int q2 = pix[2*xstride];
  2640. if( ABS( p0 - q0 ) < alpha &&
  2641. ABS( p1 - p0 ) < beta &&
  2642. ABS( q1 - q0 ) < beta ) {
  2643. int tc = tc0[i];
  2644. int i_delta;
  2645. if( ABS( p2 - p0 ) < beta ) {
  2646. pix[-2*xstride] = p1 + clip( (( p2 + ( ( p0 + q0 + 1 ) >> 1 ) ) >> 1) - p1, -tc0[i], tc0[i] );
  2647. tc++;
  2648. }
  2649. if( ABS( q2 - q0 ) < beta ) {
  2650. pix[ xstride] = q1 + clip( (( q2 + ( ( p0 + q0 + 1 ) >> 1 ) ) >> 1) - q1, -tc0[i], tc0[i] );
  2651. tc++;
  2652. }
  2653. i_delta = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
  2654. pix[-xstride] = clip_uint8( p0 + i_delta ); /* p0' */
  2655. pix[0] = clip_uint8( q0 - i_delta ); /* q0' */
  2656. }
  2657. pix += ystride;
  2658. }
  2659. }
  2660. }
  2661. static void h264_v_loop_filter_luma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
  2662. {
  2663. h264_loop_filter_luma_c(pix, stride, 1, alpha, beta, tc0);
  2664. }
  2665. static void h264_h_loop_filter_luma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
  2666. {
  2667. h264_loop_filter_luma_c(pix, 1, stride, alpha, beta, tc0);
  2668. }
  2669. static inline void h264_loop_filter_chroma_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta, int8_t *tc0)
  2670. {
  2671. int i, d;
  2672. for( i = 0; i < 4; i++ ) {
  2673. const int tc = tc0[i];
  2674. if( tc <= 0 ) {
  2675. pix += 2*ystride;
  2676. continue;
  2677. }
  2678. for( d = 0; d < 2; d++ ) {
  2679. const int p0 = pix[-1*xstride];
  2680. const int p1 = pix[-2*xstride];
  2681. const int q0 = pix[0];
  2682. const int q1 = pix[1*xstride];
  2683. if( ABS( p0 - q0 ) < alpha &&
  2684. ABS( p1 - p0 ) < beta &&
  2685. ABS( q1 - q0 ) < beta ) {
  2686. int delta = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
  2687. pix[-xstride] = clip_uint8( p0 + delta ); /* p0' */
  2688. pix[0] = clip_uint8( q0 - delta ); /* q0' */
  2689. }
  2690. pix += ystride;
  2691. }
  2692. }
  2693. }
  2694. static void h264_v_loop_filter_chroma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
  2695. {
  2696. h264_loop_filter_chroma_c(pix, stride, 1, alpha, beta, tc0);
  2697. }
  2698. static void h264_h_loop_filter_chroma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0)
  2699. {
  2700. h264_loop_filter_chroma_c(pix, 1, stride, alpha, beta, tc0);
  2701. }
  2702. static inline void h264_loop_filter_chroma_intra_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta)
  2703. {
  2704. int d;
  2705. for( d = 0; d < 8; d++ ) {
  2706. const int p0 = pix[-1*xstride];
  2707. const int p1 = pix[-2*xstride];
  2708. const int q0 = pix[0];
  2709. const int q1 = pix[1*xstride];
  2710. if( ABS( p0 - q0 ) < alpha &&
  2711. ABS( p1 - p0 ) < beta &&
  2712. ABS( q1 - q0 ) < beta ) {
  2713. pix[-xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */
  2714. pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */
  2715. }
  2716. pix += ystride;
  2717. }
  2718. }
  2719. static void h264_v_loop_filter_chroma_intra_c(uint8_t *pix, int stride, int alpha, int beta)
  2720. {
  2721. h264_loop_filter_chroma_intra_c(pix, stride, 1, alpha, beta);
  2722. }
  2723. static void h264_h_loop_filter_chroma_intra_c(uint8_t *pix, int stride, int alpha, int beta)
  2724. {
  2725. h264_loop_filter_chroma_intra_c(pix, 1, stride, alpha, beta);
  2726. }
  2727. static inline int pix_abs16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2728. {
  2729. int s, i;
  2730. s = 0;
  2731. for(i=0;i<h;i++) {
  2732. s += abs(pix1[0] - pix2[0]);
  2733. s += abs(pix1[1] - pix2[1]);
  2734. s += abs(pix1[2] - pix2[2]);
  2735. s += abs(pix1[3] - pix2[3]);
  2736. s += abs(pix1[4] - pix2[4]);
  2737. s += abs(pix1[5] - pix2[5]);
  2738. s += abs(pix1[6] - pix2[6]);
  2739. s += abs(pix1[7] - pix2[7]);
  2740. s += abs(pix1[8] - pix2[8]);
  2741. s += abs(pix1[9] - pix2[9]);
  2742. s += abs(pix1[10] - pix2[10]);
  2743. s += abs(pix1[11] - pix2[11]);
  2744. s += abs(pix1[12] - pix2[12]);
  2745. s += abs(pix1[13] - pix2[13]);
  2746. s += abs(pix1[14] - pix2[14]);
  2747. s += abs(pix1[15] - pix2[15]);
  2748. pix1 += line_size;
  2749. pix2 += line_size;
  2750. }
  2751. return s;
  2752. }
  2753. static int pix_abs16_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2754. {
  2755. int s, i;
  2756. s = 0;
  2757. for(i=0;i<h;i++) {
  2758. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  2759. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  2760. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  2761. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  2762. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  2763. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  2764. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  2765. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  2766. s += abs(pix1[8] - avg2(pix2[8], pix2[9]));
  2767. s += abs(pix1[9] - avg2(pix2[9], pix2[10]));
  2768. s += abs(pix1[10] - avg2(pix2[10], pix2[11]));
  2769. s += abs(pix1[11] - avg2(pix2[11], pix2[12]));
  2770. s += abs(pix1[12] - avg2(pix2[12], pix2[13]));
  2771. s += abs(pix1[13] - avg2(pix2[13], pix2[14]));
  2772. s += abs(pix1[14] - avg2(pix2[14], pix2[15]));
  2773. s += abs(pix1[15] - avg2(pix2[15], pix2[16]));
  2774. pix1 += line_size;
  2775. pix2 += line_size;
  2776. }
  2777. return s;
  2778. }
  2779. static int pix_abs16_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2780. {
  2781. int s, i;
  2782. uint8_t *pix3 = pix2 + line_size;
  2783. s = 0;
  2784. for(i=0;i<h;i++) {
  2785. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  2786. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  2787. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  2788. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  2789. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  2790. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  2791. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  2792. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  2793. s += abs(pix1[8] - avg2(pix2[8], pix3[8]));
  2794. s += abs(pix1[9] - avg2(pix2[9], pix3[9]));
  2795. s += abs(pix1[10] - avg2(pix2[10], pix3[10]));
  2796. s += abs(pix1[11] - avg2(pix2[11], pix3[11]));
  2797. s += abs(pix1[12] - avg2(pix2[12], pix3[12]));
  2798. s += abs(pix1[13] - avg2(pix2[13], pix3[13]));
  2799. s += abs(pix1[14] - avg2(pix2[14], pix3[14]));
  2800. s += abs(pix1[15] - avg2(pix2[15], pix3[15]));
  2801. pix1 += line_size;
  2802. pix2 += line_size;
  2803. pix3 += line_size;
  2804. }
  2805. return s;
  2806. }
  2807. static int pix_abs16_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2808. {
  2809. int s, i;
  2810. uint8_t *pix3 = pix2 + line_size;
  2811. s = 0;
  2812. for(i=0;i<h;i++) {
  2813. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  2814. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  2815. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  2816. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  2817. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  2818. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  2819. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  2820. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  2821. s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9]));
  2822. s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10]));
  2823. s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11]));
  2824. s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12]));
  2825. s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13]));
  2826. s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14]));
  2827. s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15]));
  2828. s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16]));
  2829. pix1 += line_size;
  2830. pix2 += line_size;
  2831. pix3 += line_size;
  2832. }
  2833. return s;
  2834. }
  2835. static inline int pix_abs8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2836. {
  2837. int s, i;
  2838. s = 0;
  2839. for(i=0;i<h;i++) {
  2840. s += abs(pix1[0] - pix2[0]);
  2841. s += abs(pix1[1] - pix2[1]);
  2842. s += abs(pix1[2] - pix2[2]);
  2843. s += abs(pix1[3] - pix2[3]);
  2844. s += abs(pix1[4] - pix2[4]);
  2845. s += abs(pix1[5] - pix2[5]);
  2846. s += abs(pix1[6] - pix2[6]);
  2847. s += abs(pix1[7] - pix2[7]);
  2848. pix1 += line_size;
  2849. pix2 += line_size;
  2850. }
  2851. return s;
  2852. }
  2853. static int pix_abs8_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2854. {
  2855. int s, i;
  2856. s = 0;
  2857. for(i=0;i<h;i++) {
  2858. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  2859. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  2860. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  2861. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  2862. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  2863. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  2864. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  2865. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  2866. pix1 += line_size;
  2867. pix2 += line_size;
  2868. }
  2869. return s;
  2870. }
  2871. static int pix_abs8_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2872. {
  2873. int s, i;
  2874. uint8_t *pix3 = pix2 + line_size;
  2875. s = 0;
  2876. for(i=0;i<h;i++) {
  2877. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  2878. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  2879. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  2880. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  2881. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  2882. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  2883. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  2884. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  2885. pix1 += line_size;
  2886. pix2 += line_size;
  2887. pix3 += line_size;
  2888. }
  2889. return s;
  2890. }
  2891. static int pix_abs8_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  2892. {
  2893. int s, i;
  2894. uint8_t *pix3 = pix2 + line_size;
  2895. s = 0;
  2896. for(i=0;i<h;i++) {
  2897. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  2898. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  2899. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  2900. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  2901. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  2902. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  2903. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  2904. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  2905. pix1 += line_size;
  2906. pix2 += line_size;
  2907. pix3 += line_size;
  2908. }
  2909. return s;
  2910. }
  2911. static int nsse16_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
  2912. MpegEncContext *c = v;
  2913. int score1=0;
  2914. int score2=0;
  2915. int x,y;
  2916. for(y=0; y<h; y++){
  2917. for(x=0; x<16; x++){
  2918. score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
  2919. }
  2920. if(y+1<h){
  2921. for(x=0; x<15; x++){
  2922. score2+= ABS( s1[x ] - s1[x +stride]
  2923. - s1[x+1] + s1[x+1+stride])
  2924. -ABS( s2[x ] - s2[x +stride]
  2925. - s2[x+1] + s2[x+1+stride]);
  2926. }
  2927. }
  2928. s1+= stride;
  2929. s2+= stride;
  2930. }
  2931. if(c) return score1 + ABS(score2)*c->avctx->nsse_weight;
  2932. else return score1 + ABS(score2)*8;
  2933. }
  2934. static int nsse8_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
  2935. MpegEncContext *c = v;
  2936. int score1=0;
  2937. int score2=0;
  2938. int x,y;
  2939. for(y=0; y<h; y++){
  2940. for(x=0; x<8; x++){
  2941. score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
  2942. }
  2943. if(y+1<h){
  2944. for(x=0; x<7; x++){
  2945. score2+= ABS( s1[x ] - s1[x +stride]
  2946. - s1[x+1] + s1[x+1+stride])
  2947. -ABS( s2[x ] - s2[x +stride]
  2948. - s2[x+1] + s2[x+1+stride]);
  2949. }
  2950. }
  2951. s1+= stride;
  2952. s2+= stride;
  2953. }
  2954. if(c) return score1 + ABS(score2)*c->avctx->nsse_weight;
  2955. else return score1 + ABS(score2)*8;
  2956. }
  2957. static int try_8x8basis_c(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){
  2958. int i;
  2959. unsigned int sum=0;
  2960. for(i=0; i<8*8; i++){
  2961. int b= rem[i] + ((basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT));
  2962. int w= weight[i];
  2963. b>>= RECON_SHIFT;
  2964. assert(-512<b && b<512);
  2965. sum += (w*b)*(w*b)>>4;
  2966. }
  2967. return sum>>2;
  2968. }
  2969. static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale){
  2970. int i;
  2971. for(i=0; i<8*8; i++){
  2972. rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT);
  2973. }
  2974. }
  2975. /**
  2976. * permutes an 8x8 block.
  2977. * @param block the block which will be permuted according to the given permutation vector
  2978. * @param permutation the permutation vector
  2979. * @param last the last non zero coefficient in scantable order, used to speed the permutation up
  2980. * @param scantable the used scantable, this is only used to speed the permutation up, the block is not
  2981. * (inverse) permutated to scantable order!
  2982. */
  2983. void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last)
  2984. {
  2985. int i;
  2986. DCTELEM temp[64];
  2987. if(last<=0) return;
  2988. //if(permutation[1]==1) return; //FIXME its ok but not clean and might fail for some perms
  2989. for(i=0; i<=last; i++){
  2990. const int j= scantable[i];
  2991. temp[j]= block[j];
  2992. block[j]=0;
  2993. }
  2994. for(i=0; i<=last; i++){
  2995. const int j= scantable[i];
  2996. const int perm_j= permutation[j];
  2997. block[perm_j]= temp[j];
  2998. }
  2999. }
  3000. static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){
  3001. return 0;
  3002. }
  3003. void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){
  3004. int i;
  3005. memset(cmp, 0, sizeof(void*)*5);
  3006. for(i=0; i<5; i++){
  3007. switch(type&0xFF){
  3008. case FF_CMP_SAD:
  3009. cmp[i]= c->sad[i];
  3010. break;
  3011. case FF_CMP_SATD:
  3012. cmp[i]= c->hadamard8_diff[i];
  3013. break;
  3014. case FF_CMP_SSE:
  3015. cmp[i]= c->sse[i];
  3016. break;
  3017. case FF_CMP_DCT:
  3018. cmp[i]= c->dct_sad[i];
  3019. break;
  3020. case FF_CMP_DCT264:
  3021. cmp[i]= c->dct264_sad[i];
  3022. break;
  3023. case FF_CMP_DCTMAX:
  3024. cmp[i]= c->dct_max[i];
  3025. break;
  3026. case FF_CMP_PSNR:
  3027. cmp[i]= c->quant_psnr[i];
  3028. break;
  3029. case FF_CMP_BIT:
  3030. cmp[i]= c->bit[i];
  3031. break;
  3032. case FF_CMP_RD:
  3033. cmp[i]= c->rd[i];
  3034. break;
  3035. case FF_CMP_VSAD:
  3036. cmp[i]= c->vsad[i];
  3037. break;
  3038. case FF_CMP_VSSE:
  3039. cmp[i]= c->vsse[i];
  3040. break;
  3041. case FF_CMP_ZERO:
  3042. cmp[i]= zero_cmp;
  3043. break;
  3044. case FF_CMP_NSSE:
  3045. cmp[i]= c->nsse[i];
  3046. break;
  3047. #ifdef CONFIG_SNOW_ENCODER
  3048. case FF_CMP_W53:
  3049. cmp[i]= c->w53[i];
  3050. break;
  3051. case FF_CMP_W97:
  3052. cmp[i]= c->w97[i];
  3053. break;
  3054. #endif
  3055. default:
  3056. av_log(NULL, AV_LOG_ERROR,"internal error in cmp function selection\n");
  3057. }
  3058. }
  3059. }
  3060. /**
  3061. * memset(blocks, 0, sizeof(DCTELEM)*6*64)
  3062. */
  3063. static void clear_blocks_c(DCTELEM *blocks)
  3064. {
  3065. memset(blocks, 0, sizeof(DCTELEM)*6*64);
  3066. }
  3067. static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){
  3068. int i;
  3069. for(i=0; i+7<w; i+=8){
  3070. dst[i+0] += src[i+0];
  3071. dst[i+1] += src[i+1];
  3072. dst[i+2] += src[i+2];
  3073. dst[i+3] += src[i+3];
  3074. dst[i+4] += src[i+4];
  3075. dst[i+5] += src[i+5];
  3076. dst[i+6] += src[i+6];
  3077. dst[i+7] += src[i+7];
  3078. }
  3079. for(; i<w; i++)
  3080. dst[i+0] += src[i+0];
  3081. }
  3082. static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
  3083. int i;
  3084. for(i=0; i+7<w; i+=8){
  3085. dst[i+0] = src1[i+0]-src2[i+0];
  3086. dst[i+1] = src1[i+1]-src2[i+1];
  3087. dst[i+2] = src1[i+2]-src2[i+2];
  3088. dst[i+3] = src1[i+3]-src2[i+3];
  3089. dst[i+4] = src1[i+4]-src2[i+4];
  3090. dst[i+5] = src1[i+5]-src2[i+5];
  3091. dst[i+6] = src1[i+6]-src2[i+6];
  3092. dst[i+7] = src1[i+7]-src2[i+7];
  3093. }
  3094. for(; i<w; i++)
  3095. dst[i+0] = src1[i+0]-src2[i+0];
  3096. }
  3097. static void sub_hfyu_median_prediction_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top){
  3098. int i;
  3099. uint8_t l, lt;
  3100. l= *left;
  3101. lt= *left_top;
  3102. for(i=0; i<w; i++){
  3103. const int pred= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF);
  3104. lt= src1[i];
  3105. l= src2[i];
  3106. dst[i]= l - pred;
  3107. }
  3108. *left= l;
  3109. *left_top= lt;
  3110. }
  3111. #define BUTTERFLY2(o1,o2,i1,i2) \
  3112. o1= (i1)+(i2);\
  3113. o2= (i1)-(i2);
  3114. #define BUTTERFLY1(x,y) \
  3115. {\
  3116. int a,b;\
  3117. a= x;\
  3118. b= y;\
  3119. x= a+b;\
  3120. y= a-b;\
  3121. }
  3122. #define BUTTERFLYA(x,y) (ABS((x)+(y)) + ABS((x)-(y)))
  3123. static int hadamard8_diff8x8_c(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){
  3124. int i;
  3125. int temp[64];
  3126. int sum=0;
  3127. assert(h==8);
  3128. for(i=0; i<8; i++){
  3129. //FIXME try pointer walks
  3130. 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]);
  3131. 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]);
  3132. 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]);
  3133. 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]);
  3134. BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
  3135. BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
  3136. BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
  3137. BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
  3138. BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
  3139. BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
  3140. BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
  3141. BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
  3142. }
  3143. for(i=0; i<8; i++){
  3144. BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
  3145. BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
  3146. BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
  3147. BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
  3148. BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
  3149. BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
  3150. BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
  3151. BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
  3152. sum +=
  3153. BUTTERFLYA(temp[8*0+i], temp[8*4+i])
  3154. +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
  3155. +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
  3156. +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
  3157. }
  3158. #if 0
  3159. static int maxi=0;
  3160. if(sum>maxi){
  3161. maxi=sum;
  3162. printf("MAX:%d\n", maxi);
  3163. }
  3164. #endif
  3165. return sum;
  3166. }
  3167. static int hadamard8_intra8x8_c(/*MpegEncContext*/ void *s, uint8_t *src, uint8_t *dummy, int stride, int h){
  3168. int i;
  3169. int temp[64];
  3170. int sum=0;
  3171. assert(h==8);
  3172. for(i=0; i<8; i++){
  3173. //FIXME try pointer walks
  3174. BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0],src[stride*i+1]);
  3175. BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2],src[stride*i+3]);
  3176. BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4],src[stride*i+5]);
  3177. BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6],src[stride*i+7]);
  3178. BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
  3179. BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
  3180. BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
  3181. BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
  3182. BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
  3183. BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
  3184. BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
  3185. BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
  3186. }
  3187. for(i=0; i<8; i++){
  3188. BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
  3189. BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
  3190. BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
  3191. BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
  3192. BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
  3193. BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
  3194. BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
  3195. BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
  3196. sum +=
  3197. BUTTERFLYA(temp[8*0+i], temp[8*4+i])
  3198. +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
  3199. +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
  3200. +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
  3201. }
  3202. sum -= ABS(temp[8*0] + temp[8*4]); // -mean
  3203. return sum;
  3204. }
  3205. static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3206. MpegEncContext * const s= (MpegEncContext *)c;
  3207. DECLARE_ALIGNED_8(uint64_t, aligned_temp[sizeof(DCTELEM)*64/8]);
  3208. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  3209. int sum=0, i;
  3210. assert(h==8);
  3211. s->dsp.diff_pixels(temp, src1, src2, stride);
  3212. s->dsp.fdct(temp);
  3213. for(i=0; i<64; i++)
  3214. sum+= ABS(temp[i]);
  3215. return sum;
  3216. }
  3217. #ifdef CONFIG_GPL
  3218. #define DCT8_1D {\
  3219. const int s07 = SRC(0) + SRC(7);\
  3220. const int s16 = SRC(1) + SRC(6);\
  3221. const int s25 = SRC(2) + SRC(5);\
  3222. const int s34 = SRC(3) + SRC(4);\
  3223. const int a0 = s07 + s34;\
  3224. const int a1 = s16 + s25;\
  3225. const int a2 = s07 - s34;\
  3226. const int a3 = s16 - s25;\
  3227. const int d07 = SRC(0) - SRC(7);\
  3228. const int d16 = SRC(1) - SRC(6);\
  3229. const int d25 = SRC(2) - SRC(5);\
  3230. const int d34 = SRC(3) - SRC(4);\
  3231. const int a4 = d16 + d25 + (d07 + (d07>>1));\
  3232. const int a5 = d07 - d34 - (d25 + (d25>>1));\
  3233. const int a6 = d07 + d34 - (d16 + (d16>>1));\
  3234. const int a7 = d16 - d25 + (d34 + (d34>>1));\
  3235. DST(0, a0 + a1 ) ;\
  3236. DST(1, a4 + (a7>>2)) ;\
  3237. DST(2, a2 + (a3>>1)) ;\
  3238. DST(3, a5 + (a6>>2)) ;\
  3239. DST(4, a0 - a1 ) ;\
  3240. DST(5, a6 - (a5>>2)) ;\
  3241. DST(6, (a2>>1) - a3 ) ;\
  3242. DST(7, (a4>>2) - a7 ) ;\
  3243. }
  3244. static int dct264_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3245. MpegEncContext * const s= (MpegEncContext *)c;
  3246. int16_t dct[8][8];
  3247. int i;
  3248. int sum=0;
  3249. s->dsp.diff_pixels(dct, src1, src2, stride);
  3250. #define SRC(x) dct[i][x]
  3251. #define DST(x,v) dct[i][x]= v
  3252. for( i = 0; i < 8; i++ )
  3253. DCT8_1D
  3254. #undef SRC
  3255. #undef DST
  3256. #define SRC(x) dct[x][i]
  3257. #define DST(x,v) sum += ABS(v)
  3258. for( i = 0; i < 8; i++ )
  3259. DCT8_1D
  3260. #undef SRC
  3261. #undef DST
  3262. return sum;
  3263. }
  3264. #endif
  3265. static int dct_max8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3266. MpegEncContext * const s= (MpegEncContext *)c;
  3267. DECLARE_ALIGNED_8(uint64_t, aligned_temp[sizeof(DCTELEM)*64/8]);
  3268. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  3269. int sum=0, i;
  3270. assert(h==8);
  3271. s->dsp.diff_pixels(temp, src1, src2, stride);
  3272. s->dsp.fdct(temp);
  3273. for(i=0; i<64; i++)
  3274. sum= FFMAX(sum, ABS(temp[i]));
  3275. return sum;
  3276. }
  3277. void simple_idct(DCTELEM *block); //FIXME
  3278. static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3279. MpegEncContext * const s= (MpegEncContext *)c;
  3280. DECLARE_ALIGNED_8 (uint64_t, aligned_temp[sizeof(DCTELEM)*64*2/8]);
  3281. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  3282. DCTELEM * const bak = ((DCTELEM*)aligned_temp)+64;
  3283. int sum=0, i;
  3284. assert(h==8);
  3285. s->mb_intra=0;
  3286. s->dsp.diff_pixels(temp, src1, src2, stride);
  3287. memcpy(bak, temp, 64*sizeof(DCTELEM));
  3288. s->block_last_index[0/*FIXME*/]= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  3289. s->dct_unquantize_inter(s, temp, 0, s->qscale);
  3290. simple_idct(temp); //FIXME
  3291. for(i=0; i<64; i++)
  3292. sum+= (temp[i]-bak[i])*(temp[i]-bak[i]);
  3293. return sum;
  3294. }
  3295. static int rd8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3296. MpegEncContext * const s= (MpegEncContext *)c;
  3297. const uint8_t *scantable= s->intra_scantable.permutated;
  3298. DECLARE_ALIGNED_8 (uint64_t, aligned_temp[sizeof(DCTELEM)*64/8]);
  3299. DECLARE_ALIGNED_8 (uint64_t, aligned_bak[stride]);
  3300. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  3301. uint8_t * const bak= (uint8_t*)aligned_bak;
  3302. int i, last, run, bits, level, distoration, start_i;
  3303. const int esc_length= s->ac_esc_length;
  3304. uint8_t * length;
  3305. uint8_t * last_length;
  3306. assert(h==8);
  3307. for(i=0; i<8; i++){
  3308. ((uint32_t*)(bak + i*stride))[0]= ((uint32_t*)(src2 + i*stride))[0];
  3309. ((uint32_t*)(bak + i*stride))[1]= ((uint32_t*)(src2 + i*stride))[1];
  3310. }
  3311. s->dsp.diff_pixels(temp, src1, src2, stride);
  3312. s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  3313. bits=0;
  3314. if (s->mb_intra) {
  3315. start_i = 1;
  3316. length = s->intra_ac_vlc_length;
  3317. last_length= s->intra_ac_vlc_last_length;
  3318. bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
  3319. } else {
  3320. start_i = 0;
  3321. length = s->inter_ac_vlc_length;
  3322. last_length= s->inter_ac_vlc_last_length;
  3323. }
  3324. if(last>=start_i){
  3325. run=0;
  3326. for(i=start_i; i<last; i++){
  3327. int j= scantable[i];
  3328. level= temp[j];
  3329. if(level){
  3330. level+=64;
  3331. if((level&(~127)) == 0){
  3332. bits+= length[UNI_AC_ENC_INDEX(run, level)];
  3333. }else
  3334. bits+= esc_length;
  3335. run=0;
  3336. }else
  3337. run++;
  3338. }
  3339. i= scantable[last];
  3340. level= temp[i] + 64;
  3341. assert(level - 64);
  3342. if((level&(~127)) == 0){
  3343. bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
  3344. }else
  3345. bits+= esc_length;
  3346. }
  3347. if(last>=0){
  3348. if(s->mb_intra)
  3349. s->dct_unquantize_intra(s, temp, 0, s->qscale);
  3350. else
  3351. s->dct_unquantize_inter(s, temp, 0, s->qscale);
  3352. }
  3353. s->dsp.idct_add(bak, stride, temp);
  3354. distoration= s->dsp.sse[1](NULL, bak, src1, stride, 8);
  3355. return distoration + ((bits*s->qscale*s->qscale*109 + 64)>>7);
  3356. }
  3357. static int bit8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
  3358. MpegEncContext * const s= (MpegEncContext *)c;
  3359. const uint8_t *scantable= s->intra_scantable.permutated;
  3360. DECLARE_ALIGNED_8 (uint64_t, aligned_temp[sizeof(DCTELEM)*64/8]);
  3361. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  3362. int i, last, run, bits, level, start_i;
  3363. const int esc_length= s->ac_esc_length;
  3364. uint8_t * length;
  3365. uint8_t * last_length;
  3366. assert(h==8);
  3367. s->dsp.diff_pixels(temp, src1, src2, stride);
  3368. s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  3369. bits=0;
  3370. if (s->mb_intra) {
  3371. start_i = 1;
  3372. length = s->intra_ac_vlc_length;
  3373. last_length= s->intra_ac_vlc_last_length;
  3374. bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
  3375. } else {
  3376. start_i = 0;
  3377. length = s->inter_ac_vlc_length;
  3378. last_length= s->inter_ac_vlc_last_length;
  3379. }
  3380. if(last>=start_i){
  3381. run=0;
  3382. for(i=start_i; i<last; i++){
  3383. int j= scantable[i];
  3384. level= temp[j];
  3385. if(level){
  3386. level+=64;
  3387. if((level&(~127)) == 0){
  3388. bits+= length[UNI_AC_ENC_INDEX(run, level)];
  3389. }else
  3390. bits+= esc_length;
  3391. run=0;
  3392. }else
  3393. run++;
  3394. }
  3395. i= scantable[last];
  3396. level= temp[i] + 64;
  3397. assert(level - 64);
  3398. if((level&(~127)) == 0){
  3399. bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
  3400. }else
  3401. bits+= esc_length;
  3402. }
  3403. return bits;
  3404. }
  3405. static int vsad_intra16_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){
  3406. int score=0;
  3407. int x,y;
  3408. for(y=1; y<h; y++){
  3409. for(x=0; x<16; x+=4){
  3410. score+= ABS(s[x ] - s[x +stride]) + ABS(s[x+1] - s[x+1+stride])
  3411. +ABS(s[x+2] - s[x+2+stride]) + ABS(s[x+3] - s[x+3+stride]);
  3412. }
  3413. s+= stride;
  3414. }
  3415. return score;
  3416. }
  3417. static int vsad16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
  3418. int score=0;
  3419. int x,y;
  3420. for(y=1; y<h; y++){
  3421. for(x=0; x<16; x++){
  3422. score+= ABS(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
  3423. }
  3424. s1+= stride;
  3425. s2+= stride;
  3426. }
  3427. return score;
  3428. }
  3429. #define SQ(a) ((a)*(a))
  3430. static int vsse_intra16_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){
  3431. int score=0;
  3432. int x,y;
  3433. for(y=1; y<h; y++){
  3434. for(x=0; x<16; x+=4){
  3435. score+= SQ(s[x ] - s[x +stride]) + SQ(s[x+1] - s[x+1+stride])
  3436. +SQ(s[x+2] - s[x+2+stride]) + SQ(s[x+3] - s[x+3+stride]);
  3437. }
  3438. s+= stride;
  3439. }
  3440. return score;
  3441. }
  3442. static int vsse16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
  3443. int score=0;
  3444. int x,y;
  3445. for(y=1; y<h; y++){
  3446. for(x=0; x<16; x++){
  3447. score+= SQ(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
  3448. }
  3449. s1+= stride;
  3450. s2+= stride;
  3451. }
  3452. return score;
  3453. }
  3454. WARPER8_16_SQ(hadamard8_diff8x8_c, hadamard8_diff16_c)
  3455. WARPER8_16_SQ(hadamard8_intra8x8_c, hadamard8_intra16_c)
  3456. WARPER8_16_SQ(dct_sad8x8_c, dct_sad16_c)
  3457. #ifdef CONFIG_GPL
  3458. WARPER8_16_SQ(dct264_sad8x8_c, dct264_sad16_c)
  3459. #endif
  3460. WARPER8_16_SQ(dct_max8x8_c, dct_max16_c)
  3461. WARPER8_16_SQ(quant_psnr8x8_c, quant_psnr16_c)
  3462. WARPER8_16_SQ(rd8x8_c, rd16_c)
  3463. WARPER8_16_SQ(bit8x8_c, bit16_c)
  3464. static void vector_fmul_c(float *dst, const float *src, int len){
  3465. int i;
  3466. for(i=0; i<len; i++)
  3467. dst[i] *= src[i];
  3468. }
  3469. static void vector_fmul_reverse_c(float *dst, const float *src0, const float *src1, int len){
  3470. int i;
  3471. src1 += len-1;
  3472. for(i=0; i<len; i++)
  3473. dst[i] = src0[i] * src1[-i];
  3474. }
  3475. void ff_vector_fmul_add_add_c(float *dst, const float *src0, const float *src1, const float *src2, int src3, int len, int step){
  3476. int i;
  3477. for(i=0; i<len; i++)
  3478. dst[i*step] = src0[i] * src1[i] + src2[i] + src3;
  3479. }
  3480. void ff_float_to_int16_c(int16_t *dst, const float *src, int len){
  3481. int i;
  3482. for(i=0; i<len; i++) {
  3483. int_fast32_t tmp = ((int32_t*)src)[i];
  3484. if(tmp & 0xf0000){
  3485. tmp = (0x43c0ffff - tmp)>>31;
  3486. // is this faster on some gcc/cpu combinations?
  3487. // if(tmp > 0x43c0ffff) tmp = 0xFFFF;
  3488. // else tmp = 0;
  3489. }
  3490. dst[i] = tmp - 0x8000;
  3491. }
  3492. }
  3493. /* XXX: those functions should be suppressed ASAP when all IDCTs are
  3494. converted */
  3495. static void ff_jref_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
  3496. {
  3497. j_rev_dct (block);
  3498. put_pixels_clamped_c(block, dest, line_size);
  3499. }
  3500. static void ff_jref_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
  3501. {
  3502. j_rev_dct (block);
  3503. add_pixels_clamped_c(block, dest, line_size);
  3504. }
  3505. static void ff_jref_idct4_put(uint8_t *dest, int line_size, DCTELEM *block)
  3506. {
  3507. j_rev_dct4 (block);
  3508. put_pixels_clamped4_c(block, dest, line_size);
  3509. }
  3510. static void ff_jref_idct4_add(uint8_t *dest, int line_size, DCTELEM *block)
  3511. {
  3512. j_rev_dct4 (block);
  3513. add_pixels_clamped4_c(block, dest, line_size);
  3514. }
  3515. static void ff_jref_idct2_put(uint8_t *dest, int line_size, DCTELEM *block)
  3516. {
  3517. j_rev_dct2 (block);
  3518. put_pixels_clamped2_c(block, dest, line_size);
  3519. }
  3520. static void ff_jref_idct2_add(uint8_t *dest, int line_size, DCTELEM *block)
  3521. {
  3522. j_rev_dct2 (block);
  3523. add_pixels_clamped2_c(block, dest, line_size);
  3524. }
  3525. static void ff_jref_idct1_put(uint8_t *dest, int line_size, DCTELEM *block)
  3526. {
  3527. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  3528. dest[0] = cm[(block[0] + 4)>>3];
  3529. }
  3530. static void ff_jref_idct1_add(uint8_t *dest, int line_size, DCTELEM *block)
  3531. {
  3532. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  3533. dest[0] = cm[dest[0] + ((block[0] + 4)>>3)];
  3534. }
  3535. static void just_return() { return; }
  3536. /* init static data */
  3537. void dsputil_static_init(void)
  3538. {
  3539. int i;
  3540. for(i=0;i<256;i++) cropTbl[i + MAX_NEG_CROP] = i;
  3541. for(i=0;i<MAX_NEG_CROP;i++) {
  3542. cropTbl[i] = 0;
  3543. cropTbl[i + MAX_NEG_CROP + 256] = 255;
  3544. }
  3545. for(i=0;i<512;i++) {
  3546. squareTbl[i] = (i - 256) * (i - 256);
  3547. }
  3548. for(i=0; i<64; i++) inv_zigzag_direct16[ff_zigzag_direct[i]]= i+1;
  3549. }
  3550. void dsputil_init(DSPContext* c, AVCodecContext *avctx)
  3551. {
  3552. int i;
  3553. #ifdef CONFIG_ENCODERS
  3554. if(avctx->dct_algo==FF_DCT_FASTINT) {
  3555. c->fdct = fdct_ifast;
  3556. c->fdct248 = fdct_ifast248;
  3557. }
  3558. else if(avctx->dct_algo==FF_DCT_FAAN) {
  3559. c->fdct = ff_faandct;
  3560. c->fdct248 = ff_faandct248;
  3561. }
  3562. else {
  3563. c->fdct = ff_jpeg_fdct_islow; //slow/accurate/default
  3564. c->fdct248 = ff_fdct248_islow;
  3565. }
  3566. #endif //CONFIG_ENCODERS
  3567. if(avctx->lowres==1){
  3568. if(avctx->idct_algo==FF_IDCT_INT || avctx->idct_algo==FF_IDCT_AUTO){
  3569. c->idct_put= ff_jref_idct4_put;
  3570. c->idct_add= ff_jref_idct4_add;
  3571. }else{
  3572. c->idct_put= ff_h264_lowres_idct_put_c;
  3573. c->idct_add= ff_h264_lowres_idct_add_c;
  3574. }
  3575. c->idct = j_rev_dct4;
  3576. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3577. }else if(avctx->lowres==2){
  3578. c->idct_put= ff_jref_idct2_put;
  3579. c->idct_add= ff_jref_idct2_add;
  3580. c->idct = j_rev_dct2;
  3581. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3582. }else if(avctx->lowres==3){
  3583. c->idct_put= ff_jref_idct1_put;
  3584. c->idct_add= ff_jref_idct1_add;
  3585. c->idct = j_rev_dct1;
  3586. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3587. }else{
  3588. if(avctx->idct_algo==FF_IDCT_INT){
  3589. c->idct_put= ff_jref_idct_put;
  3590. c->idct_add= ff_jref_idct_add;
  3591. c->idct = j_rev_dct;
  3592. c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
  3593. }else if(avctx->idct_algo==FF_IDCT_VP3){
  3594. c->idct_put= ff_vp3_idct_put_c;
  3595. c->idct_add= ff_vp3_idct_add_c;
  3596. c->idct = ff_vp3_idct_c;
  3597. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3598. }else{ //accurate/default
  3599. c->idct_put= simple_idct_put;
  3600. c->idct_add= simple_idct_add;
  3601. c->idct = simple_idct;
  3602. c->idct_permutation_type= FF_NO_IDCT_PERM;
  3603. }
  3604. }
  3605. c->h264_idct_add= ff_h264_idct_add_c;
  3606. c->h264_idct8_add= ff_h264_idct8_add_c;
  3607. c->h264_idct_dc_add= ff_h264_idct_dc_add_c;
  3608. c->h264_idct8_dc_add= ff_h264_idct8_dc_add_c;
  3609. c->get_pixels = get_pixels_c;
  3610. c->diff_pixels = diff_pixels_c;
  3611. c->put_pixels_clamped = put_pixels_clamped_c;
  3612. c->put_signed_pixels_clamped = put_signed_pixels_clamped_c;
  3613. c->add_pixels_clamped = add_pixels_clamped_c;
  3614. c->add_pixels8 = add_pixels8_c;
  3615. c->add_pixels4 = add_pixels4_c;
  3616. c->gmc1 = gmc1_c;
  3617. c->gmc = ff_gmc_c;
  3618. c->clear_blocks = clear_blocks_c;
  3619. c->pix_sum = pix_sum_c;
  3620. c->pix_norm1 = pix_norm1_c;
  3621. /* TODO [0] 16 [1] 8 */
  3622. c->pix_abs[0][0] = pix_abs16_c;
  3623. c->pix_abs[0][1] = pix_abs16_x2_c;
  3624. c->pix_abs[0][2] = pix_abs16_y2_c;
  3625. c->pix_abs[0][3] = pix_abs16_xy2_c;
  3626. c->pix_abs[1][0] = pix_abs8_c;
  3627. c->pix_abs[1][1] = pix_abs8_x2_c;
  3628. c->pix_abs[1][2] = pix_abs8_y2_c;
  3629. c->pix_abs[1][3] = pix_abs8_xy2_c;
  3630. #define dspfunc(PFX, IDX, NUM) \
  3631. c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## NUM ## _c; \
  3632. c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## NUM ## _x2_c; \
  3633. c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## NUM ## _y2_c; \
  3634. c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## NUM ## _xy2_c
  3635. dspfunc(put, 0, 16);
  3636. dspfunc(put_no_rnd, 0, 16);
  3637. dspfunc(put, 1, 8);
  3638. dspfunc(put_no_rnd, 1, 8);
  3639. dspfunc(put, 2, 4);
  3640. dspfunc(put, 3, 2);
  3641. dspfunc(avg, 0, 16);
  3642. dspfunc(avg_no_rnd, 0, 16);
  3643. dspfunc(avg, 1, 8);
  3644. dspfunc(avg_no_rnd, 1, 8);
  3645. dspfunc(avg, 2, 4);
  3646. dspfunc(avg, 3, 2);
  3647. #undef dspfunc
  3648. c->put_no_rnd_pixels_l2[0]= put_no_rnd_pixels16_l2_c;
  3649. c->put_no_rnd_pixels_l2[1]= put_no_rnd_pixels8_l2_c;
  3650. c->put_tpel_pixels_tab[ 0] = put_tpel_pixels_mc00_c;
  3651. c->put_tpel_pixels_tab[ 1] = put_tpel_pixels_mc10_c;
  3652. c->put_tpel_pixels_tab[ 2] = put_tpel_pixels_mc20_c;
  3653. c->put_tpel_pixels_tab[ 4] = put_tpel_pixels_mc01_c;
  3654. c->put_tpel_pixels_tab[ 5] = put_tpel_pixels_mc11_c;
  3655. c->put_tpel_pixels_tab[ 6] = put_tpel_pixels_mc21_c;
  3656. c->put_tpel_pixels_tab[ 8] = put_tpel_pixels_mc02_c;
  3657. c->put_tpel_pixels_tab[ 9] = put_tpel_pixels_mc12_c;
  3658. c->put_tpel_pixels_tab[10] = put_tpel_pixels_mc22_c;
  3659. c->avg_tpel_pixels_tab[ 0] = avg_tpel_pixels_mc00_c;
  3660. c->avg_tpel_pixels_tab[ 1] = avg_tpel_pixels_mc10_c;
  3661. c->avg_tpel_pixels_tab[ 2] = avg_tpel_pixels_mc20_c;
  3662. c->avg_tpel_pixels_tab[ 4] = avg_tpel_pixels_mc01_c;
  3663. c->avg_tpel_pixels_tab[ 5] = avg_tpel_pixels_mc11_c;
  3664. c->avg_tpel_pixels_tab[ 6] = avg_tpel_pixels_mc21_c;
  3665. c->avg_tpel_pixels_tab[ 8] = avg_tpel_pixels_mc02_c;
  3666. c->avg_tpel_pixels_tab[ 9] = avg_tpel_pixels_mc12_c;
  3667. c->avg_tpel_pixels_tab[10] = avg_tpel_pixels_mc22_c;
  3668. #define dspfunc(PFX, IDX, NUM) \
  3669. c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \
  3670. c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \
  3671. c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \
  3672. c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \
  3673. c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \
  3674. c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \
  3675. c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \
  3676. c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \
  3677. c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \
  3678. c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \
  3679. c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \
  3680. c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \
  3681. c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \
  3682. c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \
  3683. c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \
  3684. c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
  3685. dspfunc(put_qpel, 0, 16);
  3686. dspfunc(put_no_rnd_qpel, 0, 16);
  3687. dspfunc(avg_qpel, 0, 16);
  3688. /* dspfunc(avg_no_rnd_qpel, 0, 16); */
  3689. dspfunc(put_qpel, 1, 8);
  3690. dspfunc(put_no_rnd_qpel, 1, 8);
  3691. dspfunc(avg_qpel, 1, 8);
  3692. /* dspfunc(avg_no_rnd_qpel, 1, 8); */
  3693. dspfunc(put_h264_qpel, 0, 16);
  3694. dspfunc(put_h264_qpel, 1, 8);
  3695. dspfunc(put_h264_qpel, 2, 4);
  3696. dspfunc(put_h264_qpel, 3, 2);
  3697. dspfunc(avg_h264_qpel, 0, 16);
  3698. dspfunc(avg_h264_qpel, 1, 8);
  3699. dspfunc(avg_h264_qpel, 2, 4);
  3700. #undef dspfunc
  3701. c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_c;
  3702. c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_c;
  3703. c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_c;
  3704. c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_c;
  3705. c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_c;
  3706. c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_c;
  3707. c->weight_h264_pixels_tab[0]= weight_h264_pixels16x16_c;
  3708. c->weight_h264_pixels_tab[1]= weight_h264_pixels16x8_c;
  3709. c->weight_h264_pixels_tab[2]= weight_h264_pixels8x16_c;
  3710. c->weight_h264_pixels_tab[3]= weight_h264_pixels8x8_c;
  3711. c->weight_h264_pixels_tab[4]= weight_h264_pixels8x4_c;
  3712. c->weight_h264_pixels_tab[5]= weight_h264_pixels4x8_c;
  3713. c->weight_h264_pixels_tab[6]= weight_h264_pixels4x4_c;
  3714. c->weight_h264_pixels_tab[7]= weight_h264_pixels4x2_c;
  3715. c->weight_h264_pixels_tab[8]= weight_h264_pixels2x4_c;
  3716. c->weight_h264_pixels_tab[9]= weight_h264_pixels2x2_c;
  3717. c->biweight_h264_pixels_tab[0]= biweight_h264_pixels16x16_c;
  3718. c->biweight_h264_pixels_tab[1]= biweight_h264_pixels16x8_c;
  3719. c->biweight_h264_pixels_tab[2]= biweight_h264_pixels8x16_c;
  3720. c->biweight_h264_pixels_tab[3]= biweight_h264_pixels8x8_c;
  3721. c->biweight_h264_pixels_tab[4]= biweight_h264_pixels8x4_c;
  3722. c->biweight_h264_pixels_tab[5]= biweight_h264_pixels4x8_c;
  3723. c->biweight_h264_pixels_tab[6]= biweight_h264_pixels4x4_c;
  3724. c->biweight_h264_pixels_tab[7]= biweight_h264_pixels4x2_c;
  3725. c->biweight_h264_pixels_tab[8]= biweight_h264_pixels2x4_c;
  3726. c->biweight_h264_pixels_tab[9]= biweight_h264_pixels2x2_c;
  3727. #ifdef CONFIG_CAVS_DECODER
  3728. ff_cavsdsp_init(c,avctx);
  3729. #endif
  3730. #if defined(CONFIG_VC1_DECODER) || defined(CONFIG_WMV3_DECODER)
  3731. ff_vc1dsp_init(c,avctx);
  3732. #endif
  3733. c->put_mspel_pixels_tab[0]= put_mspel8_mc00_c;
  3734. c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
  3735. c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c;
  3736. c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c;
  3737. c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c;
  3738. c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c;
  3739. c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c;
  3740. c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c;
  3741. #define SET_CMP_FUNC(name) \
  3742. c->name[0]= name ## 16_c;\
  3743. c->name[1]= name ## 8x8_c;
  3744. SET_CMP_FUNC(hadamard8_diff)
  3745. c->hadamard8_diff[4]= hadamard8_intra16_c;
  3746. SET_CMP_FUNC(dct_sad)
  3747. SET_CMP_FUNC(dct_max)
  3748. #ifdef CONFIG_GPL
  3749. SET_CMP_FUNC(dct264_sad)
  3750. #endif
  3751. c->sad[0]= pix_abs16_c;
  3752. c->sad[1]= pix_abs8_c;
  3753. c->sse[0]= sse16_c;
  3754. c->sse[1]= sse8_c;
  3755. c->sse[2]= sse4_c;
  3756. SET_CMP_FUNC(quant_psnr)
  3757. SET_CMP_FUNC(rd)
  3758. SET_CMP_FUNC(bit)
  3759. c->vsad[0]= vsad16_c;
  3760. c->vsad[4]= vsad_intra16_c;
  3761. c->vsse[0]= vsse16_c;
  3762. c->vsse[4]= vsse_intra16_c;
  3763. c->nsse[0]= nsse16_c;
  3764. c->nsse[1]= nsse8_c;
  3765. #ifdef CONFIG_SNOW_ENCODER
  3766. c->w53[0]= w53_16_c;
  3767. c->w53[1]= w53_8_c;
  3768. c->w97[0]= w97_16_c;
  3769. c->w97[1]= w97_8_c;
  3770. #endif
  3771. c->add_bytes= add_bytes_c;
  3772. c->diff_bytes= diff_bytes_c;
  3773. c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c;
  3774. c->bswap_buf= bswap_buf;
  3775. c->h264_v_loop_filter_luma= h264_v_loop_filter_luma_c;
  3776. c->h264_h_loop_filter_luma= h264_h_loop_filter_luma_c;
  3777. c->h264_v_loop_filter_chroma= h264_v_loop_filter_chroma_c;
  3778. c->h264_h_loop_filter_chroma= h264_h_loop_filter_chroma_c;
  3779. c->h264_v_loop_filter_chroma_intra= h264_v_loop_filter_chroma_intra_c;
  3780. c->h264_h_loop_filter_chroma_intra= h264_h_loop_filter_chroma_intra_c;
  3781. c->h263_h_loop_filter= h263_h_loop_filter_c;
  3782. c->h263_v_loop_filter= h263_v_loop_filter_c;
  3783. c->h261_loop_filter= h261_loop_filter_c;
  3784. c->try_8x8basis= try_8x8basis_c;
  3785. c->add_8x8basis= add_8x8basis_c;
  3786. #ifdef CONFIG_SNOW_ENCODER
  3787. c->vertical_compose97i = ff_snow_vertical_compose97i;
  3788. c->horizontal_compose97i = ff_snow_horizontal_compose97i;
  3789. c->inner_add_yblock = ff_snow_inner_add_yblock;
  3790. #endif
  3791. #ifdef CONFIG_VORBIS_DECODER
  3792. c->vorbis_inverse_coupling = vorbis_inverse_coupling;
  3793. #endif
  3794. c->vector_fmul = vector_fmul_c;
  3795. c->vector_fmul_reverse = vector_fmul_reverse_c;
  3796. c->vector_fmul_add_add = ff_vector_fmul_add_add_c;
  3797. c->float_to_int16 = ff_float_to_int16_c;
  3798. c->shrink[0]= ff_img_copy_plane;
  3799. c->shrink[1]= ff_shrink22;
  3800. c->shrink[2]= ff_shrink44;
  3801. c->shrink[3]= ff_shrink88;
  3802. c->prefetch= just_return;
  3803. #ifdef HAVE_MMX
  3804. dsputil_init_mmx(c, avctx);
  3805. #endif
  3806. #ifdef ARCH_ARMV4L
  3807. dsputil_init_armv4l(c, avctx);
  3808. #endif
  3809. #ifdef HAVE_MLIB
  3810. dsputil_init_mlib(c, avctx);
  3811. #endif
  3812. #ifdef ARCH_SPARC
  3813. dsputil_init_vis(c,avctx);
  3814. #endif
  3815. #ifdef ARCH_ALPHA
  3816. dsputil_init_alpha(c, avctx);
  3817. #endif
  3818. #ifdef ARCH_POWERPC
  3819. dsputil_init_ppc(c, avctx);
  3820. #endif
  3821. #ifdef HAVE_MMI
  3822. dsputil_init_mmi(c, avctx);
  3823. #endif
  3824. #ifdef ARCH_SH4
  3825. dsputil_init_sh4(c,avctx);
  3826. #endif
  3827. switch(c->idct_permutation_type){
  3828. case FF_NO_IDCT_PERM:
  3829. for(i=0; i<64; i++)
  3830. c->idct_permutation[i]= i;
  3831. break;
  3832. case FF_LIBMPEG2_IDCT_PERM:
  3833. for(i=0; i<64; i++)
  3834. c->idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
  3835. break;
  3836. case FF_SIMPLE_IDCT_PERM:
  3837. for(i=0; i<64; i++)
  3838. c->idct_permutation[i]= simple_mmx_permutation[i];
  3839. break;
  3840. case FF_TRANSPOSE_IDCT_PERM:
  3841. for(i=0; i<64; i++)
  3842. c->idct_permutation[i]= ((i&7)<<3) | (i>>3);
  3843. break;
  3844. case FF_PARTTRANS_IDCT_PERM:
  3845. for(i=0; i<64; i++)
  3846. c->idct_permutation[i]= (i&0x24) | ((i&3)<<3) | ((i>>3)&3);
  3847. break;
  3848. default:
  3849. av_log(avctx, AV_LOG_ERROR, "Internal error, IDCT permutation not set\n");
  3850. }
  3851. }