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.

4578 lines
161KB

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