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.

4960 lines
174KB

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