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.

1738 lines
71KB

  1. /*
  2. * DSP utils
  3. * Copyright (c) 2000, 2001 Fabrice Bellard.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
  20. */
  21. #include "avcodec.h"
  22. #include "dsputil.h"
  23. #include "simple_idct.h"
  24. void (*ff_idct)(DCTELEM *block);
  25. void (*ff_idct_put)(UINT8 *dest, int line_size, DCTELEM *block);
  26. void (*ff_idct_add)(UINT8 *dest, int line_size, DCTELEM *block);
  27. void (*get_pixels)(DCTELEM *block, const UINT8 *pixels, int line_size);
  28. void (*diff_pixels)(DCTELEM *block, const UINT8 *s1, const UINT8 *s2, int stride);
  29. void (*put_pixels_clamped)(const DCTELEM *block, UINT8 *pixels, int line_size);
  30. void (*add_pixels_clamped)(const DCTELEM *block, UINT8 *pixels, int line_size);
  31. void (*gmc1)(UINT8 *dst, UINT8 *src, int srcStride, int h, int x16, int y16, int rounder);
  32. void (*clear_blocks)(DCTELEM *blocks);
  33. int (*pix_sum)(UINT8 * pix, int line_size);
  34. int (*pix_norm1)(UINT8 * pix, int line_size);
  35. op_pixels_abs_func pix_abs16x16;
  36. op_pixels_abs_func pix_abs16x16_x2;
  37. op_pixels_abs_func pix_abs16x16_y2;
  38. op_pixels_abs_func pix_abs16x16_xy2;
  39. op_pixels_abs_func pix_abs8x8;
  40. op_pixels_abs_func pix_abs8x8_x2;
  41. op_pixels_abs_func pix_abs8x8_y2;
  42. op_pixels_abs_func pix_abs8x8_xy2;
  43. UINT8 cropTbl[256 + 2 * MAX_NEG_CROP];
  44. UINT32 squareTbl[512];
  45. extern INT16 ff_mpeg1_default_intra_matrix[64];
  46. extern INT16 ff_mpeg1_default_non_intra_matrix[64];
  47. extern INT16 ff_mpeg4_default_intra_matrix[64];
  48. extern INT16 ff_mpeg4_default_non_intra_matrix[64];
  49. UINT8 zigzag_direct[64] = {
  50. 0, 1, 8, 16, 9, 2, 3, 10,
  51. 17, 24, 32, 25, 18, 11, 4, 5,
  52. 12, 19, 26, 33, 40, 48, 41, 34,
  53. 27, 20, 13, 6, 7, 14, 21, 28,
  54. 35, 42, 49, 56, 57, 50, 43, 36,
  55. 29, 22, 15, 23, 30, 37, 44, 51,
  56. 58, 59, 52, 45, 38, 31, 39, 46,
  57. 53, 60, 61, 54, 47, 55, 62, 63
  58. };
  59. /* not permutated inverse zigzag_direct + 1 for MMX quantizer */
  60. UINT16 __align8 inv_zigzag_direct16[64];
  61. /* not permutated zigzag_direct for MMX quantizer */
  62. UINT8 zigzag_direct_noperm[64];
  63. UINT8 ff_alternate_horizontal_scan[64] = {
  64. 0, 1, 2, 3, 8, 9, 16, 17,
  65. 10, 11, 4, 5, 6, 7, 15, 14,
  66. 13, 12, 19, 18, 24, 25, 32, 33,
  67. 26, 27, 20, 21, 22, 23, 28, 29,
  68. 30, 31, 34, 35, 40, 41, 48, 49,
  69. 42, 43, 36, 37, 38, 39, 44, 45,
  70. 46, 47, 50, 51, 56, 57, 58, 59,
  71. 52, 53, 54, 55, 60, 61, 62, 63,
  72. };
  73. UINT8 ff_alternate_vertical_scan[64] = {
  74. 0, 8, 16, 24, 1, 9, 2, 10,
  75. 17, 25, 32, 40, 48, 56, 57, 49,
  76. 41, 33, 26, 18, 3, 11, 4, 12,
  77. 19, 27, 34, 42, 50, 58, 35, 43,
  78. 51, 59, 20, 28, 5, 13, 6, 14,
  79. 21, 29, 36, 44, 52, 60, 37, 45,
  80. 53, 61, 22, 30, 7, 15, 23, 31,
  81. 38, 46, 54, 62, 39, 47, 55, 63,
  82. };
  83. #ifdef SIMPLE_IDCT
  84. /* Input permutation for the simple_idct_mmx */
  85. static UINT8 simple_mmx_permutation[64]={
  86. 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D,
  87. 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D,
  88. 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D,
  89. 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F,
  90. 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F,
  91. 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D,
  92. 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F,
  93. 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F,
  94. };
  95. #endif
  96. /* a*inverse[b]>>32 == a/b for all 0<=a<=65536 && 2<=b<=255 */
  97. UINT32 inverse[256]={
  98. 0, 4294967295U,2147483648U,1431655766, 1073741824, 858993460, 715827883, 613566757,
  99. 536870912, 477218589, 429496730, 390451573, 357913942, 330382100, 306783379, 286331154,
  100. 268435456, 252645136, 238609295, 226050911, 214748365, 204522253, 195225787, 186737709,
  101. 178956971, 171798692, 165191050, 159072863, 153391690, 148102321, 143165577, 138547333,
  102. 134217728, 130150525, 126322568, 122713352, 119304648, 116080198, 113025456, 110127367,
  103. 107374183, 104755300, 102261127, 99882961, 97612894, 95443718, 93368855, 91382283,
  104. 89478486, 87652394, 85899346, 84215046, 82595525, 81037119, 79536432, 78090315,
  105. 76695845, 75350304, 74051161, 72796056, 71582789, 70409300, 69273667, 68174085,
  106. 67108864, 66076420, 65075263, 64103990, 63161284, 62245903, 61356676, 60492498,
  107. 59652324, 58835169, 58040099, 57266231, 56512728, 55778797, 55063684, 54366675,
  108. 53687092, 53024288, 52377650, 51746594, 51130564, 50529028, 49941481, 49367441,
  109. 48806447, 48258060, 47721859, 47197443, 46684428, 46182445, 45691142, 45210183,
  110. 44739243, 44278014, 43826197, 43383509, 42949673, 42524429, 42107523, 41698712,
  111. 41297763, 40904451, 40518560, 40139882, 39768216, 39403370, 39045158, 38693400,
  112. 38347923, 38008561, 37675152, 37347542, 37025581, 36709123, 36398028, 36092163,
  113. 35791395, 35495598, 35204650, 34918434, 34636834, 34359739, 34087043, 33818641,
  114. 33554432, 33294321, 33038210, 32786010, 32537632, 32292988, 32051995, 31814573,
  115. 31580642, 31350127, 31122952, 30899046, 30678338, 30460761, 30246249, 30034737,
  116. 29826162, 29620465, 29417585, 29217465, 29020050, 28825284, 28633116, 28443493,
  117. 28256364, 28071682, 27889399, 27709467, 27531842, 27356480, 27183338, 27012373,
  118. 26843546, 26676816, 26512144, 26349493, 26188825, 26030105, 25873297, 25718368,
  119. 25565282, 25414008, 25264514, 25116768, 24970741, 24826401, 24683721, 24542671,
  120. 24403224, 24265352, 24129030, 23994231, 23860930, 23729102, 23598722, 23469767,
  121. 23342214, 23216040, 23091223, 22967740, 22845571, 22724695, 22605092, 22486740,
  122. 22369622, 22253717, 22139007, 22025474, 21913099, 21801865, 21691755, 21582751,
  123. 21474837, 21367997, 21262215, 21157475, 21053762, 20951060, 20849356, 20748635,
  124. 20648882, 20550083, 20452226, 20355296, 20259280, 20164166, 20069941, 19976593,
  125. 19884108, 19792477, 19701685, 19611723, 19522579, 19434242, 19346700, 19259944,
  126. 19173962, 19088744, 19004281, 18920561, 18837576, 18755316, 18673771, 18592933,
  127. 18512791, 18433337, 18354562, 18276457, 18199014, 18122225, 18046082, 17970575,
  128. 17895698, 17821442, 17747799, 17674763, 17602325, 17530479, 17459217, 17388532,
  129. 17318417, 17248865, 17179870, 17111424, 17043522, 16976156, 16909321, 16843010,
  130. };
  131. /* used to skip zeros at the end */
  132. UINT8 zigzag_end[64];
  133. UINT8 permutation[64];
  134. //UINT8 invPermutation[64];
  135. static void build_zigzag_end(void)
  136. {
  137. int lastIndex;
  138. int lastIndexAfterPerm=0;
  139. for(lastIndex=0; lastIndex<64; lastIndex++)
  140. {
  141. if(zigzag_direct[lastIndex] > lastIndexAfterPerm)
  142. lastIndexAfterPerm= zigzag_direct[lastIndex];
  143. zigzag_end[lastIndex]= lastIndexAfterPerm + 1;
  144. }
  145. }
  146. int pix_sum_c(UINT8 * pix, int line_size)
  147. {
  148. int s, i, j;
  149. s = 0;
  150. for (i = 0; i < 16; i++) {
  151. for (j = 0; j < 16; j += 8) {
  152. s += pix[0];
  153. s += pix[1];
  154. s += pix[2];
  155. s += pix[3];
  156. s += pix[4];
  157. s += pix[5];
  158. s += pix[6];
  159. s += pix[7];
  160. pix += 8;
  161. }
  162. pix += line_size - 16;
  163. }
  164. return s;
  165. }
  166. int pix_norm1_c(UINT8 * pix, int line_size)
  167. {
  168. int s, i, j;
  169. UINT32 *sq = squareTbl + 256;
  170. s = 0;
  171. for (i = 0; i < 16; i++) {
  172. for (j = 0; j < 16; j += 8) {
  173. s += sq[pix[0]];
  174. s += sq[pix[1]];
  175. s += sq[pix[2]];
  176. s += sq[pix[3]];
  177. s += sq[pix[4]];
  178. s += sq[pix[5]];
  179. s += sq[pix[6]];
  180. s += sq[pix[7]];
  181. pix += 8;
  182. }
  183. pix += line_size - 16;
  184. }
  185. return s;
  186. }
  187. void get_pixels_c(DCTELEM *restrict block, const UINT8 *pixels, int line_size)
  188. {
  189. int i;
  190. /* read the pixels */
  191. for(i=0;i<8;i++) {
  192. block[0] = pixels[0];
  193. block[1] = pixels[1];
  194. block[2] = pixels[2];
  195. block[3] = pixels[3];
  196. block[4] = pixels[4];
  197. block[5] = pixels[5];
  198. block[6] = pixels[6];
  199. block[7] = pixels[7];
  200. pixels += line_size;
  201. block += 8;
  202. }
  203. }
  204. void diff_pixels_c(DCTELEM *restrict block, const UINT8 *s1, const UINT8 *s2,
  205. int stride){
  206. int i;
  207. /* read the pixels */
  208. for(i=0;i<8;i++) {
  209. block[0] = s1[0] - s2[0];
  210. block[1] = s1[1] - s2[1];
  211. block[2] = s1[2] - s2[2];
  212. block[3] = s1[3] - s2[3];
  213. block[4] = s1[4] - s2[4];
  214. block[5] = s1[5] - s2[5];
  215. block[6] = s1[6] - s2[6];
  216. block[7] = s1[7] - s2[7];
  217. s1 += stride;
  218. s2 += stride;
  219. block += 8;
  220. }
  221. }
  222. void put_pixels_clamped_c(const DCTELEM *block, UINT8 *restrict pixels,
  223. int line_size)
  224. {
  225. int i;
  226. UINT8 *cm = cropTbl + MAX_NEG_CROP;
  227. /* read the pixels */
  228. for(i=0;i<8;i++) {
  229. pixels[0] = cm[block[0]];
  230. pixels[1] = cm[block[1]];
  231. pixels[2] = cm[block[2]];
  232. pixels[3] = cm[block[3]];
  233. pixels[4] = cm[block[4]];
  234. pixels[5] = cm[block[5]];
  235. pixels[6] = cm[block[6]];
  236. pixels[7] = cm[block[7]];
  237. pixels += line_size;
  238. block += 8;
  239. }
  240. }
  241. void add_pixels_clamped_c(const DCTELEM *block, UINT8 *restrict pixels,
  242. int line_size)
  243. {
  244. int i;
  245. UINT8 *cm = cropTbl + MAX_NEG_CROP;
  246. /* read the pixels */
  247. for(i=0;i<8;i++) {
  248. pixels[0] = cm[pixels[0] + block[0]];
  249. pixels[1] = cm[pixels[1] + block[1]];
  250. pixels[2] = cm[pixels[2] + block[2]];
  251. pixels[3] = cm[pixels[3] + block[3]];
  252. pixels[4] = cm[pixels[4] + block[4]];
  253. pixels[5] = cm[pixels[5] + block[5]];
  254. pixels[6] = cm[pixels[6] + block[6]];
  255. pixels[7] = cm[pixels[7] + block[7]];
  256. pixels += line_size;
  257. block += 8;
  258. }
  259. }
  260. #if 0
  261. #define PIXOP2(OPNAME, OP) \
  262. static void OPNAME ## _pixels(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  263. {\
  264. int i;\
  265. for(i=0; i<h; i++){\
  266. OP(*((uint64_t*)block), LD64(pixels));\
  267. pixels+=line_size;\
  268. block +=line_size;\
  269. }\
  270. }\
  271. \
  272. static void OPNAME ## _no_rnd_pixels_x2(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  273. {\
  274. int i;\
  275. for(i=0; i<h; i++){\
  276. const uint64_t a= LD64(pixels );\
  277. const uint64_t b= LD64(pixels+1);\
  278. OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  279. pixels+=line_size;\
  280. block +=line_size;\
  281. }\
  282. }\
  283. \
  284. static void OPNAME ## _pixels_x2(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  285. {\
  286. int i;\
  287. for(i=0; i<h; i++){\
  288. const uint64_t a= LD64(pixels );\
  289. const uint64_t b= LD64(pixels+1);\
  290. OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  291. pixels+=line_size;\
  292. block +=line_size;\
  293. }\
  294. }\
  295. \
  296. static void OPNAME ## _no_rnd_pixels_y2(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  297. {\
  298. int i;\
  299. for(i=0; i<h; i++){\
  300. const uint64_t a= LD64(pixels );\
  301. const uint64_t b= LD64(pixels+line_size);\
  302. OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  303. pixels+=line_size;\
  304. block +=line_size;\
  305. }\
  306. }\
  307. \
  308. static void OPNAME ## _pixels_y2(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  309. {\
  310. int i;\
  311. for(i=0; i<h; i++){\
  312. const uint64_t a= LD64(pixels );\
  313. const uint64_t b= LD64(pixels+line_size);\
  314. OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  315. pixels+=line_size;\
  316. block +=line_size;\
  317. }\
  318. }\
  319. \
  320. static void OPNAME ## _pixels_xy2(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  321. {\
  322. int i;\
  323. const uint64_t a= LD64(pixels );\
  324. const uint64_t b= LD64(pixels+1);\
  325. uint64_t l0= (a&0x0303030303030303ULL)\
  326. + (b&0x0303030303030303ULL)\
  327. + 0x0202020202020202ULL;\
  328. uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  329. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  330. uint64_t l1,h1;\
  331. \
  332. pixels+=line_size;\
  333. for(i=0; i<h; i+=2){\
  334. uint64_t a= LD64(pixels );\
  335. uint64_t b= LD64(pixels+1);\
  336. l1= (a&0x0303030303030303ULL)\
  337. + (b&0x0303030303030303ULL);\
  338. h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  339. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  340. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  341. pixels+=line_size;\
  342. block +=line_size;\
  343. a= LD64(pixels );\
  344. b= LD64(pixels+1);\
  345. l0= (a&0x0303030303030303ULL)\
  346. + (b&0x0303030303030303ULL)\
  347. + 0x0202020202020202ULL;\
  348. h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  349. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  350. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  351. pixels+=line_size;\
  352. block +=line_size;\
  353. }\
  354. }\
  355. \
  356. static void OPNAME ## _no_rnd_pixels_xy2(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  357. {\
  358. int i;\
  359. const uint64_t a= LD64(pixels );\
  360. const uint64_t b= LD64(pixels+1);\
  361. uint64_t l0= (a&0x0303030303030303ULL)\
  362. + (b&0x0303030303030303ULL)\
  363. + 0x0101010101010101ULL;\
  364. uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  365. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  366. uint64_t l1,h1;\
  367. \
  368. pixels+=line_size;\
  369. for(i=0; i<h; i+=2){\
  370. uint64_t a= LD64(pixels );\
  371. uint64_t b= LD64(pixels+1);\
  372. l1= (a&0x0303030303030303ULL)\
  373. + (b&0x0303030303030303ULL);\
  374. h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  375. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  376. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  377. pixels+=line_size;\
  378. block +=line_size;\
  379. a= LD64(pixels );\
  380. b= LD64(pixels+1);\
  381. l0= (a&0x0303030303030303ULL)\
  382. + (b&0x0303030303030303ULL)\
  383. + 0x0101010101010101ULL;\
  384. h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  385. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  386. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  387. pixels+=line_size;\
  388. block +=line_size;\
  389. }\
  390. }\
  391. \
  392. CALL_2X_PIXELS(OPNAME ## _pixels16 , OPNAME ## _pixels , 8)\
  393. CALL_2X_PIXELS(OPNAME ## _pixels16_x2 , OPNAME ## _pixels_x2 , 8)\
  394. CALL_2X_PIXELS(OPNAME ## _pixels16_y2 , OPNAME ## _pixels_y2 , 8)\
  395. CALL_2X_PIXELS(OPNAME ## _pixels16_xy2, OPNAME ## _pixels_xy2, 8)\
  396. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2 , OPNAME ## _no_rnd_pixels_x2 , 8)\
  397. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2 , OPNAME ## _no_rnd_pixels_y2 , 8)\
  398. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2, OPNAME ## _no_rnd_pixels_xy2, 8)\
  399. \
  400. void (*OPNAME ## _pixels_tab[2][4])(uint8_t *block, const uint8_t *pixels, int line_size, int h) = {\
  401. {\
  402. OPNAME ## _pixels,\
  403. OPNAME ## _pixels_x2,\
  404. OPNAME ## _pixels_y2,\
  405. OPNAME ## _pixels_xy2},\
  406. {\
  407. OPNAME ## _pixels16,\
  408. OPNAME ## _pixels16_x2,\
  409. OPNAME ## _pixels16_y2,\
  410. OPNAME ## _pixels16_xy2}\
  411. };\
  412. \
  413. void (*OPNAME ## _no_rnd_pixels_tab[2][4])(uint8_t *block, const uint8_t *pixels, int line_size, int h) = {\
  414. {\
  415. OPNAME ## _pixels,\
  416. OPNAME ## _no_rnd_pixels_x2,\
  417. OPNAME ## _no_rnd_pixels_y2,\
  418. OPNAME ## _no_rnd_pixels_xy2},\
  419. {\
  420. OPNAME ## _pixels16,\
  421. OPNAME ## _no_rnd_pixels16_x2,\
  422. OPNAME ## _no_rnd_pixels16_y2,\
  423. OPNAME ## _no_rnd_pixels16_xy2}\
  424. };
  425. #define op_avg(a, b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEFEFEFEFEULL)>>1) )
  426. #else // 64 bit variant
  427. #define PIXOP2(OPNAME, OP) \
  428. static void OPNAME ## _pixels8(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  429. int i;\
  430. for(i=0; i<h; i++){\
  431. OP(*((uint32_t*)(block )), LD32(pixels ));\
  432. OP(*((uint32_t*)(block+4)), LD32(pixels+4));\
  433. pixels+=line_size;\
  434. block +=line_size;\
  435. }\
  436. }\
  437. static inline void OPNAME ## _no_rnd_pixels8(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  438. OPNAME ## _pixels8(block, pixels, line_size, h);\
  439. }\
  440. \
  441. static inline void OPNAME ## _no_rnd_pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  442. int src_stride1, int src_stride2, int h){\
  443. int i;\
  444. for(i=0; i<h; i++){\
  445. uint32_t a,b;\
  446. a= LD32(&src1[i*src_stride1 ]);\
  447. b= LD32(&src2[i*src_stride2 ]);\
  448. OP(*((uint32_t*)&dst[i*dst_stride ]), (a&b) + (((a^b)&0xFEFEFEFEUL)>>1));\
  449. a= LD32(&src1[i*src_stride1+4]);\
  450. b= LD32(&src2[i*src_stride2+4]);\
  451. OP(*((uint32_t*)&dst[i*dst_stride+4]), (a&b) + (((a^b)&0xFEFEFEFEUL)>>1));\
  452. }\
  453. }\
  454. \
  455. static inline void OPNAME ## _pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  456. int src_stride1, int src_stride2, int h){\
  457. int i;\
  458. for(i=0; i<h; i++){\
  459. uint32_t a,b;\
  460. a= LD32(&src1[i*src_stride1 ]);\
  461. b= LD32(&src2[i*src_stride2 ]);\
  462. OP(*((uint32_t*)&dst[i*dst_stride ]), (a|b) - (((a^b)&0xFEFEFEFEUL)>>1));\
  463. a= LD32(&src1[i*src_stride1+4]);\
  464. b= LD32(&src2[i*src_stride2+4]);\
  465. OP(*((uint32_t*)&dst[i*dst_stride+4]), (a|b) - (((a^b)&0xFEFEFEFEUL)>>1));\
  466. }\
  467. }\
  468. \
  469. static inline void OPNAME ## _pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  470. int src_stride1, int src_stride2, int h){\
  471. OPNAME ## _pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
  472. OPNAME ## _pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
  473. }\
  474. \
  475. static inline void OPNAME ## _no_rnd_pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
  476. int src_stride1, int src_stride2, int h){\
  477. OPNAME ## _no_rnd_pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
  478. OPNAME ## _no_rnd_pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
  479. }\
  480. \
  481. static inline void OPNAME ## _no_rnd_pixels8_x2(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  482. OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
  483. }\
  484. \
  485. static inline void OPNAME ## _pixels8_x2(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  486. OPNAME ## _pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
  487. }\
  488. \
  489. static inline void OPNAME ## _no_rnd_pixels8_y2(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  490. OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
  491. }\
  492. \
  493. static inline void OPNAME ## _pixels8_y2(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
  494. OPNAME ## _pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
  495. }\
  496. \
  497. static inline void OPNAME ## _pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
  498. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  499. int i;\
  500. for(i=0; i<h; i++){\
  501. uint32_t a, b, c, d, l0, l1, h0, h1;\
  502. a= LD32(&src1[i*src_stride1]);\
  503. b= LD32(&src2[i*src_stride2]);\
  504. c= LD32(&src3[i*src_stride3]);\
  505. d= LD32(&src4[i*src_stride4]);\
  506. l0= (a&0x03030303UL)\
  507. + (b&0x03030303UL)\
  508. + 0x02020202UL;\
  509. h0= ((a&0xFCFCFCFCUL)>>2)\
  510. + ((b&0xFCFCFCFCUL)>>2);\
  511. l1= (c&0x03030303UL)\
  512. + (d&0x03030303UL);\
  513. h1= ((c&0xFCFCFCFCUL)>>2)\
  514. + ((d&0xFCFCFCFCUL)>>2);\
  515. OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  516. a= LD32(&src1[i*src_stride1+4]);\
  517. b= LD32(&src2[i*src_stride2+4]);\
  518. c= LD32(&src3[i*src_stride3+4]);\
  519. d= LD32(&src4[i*src_stride4+4]);\
  520. l0= (a&0x03030303UL)\
  521. + (b&0x03030303UL)\
  522. + 0x02020202UL;\
  523. h0= ((a&0xFCFCFCFCUL)>>2)\
  524. + ((b&0xFCFCFCFCUL)>>2);\
  525. l1= (c&0x03030303UL)\
  526. + (d&0x03030303UL);\
  527. h1= ((c&0xFCFCFCFCUL)>>2)\
  528. + ((d&0xFCFCFCFCUL)>>2);\
  529. OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  530. }\
  531. }\
  532. static inline void OPNAME ## _no_rnd_pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
  533. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  534. int i;\
  535. for(i=0; i<h; i++){\
  536. uint32_t a, b, c, d, l0, l1, h0, h1;\
  537. a= LD32(&src1[i*src_stride1]);\
  538. b= LD32(&src2[i*src_stride2]);\
  539. c= LD32(&src3[i*src_stride3]);\
  540. d= LD32(&src4[i*src_stride4]);\
  541. l0= (a&0x03030303UL)\
  542. + (b&0x03030303UL)\
  543. + 0x01010101UL;\
  544. h0= ((a&0xFCFCFCFCUL)>>2)\
  545. + ((b&0xFCFCFCFCUL)>>2);\
  546. l1= (c&0x03030303UL)\
  547. + (d&0x03030303UL);\
  548. h1= ((c&0xFCFCFCFCUL)>>2)\
  549. + ((d&0xFCFCFCFCUL)>>2);\
  550. OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  551. a= LD32(&src1[i*src_stride1+4]);\
  552. b= LD32(&src2[i*src_stride2+4]);\
  553. c= LD32(&src3[i*src_stride3+4]);\
  554. d= LD32(&src4[i*src_stride4+4]);\
  555. l0= (a&0x03030303UL)\
  556. + (b&0x03030303UL)\
  557. + 0x01010101UL;\
  558. h0= ((a&0xFCFCFCFCUL)>>2)\
  559. + ((b&0xFCFCFCFCUL)>>2);\
  560. l1= (c&0x03030303UL)\
  561. + (d&0x03030303UL);\
  562. h1= ((c&0xFCFCFCFCUL)>>2)\
  563. + ((d&0xFCFCFCFCUL)>>2);\
  564. OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  565. }\
  566. }\
  567. static inline void OPNAME ## _pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
  568. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  569. OPNAME ## _pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  570. OPNAME ## _pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  571. }\
  572. static inline void OPNAME ## _no_rnd_pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
  573. int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
  574. OPNAME ## _no_rnd_pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
  575. 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);\
  576. }\
  577. \
  578. static inline void OPNAME ## _pixels8_xy2(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  579. {\
  580. int j;\
  581. for(j=0; j<2; j++){\
  582. int i;\
  583. const uint32_t a= LD32(pixels );\
  584. const uint32_t b= LD32(pixels+1);\
  585. uint32_t l0= (a&0x03030303UL)\
  586. + (b&0x03030303UL)\
  587. + 0x02020202UL;\
  588. uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
  589. + ((b&0xFCFCFCFCUL)>>2);\
  590. uint32_t l1,h1;\
  591. \
  592. pixels+=line_size;\
  593. for(i=0; i<h; i+=2){\
  594. uint32_t a= LD32(pixels );\
  595. uint32_t b= LD32(pixels+1);\
  596. l1= (a&0x03030303UL)\
  597. + (b&0x03030303UL);\
  598. h1= ((a&0xFCFCFCFCUL)>>2)\
  599. + ((b&0xFCFCFCFCUL)>>2);\
  600. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  601. pixels+=line_size;\
  602. block +=line_size;\
  603. a= LD32(pixels );\
  604. b= LD32(pixels+1);\
  605. l0= (a&0x03030303UL)\
  606. + (b&0x03030303UL)\
  607. + 0x02020202UL;\
  608. h0= ((a&0xFCFCFCFCUL)>>2)\
  609. + ((b&0xFCFCFCFCUL)>>2);\
  610. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  611. pixels+=line_size;\
  612. block +=line_size;\
  613. }\
  614. pixels+=4-line_size*(h+1);\
  615. block +=4-line_size*h;\
  616. }\
  617. }\
  618. \
  619. static inline void OPNAME ## _no_rnd_pixels8_xy2(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  620. {\
  621. int j;\
  622. for(j=0; j<2; j++){\
  623. int i;\
  624. const uint32_t a= LD32(pixels );\
  625. const uint32_t b= LD32(pixels+1);\
  626. uint32_t l0= (a&0x03030303UL)\
  627. + (b&0x03030303UL)\
  628. + 0x01010101UL;\
  629. uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
  630. + ((b&0xFCFCFCFCUL)>>2);\
  631. uint32_t l1,h1;\
  632. \
  633. pixels+=line_size;\
  634. for(i=0; i<h; i+=2){\
  635. uint32_t a= LD32(pixels );\
  636. uint32_t b= LD32(pixels+1);\
  637. l1= (a&0x03030303UL)\
  638. + (b&0x03030303UL);\
  639. h1= ((a&0xFCFCFCFCUL)>>2)\
  640. + ((b&0xFCFCFCFCUL)>>2);\
  641. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  642. pixels+=line_size;\
  643. block +=line_size;\
  644. a= LD32(pixels );\
  645. b= LD32(pixels+1);\
  646. l0= (a&0x03030303UL)\
  647. + (b&0x03030303UL)\
  648. + 0x01010101UL;\
  649. h0= ((a&0xFCFCFCFCUL)>>2)\
  650. + ((b&0xFCFCFCFCUL)>>2);\
  651. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  652. pixels+=line_size;\
  653. block +=line_size;\
  654. }\
  655. pixels+=4-line_size*(h+1);\
  656. block +=4-line_size*h;\
  657. }\
  658. }\
  659. \
  660. CALL_2X_PIXELS(OPNAME ## _pixels16 , OPNAME ## _pixels8 , 8)\
  661. CALL_2X_PIXELS(OPNAME ## _pixels16_x2 , OPNAME ## _pixels8_x2 , 8)\
  662. CALL_2X_PIXELS(OPNAME ## _pixels16_y2 , OPNAME ## _pixels8_y2 , 8)\
  663. CALL_2X_PIXELS(OPNAME ## _pixels16_xy2, OPNAME ## _pixels8_xy2, 8)\
  664. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16 , OPNAME ## _pixels8 , 8)\
  665. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2 , OPNAME ## _no_rnd_pixels8_x2 , 8)\
  666. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2 , OPNAME ## _no_rnd_pixels8_y2 , 8)\
  667. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2, OPNAME ## _no_rnd_pixels8_xy2, 8)\
  668. \
  669. void (*OPNAME ## _pixels_tab[2][4])(uint8_t *block, const uint8_t *pixels, int line_size, int h) = {\
  670. {\
  671. OPNAME ## _pixels16,\
  672. OPNAME ## _pixels16_x2,\
  673. OPNAME ## _pixels16_y2,\
  674. OPNAME ## _pixels16_xy2},\
  675. {\
  676. OPNAME ## _pixels8,\
  677. OPNAME ## _pixels8_x2,\
  678. OPNAME ## _pixels8_y2,\
  679. OPNAME ## _pixels8_xy2},\
  680. };\
  681. \
  682. void (*OPNAME ## _no_rnd_pixels_tab[2][4])(uint8_t *block, const uint8_t *pixels, int line_size, int h) = {\
  683. {\
  684. OPNAME ## _pixels16,\
  685. OPNAME ## _no_rnd_pixels16_x2,\
  686. OPNAME ## _no_rnd_pixels16_y2,\
  687. OPNAME ## _no_rnd_pixels16_xy2},\
  688. {\
  689. OPNAME ## _pixels8,\
  690. OPNAME ## _no_rnd_pixels8_x2,\
  691. OPNAME ## _no_rnd_pixels8_y2,\
  692. OPNAME ## _no_rnd_pixels8_xy2},\
  693. };
  694. #define op_avg(a, b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEUL)>>1) )
  695. #endif
  696. #define op_put(a, b) a = b
  697. PIXOP2(avg, op_avg)
  698. PIXOP2(put, op_put)
  699. #undef op_avg
  700. #undef op_put
  701. #if 0
  702. /* FIXME this stuff could be removed as its ot really used anymore */
  703. #define PIXOP(BTYPE, OPNAME, OP, INCR) \
  704. \
  705. static void OPNAME ## _pixels(BTYPE *block, const UINT8 *pixels, int line_size, int h) \
  706. { \
  707. BTYPE *p; \
  708. const UINT8 *pix; \
  709. \
  710. p = block; \
  711. pix = pixels; \
  712. do { \
  713. OP(p[0], pix[0]); \
  714. OP(p[1], pix[1]); \
  715. OP(p[2], pix[2]); \
  716. OP(p[3], pix[3]); \
  717. OP(p[4], pix[4]); \
  718. OP(p[5], pix[5]); \
  719. OP(p[6], pix[6]); \
  720. OP(p[7], pix[7]); \
  721. pix += line_size; \
  722. p += INCR; \
  723. } while (--h);; \
  724. } \
  725. \
  726. static void OPNAME ## _pixels_x2(BTYPE *block, const UINT8 *pixels, int line_size, int h) \
  727. { \
  728. BTYPE *p; \
  729. const UINT8 *pix; \
  730. \
  731. p = block; \
  732. pix = pixels; \
  733. do { \
  734. OP(p[0], avg2(pix[0], pix[1])); \
  735. OP(p[1], avg2(pix[1], pix[2])); \
  736. OP(p[2], avg2(pix[2], pix[3])); \
  737. OP(p[3], avg2(pix[3], pix[4])); \
  738. OP(p[4], avg2(pix[4], pix[5])); \
  739. OP(p[5], avg2(pix[5], pix[6])); \
  740. OP(p[6], avg2(pix[6], pix[7])); \
  741. OP(p[7], avg2(pix[7], pix[8])); \
  742. pix += line_size; \
  743. p += INCR; \
  744. } while (--h); \
  745. } \
  746. \
  747. static void OPNAME ## _pixels_y2(BTYPE *block, const UINT8 *pixels, int line_size, int h) \
  748. { \
  749. BTYPE *p; \
  750. const UINT8 *pix; \
  751. const UINT8 *pix1; \
  752. \
  753. p = block; \
  754. pix = pixels; \
  755. pix1 = pixels + line_size; \
  756. do { \
  757. OP(p[0], avg2(pix[0], pix1[0])); \
  758. OP(p[1], avg2(pix[1], pix1[1])); \
  759. OP(p[2], avg2(pix[2], pix1[2])); \
  760. OP(p[3], avg2(pix[3], pix1[3])); \
  761. OP(p[4], avg2(pix[4], pix1[4])); \
  762. OP(p[5], avg2(pix[5], pix1[5])); \
  763. OP(p[6], avg2(pix[6], pix1[6])); \
  764. OP(p[7], avg2(pix[7], pix1[7])); \
  765. pix += line_size; \
  766. pix1 += line_size; \
  767. p += INCR; \
  768. } while(--h); \
  769. } \
  770. \
  771. static void OPNAME ## _pixels_xy2(BTYPE *block, const UINT8 *pixels, int line_size, int h) \
  772. { \
  773. BTYPE *p; \
  774. const UINT8 *pix; \
  775. const UINT8 *pix1; \
  776. \
  777. p = block; \
  778. pix = pixels; \
  779. pix1 = pixels + line_size; \
  780. do { \
  781. OP(p[0], avg4(pix[0], pix[1], pix1[0], pix1[1])); \
  782. OP(p[1], avg4(pix[1], pix[2], pix1[1], pix1[2])); \
  783. OP(p[2], avg4(pix[2], pix[3], pix1[2], pix1[3])); \
  784. OP(p[3], avg4(pix[3], pix[4], pix1[3], pix1[4])); \
  785. OP(p[4], avg4(pix[4], pix[5], pix1[4], pix1[5])); \
  786. OP(p[5], avg4(pix[5], pix[6], pix1[5], pix1[6])); \
  787. OP(p[6], avg4(pix[6], pix[7], pix1[6], pix1[7])); \
  788. OP(p[7], avg4(pix[7], pix[8], pix1[7], pix1[8])); \
  789. pix += line_size; \
  790. pix1 += line_size; \
  791. p += INCR; \
  792. } while(--h); \
  793. } \
  794. \
  795. void (*OPNAME ## _pixels_tab[4])(BTYPE *block, const UINT8 *pixels, int line_size, int h) = { \
  796. OPNAME ## _pixels, \
  797. OPNAME ## _pixels_x2, \
  798. OPNAME ## _pixels_y2, \
  799. OPNAME ## _pixels_xy2, \
  800. };
  801. /* rounding primitives */
  802. #define avg2(a,b) ((a+b+1)>>1)
  803. #define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
  804. #define op_avg(a, b) a = avg2(a, b)
  805. #define op_sub(a, b) a -= b
  806. #define op_put(a, b) a = b
  807. PIXOP(DCTELEM, sub, op_sub, 8)
  808. PIXOP(uint8_t, avg, op_avg, line_size)
  809. PIXOP(uint8_t, put, op_put, line_size)
  810. /* not rounding primitives */
  811. #undef avg2
  812. #undef avg4
  813. #define avg2(a,b) ((a+b)>>1)
  814. #define avg4(a,b,c,d) ((a+b+c+d+1)>>2)
  815. PIXOP(uint8_t, avg_no_rnd, op_avg, line_size)
  816. PIXOP(uint8_t, put_no_rnd, op_put, line_size)
  817. /* motion estimation */
  818. #undef avg2
  819. #undef avg4
  820. #endif
  821. #define avg2(a,b) ((a+b+1)>>1)
  822. #define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
  823. static void gmc1_c(UINT8 *dst, UINT8 *src, int stride, int h, int x16, int y16, int rounder)
  824. {
  825. const int A=(16-x16)*(16-y16);
  826. const int B=( x16)*(16-y16);
  827. const int C=(16-x16)*( y16);
  828. const int D=( x16)*( y16);
  829. int i;
  830. rounder= 128 - rounder;
  831. for(i=0; i<h; i++)
  832. {
  833. dst[0]= (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + rounder)>>8;
  834. dst[1]= (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + rounder)>>8;
  835. dst[2]= (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + rounder)>>8;
  836. dst[3]= (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + rounder)>>8;
  837. dst[4]= (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + rounder)>>8;
  838. dst[5]= (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + rounder)>>8;
  839. dst[6]= (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + rounder)>>8;
  840. dst[7]= (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + rounder)>>8;
  841. dst+= stride;
  842. src+= stride;
  843. }
  844. }
  845. static inline void copy_block17(UINT8 *dst, UINT8 *src, int dstStride, int srcStride, int h)
  846. {
  847. int i;
  848. for(i=0; i<h; i++)
  849. {
  850. ST32(dst , LD32(src ));
  851. ST32(dst+4 , LD32(src+4 ));
  852. ST32(dst+8 , LD32(src+8 ));
  853. ST32(dst+12, LD32(src+12));
  854. dst[16]= src[16];
  855. dst+=dstStride;
  856. src+=srcStride;
  857. }
  858. }
  859. static inline void copy_block9(UINT8 *dst, UINT8 *src, int dstStride, int srcStride, int h)
  860. {
  861. int i;
  862. for(i=0; i<h; i++)
  863. {
  864. ST32(dst , LD32(src ));
  865. ST32(dst+4 , LD32(src+4 ));
  866. dst[8]= src[8];
  867. dst+=dstStride;
  868. src+=srcStride;
  869. }
  870. }
  871. #define QPEL_MC(r, OPNAME, RND, OP) \
  872. static void OPNAME ## mpeg4_qpel8_h_lowpass(UINT8 *dst, UINT8 *src, int dstStride, int srcStride, int h){\
  873. UINT8 *cm = cropTbl + MAX_NEG_CROP;\
  874. int i;\
  875. for(i=0; i<h; i++)\
  876. {\
  877. OP(dst[0], (src[0]+src[1])*20 - (src[0]+src[2])*6 + (src[1]+src[3])*3 - (src[2]+src[4]));\
  878. OP(dst[1], (src[1]+src[2])*20 - (src[0]+src[3])*6 + (src[0]+src[4])*3 - (src[1]+src[5]));\
  879. OP(dst[2], (src[2]+src[3])*20 - (src[1]+src[4])*6 + (src[0]+src[5])*3 - (src[0]+src[6]));\
  880. OP(dst[3], (src[3]+src[4])*20 - (src[2]+src[5])*6 + (src[1]+src[6])*3 - (src[0]+src[7]));\
  881. OP(dst[4], (src[4]+src[5])*20 - (src[3]+src[6])*6 + (src[2]+src[7])*3 - (src[1]+src[8]));\
  882. OP(dst[5], (src[5]+src[6])*20 - (src[4]+src[7])*6 + (src[3]+src[8])*3 - (src[2]+src[8]));\
  883. OP(dst[6], (src[6]+src[7])*20 - (src[5]+src[8])*6 + (src[4]+src[8])*3 - (src[3]+src[7]));\
  884. OP(dst[7], (src[7]+src[8])*20 - (src[6]+src[8])*6 + (src[5]+src[7])*3 - (src[4]+src[6]));\
  885. dst+=dstStride;\
  886. src+=srcStride;\
  887. }\
  888. }\
  889. \
  890. static void OPNAME ## mpeg4_qpel8_v_lowpass(UINT8 *dst, UINT8 *src, int dstStride, int srcStride, int w){\
  891. UINT8 *cm = cropTbl + MAX_NEG_CROP;\
  892. int i;\
  893. for(i=0; i<w; i++)\
  894. {\
  895. const int src0= src[0*srcStride];\
  896. const int src1= src[1*srcStride];\
  897. const int src2= src[2*srcStride];\
  898. const int src3= src[3*srcStride];\
  899. const int src4= src[4*srcStride];\
  900. const int src5= src[5*srcStride];\
  901. const int src6= src[6*srcStride];\
  902. const int src7= src[7*srcStride];\
  903. const int src8= src[8*srcStride];\
  904. OP(dst[0*dstStride], (src0+src1)*20 - (src0+src2)*6 + (src1+src3)*3 - (src2+src4));\
  905. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*6 + (src0+src4)*3 - (src1+src5));\
  906. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*6 + (src0+src5)*3 - (src0+src6));\
  907. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*6 + (src1+src6)*3 - (src0+src7));\
  908. OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*6 + (src2+src7)*3 - (src1+src8));\
  909. OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*6 + (src3+src8)*3 - (src2+src8));\
  910. OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*6 + (src4+src8)*3 - (src3+src7));\
  911. OP(dst[7*dstStride], (src7+src8)*20 - (src6+src8)*6 + (src5+src7)*3 - (src4+src6));\
  912. dst++;\
  913. src++;\
  914. }\
  915. }\
  916. \
  917. static void OPNAME ## mpeg4_qpel16_h_lowpass(UINT8 *dst, UINT8 *src, int dstStride, int srcStride, int h){\
  918. UINT8 *cm = cropTbl + MAX_NEG_CROP;\
  919. int i;\
  920. for(i=0; i<h; i++)\
  921. {\
  922. OP(dst[ 0], (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]));\
  923. OP(dst[ 1], (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]));\
  924. OP(dst[ 2], (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]));\
  925. OP(dst[ 3], (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]));\
  926. OP(dst[ 4], (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]));\
  927. OP(dst[ 5], (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]));\
  928. OP(dst[ 6], (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]));\
  929. OP(dst[ 7], (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]));\
  930. OP(dst[ 8], (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]));\
  931. OP(dst[ 9], (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]));\
  932. OP(dst[10], (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]));\
  933. OP(dst[11], (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]));\
  934. OP(dst[12], (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]));\
  935. OP(dst[13], (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]));\
  936. OP(dst[14], (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]));\
  937. OP(dst[15], (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]));\
  938. dst+=dstStride;\
  939. src+=srcStride;\
  940. }\
  941. }\
  942. \
  943. static void OPNAME ## mpeg4_qpel16_v_lowpass(UINT8 *dst, UINT8 *src, int dstStride, int srcStride, int w){\
  944. UINT8 *cm = cropTbl + MAX_NEG_CROP;\
  945. int i;\
  946. for(i=0; i<w; i++)\
  947. {\
  948. const int src0= src[0*srcStride];\
  949. const int src1= src[1*srcStride];\
  950. const int src2= src[2*srcStride];\
  951. const int src3= src[3*srcStride];\
  952. const int src4= src[4*srcStride];\
  953. const int src5= src[5*srcStride];\
  954. const int src6= src[6*srcStride];\
  955. const int src7= src[7*srcStride];\
  956. const int src8= src[8*srcStride];\
  957. const int src9= src[9*srcStride];\
  958. const int src10= src[10*srcStride];\
  959. const int src11= src[11*srcStride];\
  960. const int src12= src[12*srcStride];\
  961. const int src13= src[13*srcStride];\
  962. const int src14= src[14*srcStride];\
  963. const int src15= src[15*srcStride];\
  964. const int src16= src[16*srcStride];\
  965. OP(dst[ 0*dstStride], (src0 +src1 )*20 - (src0 +src2 )*6 + (src1 +src3 )*3 - (src2 +src4 ));\
  966. OP(dst[ 1*dstStride], (src1 +src2 )*20 - (src0 +src3 )*6 + (src0 +src4 )*3 - (src1 +src5 ));\
  967. OP(dst[ 2*dstStride], (src2 +src3 )*20 - (src1 +src4 )*6 + (src0 +src5 )*3 - (src0 +src6 ));\
  968. OP(dst[ 3*dstStride], (src3 +src4 )*20 - (src2 +src5 )*6 + (src1 +src6 )*3 - (src0 +src7 ));\
  969. OP(dst[ 4*dstStride], (src4 +src5 )*20 - (src3 +src6 )*6 + (src2 +src7 )*3 - (src1 +src8 ));\
  970. OP(dst[ 5*dstStride], (src5 +src6 )*20 - (src4 +src7 )*6 + (src3 +src8 )*3 - (src2 +src9 ));\
  971. OP(dst[ 6*dstStride], (src6 +src7 )*20 - (src5 +src8 )*6 + (src4 +src9 )*3 - (src3 +src10));\
  972. OP(dst[ 7*dstStride], (src7 +src8 )*20 - (src6 +src9 )*6 + (src5 +src10)*3 - (src4 +src11));\
  973. OP(dst[ 8*dstStride], (src8 +src9 )*20 - (src7 +src10)*6 + (src6 +src11)*3 - (src5 +src12));\
  974. OP(dst[ 9*dstStride], (src9 +src10)*20 - (src8 +src11)*6 + (src7 +src12)*3 - (src6 +src13));\
  975. OP(dst[10*dstStride], (src10+src11)*20 - (src9 +src12)*6 + (src8 +src13)*3 - (src7 +src14));\
  976. OP(dst[11*dstStride], (src11+src12)*20 - (src10+src13)*6 + (src9 +src14)*3 - (src8 +src15));\
  977. OP(dst[12*dstStride], (src12+src13)*20 - (src11+src14)*6 + (src10+src15)*3 - (src9 +src16));\
  978. OP(dst[13*dstStride], (src13+src14)*20 - (src12+src15)*6 + (src11+src16)*3 - (src10+src16));\
  979. OP(dst[14*dstStride], (src14+src15)*20 - (src13+src16)*6 + (src12+src16)*3 - (src11+src15));\
  980. OP(dst[15*dstStride], (src15+src16)*20 - (src14+src16)*6 + (src13+src15)*3 - (src12+src14));\
  981. dst++;\
  982. src++;\
  983. }\
  984. }\
  985. \
  986. static void OPNAME ## qpel8_mc00_c (UINT8 *dst, UINT8 *src, int stride){\
  987. OPNAME ## pixels8(dst, src, stride, 8);\
  988. }\
  989. \
  990. static void OPNAME ## qpel8_mc10_c(UINT8 *dst, UINT8 *src, int stride){\
  991. UINT8 half[64];\
  992. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  993. OPNAME ## pixels8_l2(dst, src, half, stride, stride, 8, 8);\
  994. }\
  995. \
  996. static void OPNAME ## qpel8_mc20_c(UINT8 *dst, UINT8 *src, int stride){\
  997. OPNAME ## mpeg4_qpel8_h_lowpass(dst, src, stride, stride, 8);\
  998. }\
  999. \
  1000. static void OPNAME ## qpel8_mc30_c(UINT8 *dst, UINT8 *src, int stride){\
  1001. UINT8 half[64];\
  1002. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  1003. OPNAME ## pixels8_l2(dst, src+1, half, stride, stride, 8, 8);\
  1004. }\
  1005. \
  1006. static void OPNAME ## qpel8_mc01_c(UINT8 *dst, UINT8 *src, int stride){\
  1007. UINT8 full[16*9];\
  1008. UINT8 half[64];\
  1009. copy_block9(full, src, 16, stride, 9);\
  1010. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16, 8);\
  1011. OPNAME ## pixels8_l2(dst, full, half, stride, 16, 8, 8);\
  1012. }\
  1013. \
  1014. static void OPNAME ## qpel8_mc02_c(UINT8 *dst, UINT8 *src, int stride){\
  1015. UINT8 full[16*9];\
  1016. copy_block9(full, src, 16, stride, 9);\
  1017. OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16, 8);\
  1018. }\
  1019. \
  1020. static void OPNAME ## qpel8_mc03_c(UINT8 *dst, UINT8 *src, int stride){\
  1021. UINT8 full[16*9];\
  1022. UINT8 half[64];\
  1023. copy_block9(full, src, 16, stride, 9);\
  1024. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16, 8);\
  1025. OPNAME ## pixels8_l2(dst, full+16, half, stride, 16, 8, 8);\
  1026. }\
  1027. static void OPNAME ## qpel8_mc11_c(UINT8 *dst, UINT8 *src, int stride){\
  1028. UINT8 full[16*9];\
  1029. UINT8 halfH[72];\
  1030. UINT8 halfV[64];\
  1031. UINT8 halfHV[64];\
  1032. copy_block9(full, src, 16, stride, 9);\
  1033. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1034. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16, 8);\
  1035. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
  1036. OPNAME ## pixels8_l4(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1037. }\
  1038. static void OPNAME ## qpel8_mc31_c(UINT8 *dst, UINT8 *src, int stride){\
  1039. UINT8 full[16*9];\
  1040. UINT8 halfH[72];\
  1041. UINT8 halfV[64];\
  1042. UINT8 halfHV[64];\
  1043. copy_block9(full, src, 16, stride, 9);\
  1044. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1045. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16, 8);\
  1046. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
  1047. OPNAME ## pixels8_l4(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1048. }\
  1049. static void OPNAME ## qpel8_mc13_c(UINT8 *dst, UINT8 *src, int stride){\
  1050. UINT8 full[16*9];\
  1051. UINT8 halfH[72];\
  1052. UINT8 halfV[64];\
  1053. UINT8 halfHV[64];\
  1054. copy_block9(full, src, 16, stride, 9);\
  1055. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1056. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16, 8);\
  1057. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
  1058. OPNAME ## pixels8_l4(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1059. }\
  1060. static void OPNAME ## qpel8_mc33_c(UINT8 *dst, UINT8 *src, int stride){\
  1061. UINT8 full[16*9];\
  1062. UINT8 halfH[72];\
  1063. UINT8 halfV[64];\
  1064. UINT8 halfHV[64];\
  1065. copy_block9(full, src, 16, stride, 9);\
  1066. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full , 8, 16, 9);\
  1067. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16, 8);\
  1068. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
  1069. OPNAME ## pixels8_l4(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1070. }\
  1071. static void OPNAME ## qpel8_mc21_c(UINT8 *dst, UINT8 *src, int stride){\
  1072. UINT8 halfH[72];\
  1073. UINT8 halfHV[64];\
  1074. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1075. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
  1076. OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
  1077. }\
  1078. static void OPNAME ## qpel8_mc23_c(UINT8 *dst, UINT8 *src, int stride){\
  1079. UINT8 halfH[72];\
  1080. UINT8 halfHV[64];\
  1081. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1082. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
  1083. OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  1084. }\
  1085. static void OPNAME ## qpel8_mc12_c(UINT8 *dst, UINT8 *src, int stride){\
  1086. UINT8 full[16*9];\
  1087. UINT8 halfH[72];\
  1088. UINT8 halfV[64];\
  1089. UINT8 halfHV[64];\
  1090. copy_block9(full, src, 16, stride, 9);\
  1091. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1092. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16, 8);\
  1093. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
  1094. OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
  1095. }\
  1096. static void OPNAME ## qpel8_mc32_c(UINT8 *dst, UINT8 *src, int stride){\
  1097. UINT8 full[16*9];\
  1098. UINT8 halfH[72];\
  1099. UINT8 halfV[64];\
  1100. UINT8 halfHV[64];\
  1101. copy_block9(full, src, 16, stride, 9);\
  1102. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1103. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16, 8);\
  1104. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
  1105. OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
  1106. }\
  1107. static void OPNAME ## qpel8_mc22_c(UINT8 *dst, UINT8 *src, int stride){\
  1108. UINT8 halfH[72];\
  1109. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1110. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8, 8);\
  1111. }\
  1112. static void OPNAME ## qpel16_mc00_c (UINT8 *dst, UINT8 *src, int stride){\
  1113. OPNAME ## pixels16(dst, src, stride, 16);\
  1114. }\
  1115. \
  1116. static void OPNAME ## qpel16_mc10_c(UINT8 *dst, UINT8 *src, int stride){\
  1117. UINT8 half[256];\
  1118. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  1119. OPNAME ## pixels16_l2(dst, src, half, stride, stride, 16, 16);\
  1120. }\
  1121. \
  1122. static void OPNAME ## qpel16_mc20_c(UINT8 *dst, UINT8 *src, int stride){\
  1123. OPNAME ## mpeg4_qpel16_h_lowpass(dst, src, stride, stride, 16);\
  1124. }\
  1125. \
  1126. static void OPNAME ## qpel16_mc30_c(UINT8 *dst, UINT8 *src, int stride){\
  1127. UINT8 half[256];\
  1128. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  1129. OPNAME ## pixels16_l2(dst, src+1, half, stride, stride, 16, 16);\
  1130. }\
  1131. \
  1132. static void OPNAME ## qpel16_mc01_c(UINT8 *dst, UINT8 *src, int stride){\
  1133. UINT8 full[24*17];\
  1134. UINT8 half[256];\
  1135. copy_block17(full, src, 24, stride, 17);\
  1136. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24, 16);\
  1137. OPNAME ## pixels16_l2(dst, full, half, stride, 24, 16, 16);\
  1138. }\
  1139. \
  1140. static void OPNAME ## qpel16_mc02_c(UINT8 *dst, UINT8 *src, int stride){\
  1141. UINT8 full[24*17];\
  1142. copy_block17(full, src, 24, stride, 17);\
  1143. OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24, 16);\
  1144. }\
  1145. \
  1146. static void OPNAME ## qpel16_mc03_c(UINT8 *dst, UINT8 *src, int stride){\
  1147. UINT8 full[24*17];\
  1148. UINT8 half[256];\
  1149. copy_block17(full, src, 24, stride, 17);\
  1150. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24, 16);\
  1151. OPNAME ## pixels16_l2(dst, full+24, half, stride, 24, 16, 16);\
  1152. }\
  1153. static void OPNAME ## qpel16_mc11_c(UINT8 *dst, UINT8 *src, int stride){\
  1154. UINT8 full[24*17];\
  1155. UINT8 halfH[272];\
  1156. UINT8 halfV[256];\
  1157. UINT8 halfHV[256];\
  1158. copy_block17(full, src, 24, stride, 17);\
  1159. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1160. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24, 16);\
  1161. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16, 16);\
  1162. OPNAME ## pixels16_l4(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1163. }\
  1164. static void OPNAME ## qpel16_mc31_c(UINT8 *dst, UINT8 *src, int stride){\
  1165. UINT8 full[24*17];\
  1166. UINT8 halfH[272];\
  1167. UINT8 halfV[256];\
  1168. UINT8 halfHV[256];\
  1169. copy_block17(full, src, 24, stride, 17);\
  1170. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1171. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24, 16);\
  1172. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16, 16);\
  1173. OPNAME ## pixels16_l4(dst, full+1, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1174. }\
  1175. static void OPNAME ## qpel16_mc13_c(UINT8 *dst, UINT8 *src, int stride){\
  1176. UINT8 full[24*17];\
  1177. UINT8 halfH[272];\
  1178. UINT8 halfV[256];\
  1179. UINT8 halfHV[256];\
  1180. copy_block17(full, src, 24, stride, 17);\
  1181. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1182. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24, 16);\
  1183. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16, 16);\
  1184. OPNAME ## pixels16_l4(dst, full+24, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1185. }\
  1186. static void OPNAME ## qpel16_mc33_c(UINT8 *dst, UINT8 *src, int stride){\
  1187. UINT8 full[24*17];\
  1188. UINT8 halfH[272];\
  1189. UINT8 halfV[256];\
  1190. UINT8 halfHV[256];\
  1191. copy_block17(full, src, 24, stride, 17);\
  1192. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full , 16, 24, 17);\
  1193. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24, 16);\
  1194. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16, 16);\
  1195. OPNAME ## pixels16_l4(dst, full+25, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1196. }\
  1197. static void OPNAME ## qpel16_mc21_c(UINT8 *dst, UINT8 *src, int stride){\
  1198. UINT8 halfH[272];\
  1199. UINT8 halfHV[256];\
  1200. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1201. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16, 16);\
  1202. OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
  1203. }\
  1204. static void OPNAME ## qpel16_mc23_c(UINT8 *dst, UINT8 *src, int stride){\
  1205. UINT8 halfH[272];\
  1206. UINT8 halfHV[256];\
  1207. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1208. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16, 16);\
  1209. OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1210. }\
  1211. static void OPNAME ## qpel16_mc12_c(UINT8 *dst, UINT8 *src, int stride){\
  1212. UINT8 full[24*17];\
  1213. UINT8 halfH[272];\
  1214. UINT8 halfV[256];\
  1215. UINT8 halfHV[256];\
  1216. copy_block17(full, src, 24, stride, 17);\
  1217. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1218. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24, 16);\
  1219. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16, 16);\
  1220. OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
  1221. }\
  1222. static void OPNAME ## qpel16_mc32_c(UINT8 *dst, UINT8 *src, int stride){\
  1223. UINT8 full[24*17];\
  1224. UINT8 halfH[272];\
  1225. UINT8 halfV[256];\
  1226. UINT8 halfHV[256];\
  1227. copy_block17(full, src, 24, stride, 17);\
  1228. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1229. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24, 16);\
  1230. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16, 16);\
  1231. OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
  1232. }\
  1233. static void OPNAME ## qpel16_mc22_c(UINT8 *dst, UINT8 *src, int stride){\
  1234. UINT8 halfH[272];\
  1235. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1236. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16, 16);\
  1237. }\
  1238. qpel_mc_func OPNAME ## qpel_pixels_tab[2][16]={ \
  1239. {\
  1240. OPNAME ## qpel16_mc00_c, \
  1241. OPNAME ## qpel16_mc10_c, \
  1242. OPNAME ## qpel16_mc20_c, \
  1243. OPNAME ## qpel16_mc30_c, \
  1244. OPNAME ## qpel16_mc01_c, \
  1245. OPNAME ## qpel16_mc11_c, \
  1246. OPNAME ## qpel16_mc21_c, \
  1247. OPNAME ## qpel16_mc31_c, \
  1248. OPNAME ## qpel16_mc02_c, \
  1249. OPNAME ## qpel16_mc12_c, \
  1250. OPNAME ## qpel16_mc22_c, \
  1251. OPNAME ## qpel16_mc32_c, \
  1252. OPNAME ## qpel16_mc03_c, \
  1253. OPNAME ## qpel16_mc13_c, \
  1254. OPNAME ## qpel16_mc23_c, \
  1255. OPNAME ## qpel16_mc33_c, \
  1256. },{\
  1257. OPNAME ## qpel8_mc00_c, \
  1258. OPNAME ## qpel8_mc10_c, \
  1259. OPNAME ## qpel8_mc20_c, \
  1260. OPNAME ## qpel8_mc30_c, \
  1261. OPNAME ## qpel8_mc01_c, \
  1262. OPNAME ## qpel8_mc11_c, \
  1263. OPNAME ## qpel8_mc21_c, \
  1264. OPNAME ## qpel8_mc31_c, \
  1265. OPNAME ## qpel8_mc02_c, \
  1266. OPNAME ## qpel8_mc12_c, \
  1267. OPNAME ## qpel8_mc22_c, \
  1268. OPNAME ## qpel8_mc32_c, \
  1269. OPNAME ## qpel8_mc03_c, \
  1270. OPNAME ## qpel8_mc13_c, \
  1271. OPNAME ## qpel8_mc23_c, \
  1272. OPNAME ## qpel8_mc33_c, \
  1273. }\
  1274. };
  1275. #define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
  1276. #define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1)
  1277. #define op_put(a, b) a = cm[((b) + 16)>>5]
  1278. #define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5]
  1279. QPEL_MC(0, put_ , _ , op_put)
  1280. QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd)
  1281. QPEL_MC(0, avg_ , _ , op_avg)
  1282. //QPEL_MC(1, avg_no_rnd , _ , op_avg)
  1283. #undef op_avg
  1284. #undef op_avg_no_rnd
  1285. #undef op_put
  1286. #undef op_put_no_rnd
  1287. int pix_abs16x16_c(UINT8 *pix1, UINT8 *pix2, int line_size)
  1288. {
  1289. int s, i;
  1290. s = 0;
  1291. for(i=0;i<16;i++) {
  1292. s += abs(pix1[0] - pix2[0]);
  1293. s += abs(pix1[1] - pix2[1]);
  1294. s += abs(pix1[2] - pix2[2]);
  1295. s += abs(pix1[3] - pix2[3]);
  1296. s += abs(pix1[4] - pix2[4]);
  1297. s += abs(pix1[5] - pix2[5]);
  1298. s += abs(pix1[6] - pix2[6]);
  1299. s += abs(pix1[7] - pix2[7]);
  1300. s += abs(pix1[8] - pix2[8]);
  1301. s += abs(pix1[9] - pix2[9]);
  1302. s += abs(pix1[10] - pix2[10]);
  1303. s += abs(pix1[11] - pix2[11]);
  1304. s += abs(pix1[12] - pix2[12]);
  1305. s += abs(pix1[13] - pix2[13]);
  1306. s += abs(pix1[14] - pix2[14]);
  1307. s += abs(pix1[15] - pix2[15]);
  1308. pix1 += line_size;
  1309. pix2 += line_size;
  1310. }
  1311. return s;
  1312. }
  1313. int pix_abs16x16_x2_c(UINT8 *pix1, UINT8 *pix2, int line_size)
  1314. {
  1315. int s, i;
  1316. s = 0;
  1317. for(i=0;i<16;i++) {
  1318. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  1319. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  1320. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  1321. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  1322. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  1323. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  1324. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  1325. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  1326. s += abs(pix1[8] - avg2(pix2[8], pix2[9]));
  1327. s += abs(pix1[9] - avg2(pix2[9], pix2[10]));
  1328. s += abs(pix1[10] - avg2(pix2[10], pix2[11]));
  1329. s += abs(pix1[11] - avg2(pix2[11], pix2[12]));
  1330. s += abs(pix1[12] - avg2(pix2[12], pix2[13]));
  1331. s += abs(pix1[13] - avg2(pix2[13], pix2[14]));
  1332. s += abs(pix1[14] - avg2(pix2[14], pix2[15]));
  1333. s += abs(pix1[15] - avg2(pix2[15], pix2[16]));
  1334. pix1 += line_size;
  1335. pix2 += line_size;
  1336. }
  1337. return s;
  1338. }
  1339. int pix_abs16x16_y2_c(UINT8 *pix1, UINT8 *pix2, int line_size)
  1340. {
  1341. int s, i;
  1342. UINT8 *pix3 = pix2 + line_size;
  1343. s = 0;
  1344. for(i=0;i<16;i++) {
  1345. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  1346. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  1347. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  1348. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  1349. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  1350. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  1351. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  1352. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  1353. s += abs(pix1[8] - avg2(pix2[8], pix3[8]));
  1354. s += abs(pix1[9] - avg2(pix2[9], pix3[9]));
  1355. s += abs(pix1[10] - avg2(pix2[10], pix3[10]));
  1356. s += abs(pix1[11] - avg2(pix2[11], pix3[11]));
  1357. s += abs(pix1[12] - avg2(pix2[12], pix3[12]));
  1358. s += abs(pix1[13] - avg2(pix2[13], pix3[13]));
  1359. s += abs(pix1[14] - avg2(pix2[14], pix3[14]));
  1360. s += abs(pix1[15] - avg2(pix2[15], pix3[15]));
  1361. pix1 += line_size;
  1362. pix2 += line_size;
  1363. pix3 += line_size;
  1364. }
  1365. return s;
  1366. }
  1367. int pix_abs16x16_xy2_c(UINT8 *pix1, UINT8 *pix2, int line_size)
  1368. {
  1369. int s, i;
  1370. UINT8 *pix3 = pix2 + line_size;
  1371. s = 0;
  1372. for(i=0;i<16;i++) {
  1373. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  1374. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  1375. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  1376. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  1377. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  1378. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  1379. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  1380. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  1381. s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9]));
  1382. s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10]));
  1383. s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11]));
  1384. s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12]));
  1385. s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13]));
  1386. s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14]));
  1387. s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15]));
  1388. s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16]));
  1389. pix1 += line_size;
  1390. pix2 += line_size;
  1391. pix3 += line_size;
  1392. }
  1393. return s;
  1394. }
  1395. int pix_abs8x8_c(UINT8 *pix1, UINT8 *pix2, int line_size)
  1396. {
  1397. int s, i;
  1398. s = 0;
  1399. for(i=0;i<8;i++) {
  1400. s += abs(pix1[0] - pix2[0]);
  1401. s += abs(pix1[1] - pix2[1]);
  1402. s += abs(pix1[2] - pix2[2]);
  1403. s += abs(pix1[3] - pix2[3]);
  1404. s += abs(pix1[4] - pix2[4]);
  1405. s += abs(pix1[5] - pix2[5]);
  1406. s += abs(pix1[6] - pix2[6]);
  1407. s += abs(pix1[7] - pix2[7]);
  1408. pix1 += line_size;
  1409. pix2 += line_size;
  1410. }
  1411. return s;
  1412. }
  1413. int pix_abs8x8_x2_c(UINT8 *pix1, UINT8 *pix2, int line_size)
  1414. {
  1415. int s, i;
  1416. s = 0;
  1417. for(i=0;i<8;i++) {
  1418. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  1419. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  1420. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  1421. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  1422. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  1423. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  1424. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  1425. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  1426. pix1 += line_size;
  1427. pix2 += line_size;
  1428. }
  1429. return s;
  1430. }
  1431. int pix_abs8x8_y2_c(UINT8 *pix1, UINT8 *pix2, int line_size)
  1432. {
  1433. int s, i;
  1434. UINT8 *pix3 = pix2 + line_size;
  1435. s = 0;
  1436. for(i=0;i<8;i++) {
  1437. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  1438. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  1439. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  1440. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  1441. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  1442. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  1443. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  1444. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  1445. pix1 += line_size;
  1446. pix2 += line_size;
  1447. pix3 += line_size;
  1448. }
  1449. return s;
  1450. }
  1451. int pix_abs8x8_xy2_c(UINT8 *pix1, UINT8 *pix2, int line_size)
  1452. {
  1453. int s, i;
  1454. UINT8 *pix3 = pix2 + line_size;
  1455. s = 0;
  1456. for(i=0;i<8;i++) {
  1457. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  1458. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  1459. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  1460. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  1461. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  1462. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  1463. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  1464. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  1465. pix1 += line_size;
  1466. pix2 += line_size;
  1467. pix3 += line_size;
  1468. }
  1469. return s;
  1470. }
  1471. /* permute block according so that it corresponds to the MMX idct
  1472. order */
  1473. #ifdef SIMPLE_IDCT
  1474. /* general permutation, but perhaps slightly slower */
  1475. void block_permute(INT16 *block)
  1476. {
  1477. int i;
  1478. INT16 temp[64];
  1479. for(i=0; i<64; i++) temp[ block_permute_op(i) ] = block[i];
  1480. for(i=0; i<64; i++) block[i] = temp[i];
  1481. }
  1482. #else
  1483. void block_permute(INT16 *block)
  1484. {
  1485. int tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;
  1486. int i;
  1487. for(i=0;i<8;i++) {
  1488. tmp1 = block[1];
  1489. tmp2 = block[2];
  1490. tmp3 = block[3];
  1491. tmp4 = block[4];
  1492. tmp5 = block[5];
  1493. tmp6 = block[6];
  1494. block[1] = tmp2;
  1495. block[2] = tmp4;
  1496. block[3] = tmp6;
  1497. block[4] = tmp1;
  1498. block[5] = tmp3;
  1499. block[6] = tmp5;
  1500. block += 8;
  1501. }
  1502. }
  1503. #endif
  1504. void clear_blocks_c(DCTELEM *blocks)
  1505. {
  1506. memset(blocks, 0, sizeof(DCTELEM)*6*64);
  1507. }
  1508. /* XXX: those functions should be suppressed ASAP when all IDCTs are
  1509. converted */
  1510. void gen_idct_put(UINT8 *dest, int line_size, DCTELEM *block)
  1511. {
  1512. ff_idct (block);
  1513. put_pixels_clamped(block, dest, line_size);
  1514. }
  1515. void gen_idct_add(UINT8 *dest, int line_size, DCTELEM *block)
  1516. {
  1517. ff_idct (block);
  1518. add_pixels_clamped(block, dest, line_size);
  1519. }
  1520. void dsputil_init(void)
  1521. {
  1522. int i, j;
  1523. int use_permuted_idct;
  1524. for(i=0;i<256;i++) cropTbl[i + MAX_NEG_CROP] = i;
  1525. for(i=0;i<MAX_NEG_CROP;i++) {
  1526. cropTbl[i] = 0;
  1527. cropTbl[i + MAX_NEG_CROP + 256] = 255;
  1528. }
  1529. for(i=0;i<512;i++) {
  1530. squareTbl[i] = (i - 256) * (i - 256);
  1531. }
  1532. #ifdef SIMPLE_IDCT
  1533. ff_idct = NULL;
  1534. #else
  1535. ff_idct = j_rev_dct;
  1536. #endif
  1537. get_pixels = get_pixels_c;
  1538. diff_pixels = diff_pixels_c;
  1539. put_pixels_clamped = put_pixels_clamped_c;
  1540. add_pixels_clamped = add_pixels_clamped_c;
  1541. gmc1= gmc1_c;
  1542. clear_blocks= clear_blocks_c;
  1543. pix_sum= pix_sum_c;
  1544. pix_norm1= pix_norm1_c;
  1545. pix_abs16x16 = pix_abs16x16_c;
  1546. pix_abs16x16_x2 = pix_abs16x16_x2_c;
  1547. pix_abs16x16_y2 = pix_abs16x16_y2_c;
  1548. pix_abs16x16_xy2 = pix_abs16x16_xy2_c;
  1549. pix_abs8x8 = pix_abs8x8_c;
  1550. pix_abs8x8_x2 = pix_abs8x8_x2_c;
  1551. pix_abs8x8_y2 = pix_abs8x8_y2_c;
  1552. pix_abs8x8_xy2 = pix_abs8x8_xy2_c;
  1553. use_permuted_idct = 1;
  1554. #ifdef HAVE_MMX
  1555. dsputil_init_mmx();
  1556. #endif
  1557. #ifdef ARCH_ARMV4L
  1558. dsputil_init_armv4l();
  1559. #endif
  1560. #ifdef HAVE_MLIB
  1561. dsputil_init_mlib();
  1562. use_permuted_idct = 0;
  1563. #endif
  1564. #ifdef ARCH_ALPHA
  1565. dsputil_init_alpha();
  1566. use_permuted_idct = 0;
  1567. #endif
  1568. #ifdef ARCH_POWERPC
  1569. dsputil_init_ppc();
  1570. #endif
  1571. #ifdef SIMPLE_IDCT
  1572. if (ff_idct == NULL) {
  1573. ff_idct_put = simple_idct_put;
  1574. ff_idct_add = simple_idct_add;
  1575. use_permuted_idct=0;
  1576. }
  1577. #endif
  1578. if(ff_idct != NULL) {
  1579. ff_idct_put = gen_idct_put;
  1580. ff_idct_add = gen_idct_add;
  1581. }
  1582. if(use_permuted_idct)
  1583. #ifdef SIMPLE_IDCT
  1584. for(i=0; i<64; i++) permutation[i]= simple_mmx_permutation[i];
  1585. #else
  1586. for(i=0; i<64; i++) permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
  1587. #endif
  1588. else
  1589. for(i=0; i<64; i++) permutation[i]=i;
  1590. for(i=0; i<64; i++) inv_zigzag_direct16[zigzag_direct[i]]= i+1;
  1591. for(i=0; i<64; i++) zigzag_direct_noperm[i]= zigzag_direct[i];
  1592. if (use_permuted_idct) {
  1593. /* permute for IDCT */
  1594. for(i=0;i<64;i++) {
  1595. j = zigzag_direct[i];
  1596. zigzag_direct[i] = block_permute_op(j);
  1597. j = ff_alternate_horizontal_scan[i];
  1598. ff_alternate_horizontal_scan[i] = block_permute_op(j);
  1599. j = ff_alternate_vertical_scan[i];
  1600. ff_alternate_vertical_scan[i] = block_permute_op(j);
  1601. }
  1602. block_permute(ff_mpeg1_default_intra_matrix);
  1603. block_permute(ff_mpeg1_default_non_intra_matrix);
  1604. block_permute(ff_mpeg4_default_intra_matrix);
  1605. block_permute(ff_mpeg4_default_non_intra_matrix);
  1606. }
  1607. build_zigzag_end();
  1608. }
  1609. /* remove any non bit exact operation (testing purpose) */
  1610. void avcodec_set_bit_exact(void)
  1611. {
  1612. #ifdef HAVE_MMX
  1613. dsputil_set_bit_exact_mmx();
  1614. #endif
  1615. }
  1616. void get_psnr(UINT8 *orig_image[3], UINT8 *coded_image[3],
  1617. int orig_linesize[3], int coded_linesize,
  1618. AVCodecContext *avctx)
  1619. {
  1620. int quad, diff, x, y;
  1621. UINT8 *orig, *coded;
  1622. UINT32 *sq = squareTbl + 256;
  1623. quad = 0;
  1624. diff = 0;
  1625. /* Luminance */
  1626. orig = orig_image[0];
  1627. coded = coded_image[0];
  1628. for (y=0;y<avctx->height;y++) {
  1629. for (x=0;x<avctx->width;x++) {
  1630. diff = *(orig + x) - *(coded + x);
  1631. quad += sq[diff];
  1632. }
  1633. orig += orig_linesize[0];
  1634. coded += coded_linesize;
  1635. }
  1636. avctx->psnr_y = (float) quad / (float) (avctx->width * avctx->height);
  1637. if (avctx->psnr_y) {
  1638. avctx->psnr_y = (float) (255 * 255) / avctx->psnr_y;
  1639. avctx->psnr_y = 10 * (float) log10 (avctx->psnr_y);
  1640. } else
  1641. avctx->psnr_y = 99.99;
  1642. }