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.

4101 lines
144KB

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