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.

4202 lines
148KB

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