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.

4985 lines
175KB

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