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.

3961 lines
140KB

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