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.

3556 lines
127KB

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