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.

4192 lines
149KB

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