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.

4151 lines
146KB

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