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.

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