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.

1463 lines
43KB

  1. // Software scaling and colorspace conversion routines for MPlayer
  2. // Orginal C implementation by A'rpi/ESP-team <arpi@thot.banki.hu>
  3. // current version mostly by Michael Niedermayer (michaelni@gmx.at)
  4. // the parts written by michael are under GNU GPL
  5. #include <inttypes.h>
  6. #include <string.h>
  7. #include "../config.h"
  8. #include "swscale.h"
  9. #include "../mmx_defs.h"
  10. #undef MOVNTQ
  11. //#undef HAVE_MMX2
  12. //#undef HAVE_MMX
  13. //#undef ARCH_X86
  14. #define DITHER1XBPP
  15. int fullUVIpol=0;
  16. //disables the unscaled height version
  17. int allwaysIpol=0;
  18. #define RET 0xC3 //near return opcode
  19. /*
  20. NOTES
  21. known BUGS with known cause (no bugreports please!, but patches are welcome :) )
  22. horizontal MMX2 scaler reads 1-7 samples too much (might cause a sig11)
  23. Supported output formats BGR15 BGR16 BGR24 BGR32
  24. BGR15 & BGR16 MMX verions support dithering
  25. Special versions: fast Y 1:1 scaling (no interpolation in y direction)
  26. TODO
  27. more intelligent missalignment avoidance for the horizontal scaler
  28. */
  29. #define ABS(a) ((a) > 0 ? (a) : (-(a)))
  30. #define MIN(a,b) ((a) > (b) ? (b) : (a))
  31. #define MAX(a,b) ((a) < (b) ? (b) : (a))
  32. #ifdef HAVE_MMX2
  33. #define PAVGB(a,b) "pavgb " #a ", " #b " \n\t"
  34. #elif defined (HAVE_3DNOW)
  35. #define PAVGB(a,b) "pavgusb " #a ", " #b " \n\t"
  36. #endif
  37. #ifdef HAVE_MMX2
  38. #define MOVNTQ(a,b) "movntq " #a ", " #b " \n\t"
  39. #else
  40. #define MOVNTQ(a,b) "movq " #a ", " #b " \n\t"
  41. #endif
  42. #ifdef HAVE_MMX
  43. static uint64_t __attribute__((aligned(8))) yCoeff= 0x2568256825682568LL;
  44. static uint64_t __attribute__((aligned(8))) vrCoeff= 0x3343334333433343LL;
  45. static uint64_t __attribute__((aligned(8))) ubCoeff= 0x40cf40cf40cf40cfLL;
  46. static uint64_t __attribute__((aligned(8))) vgCoeff= 0xE5E2E5E2E5E2E5E2LL;
  47. static uint64_t __attribute__((aligned(8))) ugCoeff= 0xF36EF36EF36EF36ELL;
  48. static uint64_t __attribute__((aligned(8))) w400= 0x0400040004000400LL;
  49. static uint64_t __attribute__((aligned(8))) w80= 0x0080008000800080LL;
  50. static uint64_t __attribute__((aligned(8))) w10= 0x0010001000100010LL;
  51. static uint64_t __attribute__((aligned(8))) bm00001111=0x00000000FFFFFFFFLL;
  52. static uint64_t __attribute__((aligned(8))) bm00000111=0x0000000000FFFFFFLL;
  53. static uint64_t __attribute__((aligned(8))) bm11111000=0xFFFFFFFFFF000000LL;
  54. static uint64_t __attribute__((aligned(8))) b16Dither= 0x0004000400040004LL;
  55. static uint64_t __attribute__((aligned(8))) b16Dither1=0x0004000400040004LL;
  56. static uint64_t __attribute__((aligned(8))) b16Dither2=0x0602060206020602LL;
  57. static uint64_t __attribute__((aligned(8))) g16Dither= 0x0002000200020002LL;
  58. static uint64_t __attribute__((aligned(8))) g16Dither1=0x0002000200020002LL;
  59. static uint64_t __attribute__((aligned(8))) g16Dither2=0x0301030103010301LL;
  60. static uint64_t __attribute__((aligned(8))) b16Mask= 0x001F001F001F001FLL;
  61. static uint64_t __attribute__((aligned(8))) g16Mask= 0x07E007E007E007E0LL;
  62. static uint64_t __attribute__((aligned(8))) r16Mask= 0xF800F800F800F800LL;
  63. static uint64_t __attribute__((aligned(8))) b15Mask= 0x001F001F001F001FLL;
  64. static uint64_t __attribute__((aligned(8))) g15Mask= 0x03E003E003E003E0LL;
  65. static uint64_t __attribute__((aligned(8))) r15Mask= 0x7C007C007C007C00LL;
  66. static uint64_t __attribute__((aligned(8))) temp0;
  67. static uint64_t __attribute__((aligned(8))) asm_yalpha1;
  68. static uint64_t __attribute__((aligned(8))) asm_uvalpha1;
  69. #endif
  70. // temporary storage for 4 yuv lines:
  71. // 16bit for now (mmx likes it more compact)
  72. #ifdef HAVE_MMX
  73. static uint16_t __attribute__((aligned(8))) pix_buf_y[4][2048];
  74. static uint16_t __attribute__((aligned(8))) pix_buf_uv[2][2048*2];
  75. #else
  76. static uint16_t pix_buf_y[4][2048];
  77. static uint16_t pix_buf_uv[2][2048*2];
  78. #endif
  79. // clipping helper table for C implementations:
  80. static unsigned char clip_table[768];
  81. // yuv->rgb conversion tables:
  82. static int yuvtab_2568[256];
  83. static int yuvtab_3343[256];
  84. static int yuvtab_0c92[256];
  85. static int yuvtab_1a1e[256];
  86. static int yuvtab_40cf[256];
  87. static uint8_t funnyYCode[10000];
  88. static uint8_t funnyUVCode[10000];
  89. static int canMMX2BeUsed=0;
  90. #define FULL_YSCALEYUV2RGB \
  91. "pxor %%mm7, %%mm7 \n\t"\
  92. "movd %6, %%mm6 \n\t" /*yalpha1*/\
  93. "punpcklwd %%mm6, %%mm6 \n\t"\
  94. "punpcklwd %%mm6, %%mm6 \n\t"\
  95. "movd %7, %%mm5 \n\t" /*uvalpha1*/\
  96. "punpcklwd %%mm5, %%mm5 \n\t"\
  97. "punpcklwd %%mm5, %%mm5 \n\t"\
  98. "xorl %%eax, %%eax \n\t"\
  99. "1: \n\t"\
  100. "movq (%0, %%eax, 2), %%mm0 \n\t" /*buf0[eax]*/\
  101. "movq (%1, %%eax, 2), %%mm1 \n\t" /*buf1[eax]*/\
  102. "movq (%2, %%eax,2), %%mm2 \n\t" /* uvbuf0[eax]*/\
  103. "movq (%3, %%eax,2), %%mm3 \n\t" /* uvbuf1[eax]*/\
  104. "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\
  105. "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\
  106. "pmulhw %%mm6, %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
  107. "pmulhw %%mm5, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\
  108. "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  109. "movq 4096(%2, %%eax,2), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\
  110. "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
  111. "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
  112. "movq 4096(%3, %%eax,2), %%mm0 \n\t" /* uvbuf1[eax+2048]*/\
  113. "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\
  114. "psubw %%mm0, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\
  115. "psubw w80, %%mm1 \n\t" /* 8(Y-16)*/\
  116. "psubw w400, %%mm3 \n\t" /* 8(U-128)*/\
  117. "pmulhw yCoeff, %%mm1 \n\t"\
  118. \
  119. \
  120. "pmulhw %%mm5, %%mm4 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\
  121. "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
  122. "pmulhw ubCoeff, %%mm3 \n\t"\
  123. "psraw $4, %%mm0 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
  124. "pmulhw ugCoeff, %%mm2 \n\t"\
  125. "paddw %%mm4, %%mm0 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\
  126. "psubw w400, %%mm0 \n\t" /* (V-128)8*/\
  127. \
  128. \
  129. "movq %%mm0, %%mm4 \n\t" /* (V-128)8*/\
  130. "pmulhw vrCoeff, %%mm0 \n\t"\
  131. "pmulhw vgCoeff, %%mm4 \n\t"\
  132. "paddw %%mm1, %%mm3 \n\t" /* B*/\
  133. "paddw %%mm1, %%mm0 \n\t" /* R*/\
  134. "packuswb %%mm3, %%mm3 \n\t"\
  135. \
  136. "packuswb %%mm0, %%mm0 \n\t"\
  137. "paddw %%mm4, %%mm2 \n\t"\
  138. "paddw %%mm2, %%mm1 \n\t" /* G*/\
  139. \
  140. "packuswb %%mm1, %%mm1 \n\t"
  141. #define YSCALEYUV2RGB \
  142. "movd %6, %%mm6 \n\t" /*yalpha1*/\
  143. "punpcklwd %%mm6, %%mm6 \n\t"\
  144. "punpcklwd %%mm6, %%mm6 \n\t"\
  145. "movq %%mm6, asm_yalpha1 \n\t"\
  146. "movd %7, %%mm5 \n\t" /*uvalpha1*/\
  147. "punpcklwd %%mm5, %%mm5 \n\t"\
  148. "punpcklwd %%mm5, %%mm5 \n\t"\
  149. "movq %%mm5, asm_uvalpha1 \n\t"\
  150. "xorl %%eax, %%eax \n\t"\
  151. "1: \n\t"\
  152. "movq (%2, %%eax), %%mm2 \n\t" /* uvbuf0[eax]*/\
  153. "movq (%3, %%eax), %%mm3 \n\t" /* uvbuf1[eax]*/\
  154. "movq 4096(%2, %%eax), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
  155. "movq 4096(%3, %%eax), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
  156. "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\
  157. "psubw %%mm4, %%mm5 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\
  158. "movq asm_uvalpha1, %%mm0 \n\t"\
  159. "pmulhw %%mm0, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\
  160. "pmulhw %%mm0, %%mm5 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\
  161. "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
  162. "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
  163. "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\
  164. "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\
  165. "psubw w400, %%mm3 \n\t" /* (U-128)8*/\
  166. "psubw w400, %%mm4 \n\t" /* (V-128)8*/\
  167. "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
  168. "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
  169. "pmulhw ugCoeff, %%mm3 \n\t"\
  170. "pmulhw vgCoeff, %%mm4 \n\t"\
  171. /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
  172. "movq (%0, %%eax, 2), %%mm0 \n\t" /*buf0[eax]*/\
  173. "movq (%1, %%eax, 2), %%mm1 \n\t" /*buf1[eax]*/\
  174. "movq 8(%0, %%eax, 2), %%mm6 \n\t" /*buf0[eax]*/\
  175. "movq 8(%1, %%eax, 2), %%mm7 \n\t" /*buf1[eax]*/\
  176. "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\
  177. "psubw %%mm7, %%mm6 \n\t" /* buf0[eax] - buf1[eax]*/\
  178. "pmulhw asm_yalpha1, %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
  179. "pmulhw asm_yalpha1, %%mm6 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
  180. "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  181. "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  182. "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
  183. "paddw %%mm6, %%mm7 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
  184. "pmulhw ubCoeff, %%mm2 \n\t"\
  185. "pmulhw vrCoeff, %%mm5 \n\t"\
  186. "psubw w80, %%mm1 \n\t" /* 8(Y-16)*/\
  187. "psubw w80, %%mm7 \n\t" /* 8(Y-16)*/\
  188. "pmulhw yCoeff, %%mm1 \n\t"\
  189. "pmulhw yCoeff, %%mm7 \n\t"\
  190. /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
  191. "paddw %%mm3, %%mm4 \n\t"\
  192. "movq %%mm2, %%mm0 \n\t"\
  193. "movq %%mm5, %%mm6 \n\t"\
  194. "movq %%mm4, %%mm3 \n\t"\
  195. "punpcklwd %%mm2, %%mm2 \n\t"\
  196. "punpcklwd %%mm5, %%mm5 \n\t"\
  197. "punpcklwd %%mm4, %%mm4 \n\t"\
  198. "paddw %%mm1, %%mm2 \n\t"\
  199. "paddw %%mm1, %%mm5 \n\t"\
  200. "paddw %%mm1, %%mm4 \n\t"\
  201. "punpckhwd %%mm0, %%mm0 \n\t"\
  202. "punpckhwd %%mm6, %%mm6 \n\t"\
  203. "punpckhwd %%mm3, %%mm3 \n\t"\
  204. "paddw %%mm7, %%mm0 \n\t"\
  205. "paddw %%mm7, %%mm6 \n\t"\
  206. "paddw %%mm7, %%mm3 \n\t"\
  207. /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
  208. "packuswb %%mm0, %%mm2 \n\t"\
  209. "packuswb %%mm6, %%mm5 \n\t"\
  210. "packuswb %%mm3, %%mm4 \n\t"\
  211. "pxor %%mm7, %%mm7 \n\t"
  212. #define YSCALEYUV2RGB1 \
  213. "xorl %%eax, %%eax \n\t"\
  214. "1: \n\t"\
  215. "movq (%2, %%eax), %%mm3 \n\t" /* uvbuf0[eax]*/\
  216. "movq 4096(%2, %%eax), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\
  217. "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
  218. "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
  219. "psubw w400, %%mm3 \n\t" /* (U-128)8*/\
  220. "psubw w400, %%mm4 \n\t" /* (V-128)8*/\
  221. "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
  222. "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
  223. "pmulhw ugCoeff, %%mm3 \n\t"\
  224. "pmulhw vgCoeff, %%mm4 \n\t"\
  225. /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
  226. "movq (%1, %%eax, 2), %%mm1 \n\t" /*buf0[eax]*/\
  227. "movq 8(%1, %%eax, 2), %%mm7 \n\t" /*buf0[eax]*/\
  228. "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  229. "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
  230. "pmulhw ubCoeff, %%mm2 \n\t"\
  231. "pmulhw vrCoeff, %%mm5 \n\t"\
  232. "psubw w80, %%mm1 \n\t" /* 8(Y-16)*/\
  233. "psubw w80, %%mm7 \n\t" /* 8(Y-16)*/\
  234. "pmulhw yCoeff, %%mm1 \n\t"\
  235. "pmulhw yCoeff, %%mm7 \n\t"\
  236. /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
  237. "paddw %%mm3, %%mm4 \n\t"\
  238. "movq %%mm2, %%mm0 \n\t"\
  239. "movq %%mm5, %%mm6 \n\t"\
  240. "movq %%mm4, %%mm3 \n\t"\
  241. "punpcklwd %%mm2, %%mm2 \n\t"\
  242. "punpcklwd %%mm5, %%mm5 \n\t"\
  243. "punpcklwd %%mm4, %%mm4 \n\t"\
  244. "paddw %%mm1, %%mm2 \n\t"\
  245. "paddw %%mm1, %%mm5 \n\t"\
  246. "paddw %%mm1, %%mm4 \n\t"\
  247. "punpckhwd %%mm0, %%mm0 \n\t"\
  248. "punpckhwd %%mm6, %%mm6 \n\t"\
  249. "punpckhwd %%mm3, %%mm3 \n\t"\
  250. "paddw %%mm7, %%mm0 \n\t"\
  251. "paddw %%mm7, %%mm6 \n\t"\
  252. "paddw %%mm7, %%mm3 \n\t"\
  253. /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
  254. "packuswb %%mm0, %%mm2 \n\t"\
  255. "packuswb %%mm6, %%mm5 \n\t"\
  256. "packuswb %%mm3, %%mm4 \n\t"\
  257. "pxor %%mm7, %%mm7 \n\t"
  258. #define WRITEBGR32 \
  259. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\
  260. "movq %%mm2, %%mm1 \n\t" /* B */\
  261. "movq %%mm5, %%mm6 \n\t" /* R */\
  262. "punpcklbw %%mm4, %%mm2 \n\t" /* GBGBGBGB 0 */\
  263. "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R 0 */\
  264. "punpckhbw %%mm4, %%mm1 \n\t" /* GBGBGBGB 2 */\
  265. "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R 2 */\
  266. "movq %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */\
  267. "movq %%mm1, %%mm3 \n\t" /* GBGBGBGB 2 */\
  268. "punpcklwd %%mm5, %%mm0 \n\t" /* 0RGB0RGB 0 */\
  269. "punpckhwd %%mm5, %%mm2 \n\t" /* 0RGB0RGB 1 */\
  270. "punpcklwd %%mm6, %%mm1 \n\t" /* 0RGB0RGB 2 */\
  271. "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\
  272. \
  273. MOVNTQ(%%mm0, (%4, %%eax, 4))\
  274. MOVNTQ(%%mm2, 8(%4, %%eax, 4))\
  275. MOVNTQ(%%mm1, 16(%4, %%eax, 4))\
  276. MOVNTQ(%%mm3, 24(%4, %%eax, 4))\
  277. \
  278. "addl $8, %%eax \n\t"\
  279. "cmpl %5, %%eax \n\t"\
  280. " jb 1b \n\t"
  281. #define WRITEBGR16 \
  282. "movq %%mm2, %%mm1 \n\t" /* B */\
  283. "movq %%mm4, %%mm3 \n\t" /* G */\
  284. "movq %%mm5, %%mm6 \n\t" /* R */\
  285. \
  286. "punpcklbw %%mm7, %%mm3 \n\t" /* 0G0G0G0G */\
  287. "punpcklbw %%mm7, %%mm2 \n\t" /* 0B0B0B0B */\
  288. "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R */\
  289. \
  290. "psrlw $3, %%mm2 \n\t"\
  291. "psllw $3, %%mm3 \n\t"\
  292. "psllw $8, %%mm5 \n\t"\
  293. \
  294. "pand g16Mask, %%mm3 \n\t"\
  295. "pand r16Mask, %%mm5 \n\t"\
  296. \
  297. "por %%mm3, %%mm2 \n\t"\
  298. "por %%mm5, %%mm2 \n\t"\
  299. \
  300. "punpckhbw %%mm7, %%mm4 \n\t" /* 0G0G0G0G */\
  301. "punpckhbw %%mm7, %%mm1 \n\t" /* 0B0B0B0B */\
  302. "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R */\
  303. \
  304. "psrlw $3, %%mm1 \n\t"\
  305. "psllw $3, %%mm4 \n\t"\
  306. "psllw $8, %%mm6 \n\t"\
  307. \
  308. "pand g16Mask, %%mm4 \n\t"\
  309. "pand r16Mask, %%mm6 \n\t"\
  310. \
  311. "por %%mm4, %%mm1 \n\t"\
  312. "por %%mm6, %%mm1 \n\t"\
  313. \
  314. MOVNTQ(%%mm2, (%4, %%eax, 2))\
  315. MOVNTQ(%%mm1, 8(%4, %%eax, 2))\
  316. \
  317. "addl $8, %%eax \n\t"\
  318. "cmpl %5, %%eax \n\t"\
  319. " jb 1b \n\t"
  320. #define WRITEBGR15 \
  321. "movq %%mm2, %%mm1 \n\t" /* B */\
  322. "movq %%mm4, %%mm3 \n\t" /* G */\
  323. "movq %%mm5, %%mm6 \n\t" /* R */\
  324. \
  325. "punpcklbw %%mm7, %%mm3 \n\t" /* 0G0G0G0G */\
  326. "punpcklbw %%mm7, %%mm2 \n\t" /* 0B0B0B0B */\
  327. "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R */\
  328. \
  329. "psrlw $3, %%mm2 \n\t"\
  330. "psllw $2, %%mm3 \n\t"\
  331. "psllw $7, %%mm5 \n\t"\
  332. \
  333. "pand g15Mask, %%mm3 \n\t"\
  334. "pand r15Mask, %%mm5 \n\t"\
  335. \
  336. "por %%mm3, %%mm2 \n\t"\
  337. "por %%mm5, %%mm2 \n\t"\
  338. \
  339. "punpckhbw %%mm7, %%mm4 \n\t" /* 0G0G0G0G */\
  340. "punpckhbw %%mm7, %%mm1 \n\t" /* 0B0B0B0B */\
  341. "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R */\
  342. \
  343. "psrlw $3, %%mm1 \n\t"\
  344. "psllw $2, %%mm4 \n\t"\
  345. "psllw $7, %%mm6 \n\t"\
  346. \
  347. "pand g15Mask, %%mm4 \n\t"\
  348. "pand r15Mask, %%mm6 \n\t"\
  349. \
  350. "por %%mm4, %%mm1 \n\t"\
  351. "por %%mm6, %%mm1 \n\t"\
  352. \
  353. MOVNTQ(%%mm2, (%4, %%eax, 2))\
  354. MOVNTQ(%%mm1, 8(%4, %%eax, 2))\
  355. \
  356. "addl $8, %%eax \n\t"\
  357. "cmpl %5, %%eax \n\t"\
  358. " jb 1b \n\t"
  359. // FIXME find a faster way to shuffle it to BGR24
  360. #define WRITEBGR24 \
  361. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\
  362. "movq %%mm2, %%mm1 \n\t" /* B */\
  363. "movq %%mm5, %%mm6 \n\t" /* R */\
  364. "punpcklbw %%mm4, %%mm2 \n\t" /* GBGBGBGB 0 */\
  365. "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R 0 */\
  366. "punpckhbw %%mm4, %%mm1 \n\t" /* GBGBGBGB 2 */\
  367. "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R 2 */\
  368. "movq %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */\
  369. "movq %%mm1, %%mm3 \n\t" /* GBGBGBGB 2 */\
  370. "punpcklwd %%mm5, %%mm0 \n\t" /* 0RGB0RGB 0 */\
  371. "punpckhwd %%mm5, %%mm2 \n\t" /* 0RGB0RGB 1 */\
  372. "punpcklwd %%mm6, %%mm1 \n\t" /* 0RGB0RGB 2 */\
  373. "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\
  374. \
  375. "movq %%mm0, %%mm4 \n\t" /* 0RGB0RGB 0 */\
  376. "psrlq $8, %%mm0 \n\t" /* 00RGB0RG 0 */\
  377. "pand bm00000111, %%mm4 \n\t" /* 00000RGB 0 */\
  378. "pand bm11111000, %%mm0 \n\t" /* 00RGB000 0.5 */\
  379. "por %%mm4, %%mm0 \n\t" /* 00RGBRGB 0 */\
  380. "movq %%mm2, %%mm4 \n\t" /* 0RGB0RGB 1 */\
  381. "psllq $48, %%mm2 \n\t" /* GB000000 1 */\
  382. "por %%mm2, %%mm0 \n\t" /* GBRGBRGB 0 */\
  383. \
  384. "movq %%mm4, %%mm2 \n\t" /* 0RGB0RGB 1 */\
  385. "psrld $16, %%mm4 \n\t" /* 000R000R 1 */\
  386. "psrlq $24, %%mm2 \n\t" /* 0000RGB0 1.5 */\
  387. "por %%mm4, %%mm2 \n\t" /* 000RRGBR 1 */\
  388. "pand bm00001111, %%mm2 \n\t" /* 0000RGBR 1 */\
  389. "movq %%mm1, %%mm4 \n\t" /* 0RGB0RGB 2 */\
  390. "psrlq $8, %%mm1 \n\t" /* 00RGB0RG 2 */\
  391. "pand bm00000111, %%mm4 \n\t" /* 00000RGB 2 */\
  392. "pand bm11111000, %%mm1 \n\t" /* 00RGB000 2.5 */\
  393. "por %%mm4, %%mm1 \n\t" /* 00RGBRGB 2 */\
  394. "movq %%mm1, %%mm4 \n\t" /* 00RGBRGB 2 */\
  395. "psllq $32, %%mm1 \n\t" /* BRGB0000 2 */\
  396. "por %%mm1, %%mm2 \n\t" /* BRGBRGBR 1 */\
  397. \
  398. "psrlq $32, %%mm4 \n\t" /* 000000RG 2.5 */\
  399. "movq %%mm3, %%mm5 \n\t" /* 0RGB0RGB 3 */\
  400. "psrlq $8, %%mm3 \n\t" /* 00RGB0RG 3 */\
  401. "pand bm00000111, %%mm5 \n\t" /* 00000RGB 3 */\
  402. "pand bm11111000, %%mm3 \n\t" /* 00RGB000 3.5 */\
  403. "por %%mm5, %%mm3 \n\t" /* 00RGBRGB 3 */\
  404. "psllq $16, %%mm3 \n\t" /* RGBRGB00 3 */\
  405. "por %%mm4, %%mm3 \n\t" /* RGBRGBRG 2.5 */\
  406. \
  407. "leal (%%eax, %%eax, 2), %%ebx \n\t"\
  408. MOVNTQ(%%mm0, (%4, %%ebx))\
  409. MOVNTQ(%%mm2, 8(%4, %%ebx))\
  410. MOVNTQ(%%mm3, 16(%4, %%ebx))\
  411. \
  412. "addl $8, %%eax \n\t"\
  413. "cmpl %5, %%eax \n\t"\
  414. " jb 1b \n\t"
  415. static inline void yuv2yuv(uint16_t *buf0, uint16_t *buf1, uint16_t *uvbuf0, uint16_t *uvbuf1,
  416. uint8_t *dest, uint8_t *uDest, uint8_t *vDest, int dstw, int yalpha, int uvalpha)
  417. {
  418. int yalpha1=yalpha^4095;
  419. int uvalpha1=uvalpha^4095;
  420. int i;
  421. asm volatile ("\n\t"::: "memory");
  422. for(i=0;i<dstw;i++)
  423. {
  424. ((uint8_t*)dest)[0] = (buf0[i]*yalpha1+buf1[i]*yalpha)>>19;
  425. dest++;
  426. }
  427. if(uvalpha != -1)
  428. {
  429. for(i=0; i<dstw/2; i++)
  430. {
  431. ((uint8_t*)uDest)[0] = (uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19;
  432. ((uint8_t*)vDest)[0] = (uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19;
  433. uDest++;
  434. vDest++;
  435. }
  436. }
  437. }
  438. /**
  439. * vertical scale YV12 to RGB
  440. */
  441. static inline void yuv2rgbX(uint16_t *buf0, uint16_t *buf1, uint16_t *uvbuf0, uint16_t *uvbuf1,
  442. uint8_t *dest, int dstw, int yalpha, int uvalpha, int dstbpp)
  443. {
  444. int yalpha1=yalpha^4095;
  445. int uvalpha1=uvalpha^4095;
  446. int i;
  447. if(fullUVIpol)
  448. {
  449. #ifdef HAVE_MMX
  450. if(dstbpp == 32)
  451. {
  452. asm volatile(
  453. FULL_YSCALEYUV2RGB
  454. "punpcklbw %%mm1, %%mm3 \n\t" // BGBGBGBG
  455. "punpcklbw %%mm7, %%mm0 \n\t" // R0R0R0R0
  456. "movq %%mm3, %%mm1 \n\t"
  457. "punpcklwd %%mm0, %%mm3 \n\t" // BGR0BGR0
  458. "punpckhwd %%mm0, %%mm1 \n\t" // BGR0BGR0
  459. MOVNTQ(%%mm3, (%4, %%eax, 4))
  460. MOVNTQ(%%mm1, 8(%4, %%eax, 4))
  461. "addl $4, %%eax \n\t"
  462. "cmpl %5, %%eax \n\t"
  463. " jb 1b \n\t"
  464. :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
  465. "m" (yalpha1), "m" (uvalpha1)
  466. : "%eax"
  467. );
  468. }
  469. else if(dstbpp==24)
  470. {
  471. asm volatile(
  472. FULL_YSCALEYUV2RGB
  473. // lsb ... msb
  474. "punpcklbw %%mm1, %%mm3 \n\t" // BGBGBGBG
  475. "punpcklbw %%mm7, %%mm0 \n\t" // R0R0R0R0
  476. "movq %%mm3, %%mm1 \n\t"
  477. "punpcklwd %%mm0, %%mm3 \n\t" // BGR0BGR0
  478. "punpckhwd %%mm0, %%mm1 \n\t" // BGR0BGR0
  479. "movq %%mm3, %%mm2 \n\t" // BGR0BGR0
  480. "psrlq $8, %%mm3 \n\t" // GR0BGR00
  481. "pand bm00000111, %%mm2 \n\t" // BGR00000
  482. "pand bm11111000, %%mm3 \n\t" // 000BGR00
  483. "por %%mm2, %%mm3 \n\t" // BGRBGR00
  484. "movq %%mm1, %%mm2 \n\t"
  485. "psllq $48, %%mm1 \n\t" // 000000BG
  486. "por %%mm1, %%mm3 \n\t" // BGRBGRBG
  487. "movq %%mm2, %%mm1 \n\t" // BGR0BGR0
  488. "psrld $16, %%mm2 \n\t" // R000R000
  489. "psrlq $24, %%mm1 \n\t" // 0BGR0000
  490. "por %%mm2, %%mm1 \n\t" // RBGRR000
  491. "movl %4, %%ebx \n\t"
  492. "addl %%eax, %%ebx \n\t"
  493. #ifdef HAVE_MMX2
  494. //FIXME Alignment
  495. "movntq %%mm3, (%%ebx, %%eax, 2)\n\t"
  496. "movntq %%mm1, 8(%%ebx, %%eax, 2)\n\t"
  497. #else
  498. "movd %%mm3, (%%ebx, %%eax, 2) \n\t"
  499. "psrlq $32, %%mm3 \n\t"
  500. "movd %%mm3, 4(%%ebx, %%eax, 2) \n\t"
  501. "movd %%mm1, 8(%%ebx, %%eax, 2) \n\t"
  502. #endif
  503. "addl $4, %%eax \n\t"
  504. "cmpl %5, %%eax \n\t"
  505. " jb 1b \n\t"
  506. :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "m" (dest), "m" (dstw),
  507. "m" (yalpha1), "m" (uvalpha1)
  508. : "%eax", "%ebx"
  509. );
  510. }
  511. else if(dstbpp==15)
  512. {
  513. asm volatile(
  514. FULL_YSCALEYUV2RGB
  515. #ifdef DITHER1XBPP
  516. "paddusb b16Dither, %%mm1 \n\t"
  517. "paddusb b16Dither, %%mm0 \n\t"
  518. "paddusb b16Dither, %%mm3 \n\t"
  519. #endif
  520. "punpcklbw %%mm7, %%mm1 \n\t" // 0G0G0G0G
  521. "punpcklbw %%mm7, %%mm3 \n\t" // 0B0B0B0B
  522. "punpcklbw %%mm7, %%mm0 \n\t" // 0R0R0R0R
  523. "psrlw $3, %%mm3 \n\t"
  524. "psllw $2, %%mm1 \n\t"
  525. "psllw $7, %%mm0 \n\t"
  526. "pand g15Mask, %%mm1 \n\t"
  527. "pand r15Mask, %%mm0 \n\t"
  528. "por %%mm3, %%mm1 \n\t"
  529. "por %%mm1, %%mm0 \n\t"
  530. MOVNTQ(%%mm0, (%4, %%eax, 2))
  531. "addl $4, %%eax \n\t"
  532. "cmpl %5, %%eax \n\t"
  533. " jb 1b \n\t"
  534. :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
  535. "m" (yalpha1), "m" (uvalpha1)
  536. : "%eax"
  537. );
  538. }
  539. else if(dstbpp==16)
  540. {
  541. asm volatile(
  542. FULL_YSCALEYUV2RGB
  543. #ifdef DITHER1XBPP
  544. "paddusb g16Dither, %%mm1 \n\t"
  545. "paddusb b16Dither, %%mm0 \n\t"
  546. "paddusb b16Dither, %%mm3 \n\t"
  547. #endif
  548. "punpcklbw %%mm7, %%mm1 \n\t" // 0G0G0G0G
  549. "punpcklbw %%mm7, %%mm3 \n\t" // 0B0B0B0B
  550. "punpcklbw %%mm7, %%mm0 \n\t" // 0R0R0R0R
  551. "psrlw $3, %%mm3 \n\t"
  552. "psllw $3, %%mm1 \n\t"
  553. "psllw $8, %%mm0 \n\t"
  554. "pand g16Mask, %%mm1 \n\t"
  555. "pand r16Mask, %%mm0 \n\t"
  556. "por %%mm3, %%mm1 \n\t"
  557. "por %%mm1, %%mm0 \n\t"
  558. MOVNTQ(%%mm0, (%4, %%eax, 2))
  559. "addl $4, %%eax \n\t"
  560. "cmpl %5, %%eax \n\t"
  561. " jb 1b \n\t"
  562. :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
  563. "m" (yalpha1), "m" (uvalpha1)
  564. : "%eax"
  565. );
  566. }
  567. #else
  568. asm volatile ("\n\t"::: "memory");
  569. if(dstbpp==32 || dstbpp==24)
  570. {
  571. for(i=0;i<dstw;i++){
  572. // vertical linear interpolation && yuv2rgb in a single step:
  573. int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
  574. int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19);
  575. int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19);
  576. dest[0]=clip_table[((Y + yuvtab_40cf[U]) >>13)];
  577. dest[1]=clip_table[((Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13)];
  578. dest[2]=clip_table[((Y + yuvtab_3343[V]) >>13)];
  579. dest+=dstbpp>>3;
  580. }
  581. }
  582. else if(dstbpp==16)
  583. {
  584. for(i=0;i<dstw;i++){
  585. // vertical linear interpolation && yuv2rgb in a single step:
  586. int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
  587. int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19);
  588. int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19);
  589. ((uint16_t*)dest)[0] =
  590. (clip_table[(Y + yuvtab_40cf[U]) >>13]>>3) |
  591. ((clip_table[(Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13]<<3)&0x07E0) |
  592. ((clip_table[(Y + yuvtab_3343[V]) >>13]<<8)&0xF800);
  593. dest+=2;
  594. }
  595. }
  596. else if(dstbpp==15)
  597. {
  598. for(i=0;i<dstw;i++){
  599. // vertical linear interpolation && yuv2rgb in a single step:
  600. int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
  601. int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19);
  602. int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19);
  603. ((uint16_t*)dest)[0] =
  604. (clip_table[(Y + yuvtab_40cf[U]) >>13]>>3) |
  605. ((clip_table[(Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13]<<2)&0x03E0) |
  606. ((clip_table[(Y + yuvtab_3343[V]) >>13]<<7)&0x7C00);
  607. dest+=2;
  608. }
  609. }
  610. #endif
  611. }//FULL_UV_IPOL
  612. else
  613. {
  614. #ifdef HAVE_MMX
  615. if(dstbpp == 32)
  616. {
  617. asm volatile(
  618. YSCALEYUV2RGB
  619. WRITEBGR32
  620. :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
  621. "m" (yalpha1), "m" (uvalpha1)
  622. : "%eax"
  623. );
  624. }
  625. else if(dstbpp==24)
  626. {
  627. asm volatile(
  628. YSCALEYUV2RGB
  629. WRITEBGR24
  630. :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
  631. "m" (yalpha1), "m" (uvalpha1)
  632. : "%eax", "%ebx"
  633. );
  634. }
  635. else if(dstbpp==15)
  636. {
  637. asm volatile(
  638. YSCALEYUV2RGB
  639. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  640. #ifdef DITHER1XBPP
  641. "paddusb b16Dither, %%mm2 \n\t"
  642. "paddusb b16Dither, %%mm4 \n\t"
  643. "paddusb b16Dither, %%mm5 \n\t"
  644. #endif
  645. WRITEBGR15
  646. :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
  647. "m" (yalpha1), "m" (uvalpha1)
  648. : "%eax"
  649. );
  650. }
  651. else if(dstbpp==16)
  652. {
  653. asm volatile(
  654. YSCALEYUV2RGB
  655. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  656. #ifdef DITHER1XBPP
  657. "paddusb g16Dither, %%mm2 \n\t"
  658. "paddusb b16Dither, %%mm4 \n\t"
  659. "paddusb b16Dither, %%mm5 \n\t"
  660. #endif
  661. WRITEBGR16
  662. :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
  663. "m" (yalpha1), "m" (uvalpha1)
  664. : "%eax"
  665. );
  666. }
  667. #else
  668. //FIXME unroll C loop and dont recalculate UV
  669. asm volatile ("\n\t"::: "memory");
  670. if(dstbpp==32 || dstbpp==24)
  671. {
  672. for(i=0;i<dstw;i++){
  673. // vertical linear interpolation && yuv2rgb in a single step:
  674. int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
  675. int U=((uvbuf0[i/2]*uvalpha1+uvbuf1[i/2]*uvalpha)>>19);
  676. int V=((uvbuf0[i/2+2048]*uvalpha1+uvbuf1[i/2+2048]*uvalpha)>>19);
  677. dest[0]=clip_table[((Y + yuvtab_40cf[U]) >>13)];
  678. dest[1]=clip_table[((Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13)];
  679. dest[2]=clip_table[((Y + yuvtab_3343[V]) >>13)];
  680. dest+=dstbpp>>3;
  681. }
  682. }
  683. else if(dstbpp==16)
  684. {
  685. for(i=0;i<dstw;i++){
  686. // vertical linear interpolation && yuv2rgb in a single step:
  687. int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
  688. int U=((uvbuf0[i/2]*uvalpha1+uvbuf1[i/2]*uvalpha)>>19);
  689. int V=((uvbuf0[i/2+2048]*uvalpha1+uvbuf1[i/2+2048]*uvalpha)>>19);
  690. ((uint16_t*)dest)[0] =
  691. (clip_table[(Y + yuvtab_40cf[U]) >>13]>>3) |
  692. ((clip_table[(Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13]<<3)&0x07E0) |
  693. ((clip_table[(Y + yuvtab_3343[V]) >>13]<<8)&0xF800);
  694. dest+=2;
  695. }
  696. }
  697. else if(dstbpp==15)
  698. {
  699. for(i=0;i<dstw;i++){
  700. // vertical linear interpolation && yuv2rgb in a single step:
  701. int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
  702. int U=((uvbuf0[i/2]*uvalpha1+uvbuf1[i/2]*uvalpha)>>19);
  703. int V=((uvbuf0[i/2+2048]*uvalpha1+uvbuf1[i/2+2048]*uvalpha)>>19);
  704. ((uint16_t*)dest)[0] =
  705. (clip_table[(Y + yuvtab_40cf[U]) >>13]>>3) |
  706. ((clip_table[(Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13]<<2)&0x03E0) |
  707. ((clip_table[(Y + yuvtab_3343[V]) >>13]<<7)&0x7C00);
  708. dest+=2;
  709. }
  710. }
  711. #endif
  712. } //!FULL_UV_IPOL
  713. }
  714. /**
  715. * YV12 to RGB without scaling or interpolating
  716. */
  717. static inline void yuv2rgb1(uint16_t *buf0, uint16_t *buf1, uint16_t *uvbuf0, uint16_t *uvbuf1,
  718. uint8_t *dest, int dstw, int yalpha, int uvalpha, int dstbpp)
  719. {
  720. int yalpha1=yalpha^4095;
  721. int uvalpha1=uvalpha^4095;
  722. int i;
  723. if(fullUVIpol || allwaysIpol)
  724. {
  725. yuv2rgbX(buf0, buf1, uvbuf0, uvbuf1, dest, dstw, yalpha, uvalpha, dstbpp);
  726. return;
  727. }
  728. #ifdef HAVE_MMX
  729. if(dstbpp == 32)
  730. {
  731. asm volatile(
  732. YSCALEYUV2RGB1
  733. WRITEBGR32
  734. :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
  735. "m" (yalpha1), "m" (uvalpha1)
  736. : "%eax"
  737. );
  738. }
  739. else if(dstbpp==24)
  740. {
  741. asm volatile(
  742. YSCALEYUV2RGB1
  743. WRITEBGR24
  744. :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
  745. "m" (yalpha1), "m" (uvalpha1)
  746. : "%eax", "%ebx"
  747. );
  748. }
  749. else if(dstbpp==15)
  750. {
  751. asm volatile(
  752. YSCALEYUV2RGB1
  753. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  754. #ifdef DITHER1XBPP
  755. "paddusb b16Dither, %%mm2 \n\t"
  756. "paddusb b16Dither, %%mm4 \n\t"
  757. "paddusb b16Dither, %%mm5 \n\t"
  758. #endif
  759. WRITEBGR15
  760. :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
  761. "m" (yalpha1), "m" (uvalpha1)
  762. : "%eax"
  763. );
  764. }
  765. else if(dstbpp==16)
  766. {
  767. asm volatile(
  768. YSCALEYUV2RGB1
  769. /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
  770. #ifdef DITHER1XBPP
  771. "paddusb g16Dither, %%mm2 \n\t"
  772. "paddusb b16Dither, %%mm4 \n\t"
  773. "paddusb b16Dither, %%mm5 \n\t"
  774. #endif
  775. WRITEBGR16
  776. :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
  777. "m" (yalpha1), "m" (uvalpha1)
  778. : "%eax"
  779. );
  780. }
  781. #else
  782. //FIXME unroll C loop and dont recalculate UV
  783. asm volatile ("\n\t"::: "memory");
  784. if(dstbpp==32 || dstbpp==24)
  785. {
  786. for(i=0;i<dstw;i++){
  787. // vertical linear interpolation && yuv2rgb in a single step:
  788. int Y=yuvtab_2568[buf0[i]>>7];
  789. int U=((uvbuf0[i/2]*uvalpha1+uvbuf1[i/2]*uvalpha)>>19);
  790. int V=((uvbuf0[i/2+2048]*uvalpha1+uvbuf1[i/2+2048]*uvalpha)>>19);
  791. dest[0]=clip_table[((Y + yuvtab_40cf[U]) >>13)];
  792. dest[1]=clip_table[((Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13)];
  793. dest[2]=clip_table[((Y + yuvtab_3343[V]) >>13)];
  794. dest+=dstbpp>>3;
  795. }
  796. }
  797. else if(dstbpp==16)
  798. {
  799. for(i=0;i<dstw;i++){
  800. // vertical linear interpolation && yuv2rgb in a single step:
  801. int Y=yuvtab_2568[buf0[i]>>7];
  802. int U=((uvbuf0[i/2]*uvalpha1+uvbuf1[i/2]*uvalpha)>>19);
  803. int V=((uvbuf0[i/2+2048]*uvalpha1+uvbuf1[i/2+2048]*uvalpha)>>19);
  804. ((uint16_t*)dest)[0] =
  805. (clip_table[(Y + yuvtab_40cf[U]) >>13]>>3) |
  806. ((clip_table[(Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13]<<3)&0x07E0) |
  807. ((clip_table[(Y + yuvtab_3343[V]) >>13]<<8)&0xF800);
  808. dest+=2;
  809. }
  810. }
  811. else if(dstbpp==15)
  812. {
  813. for(i=0;i<dstw;i++){
  814. // vertical linear interpolation && yuv2rgb in a single step:
  815. int Y=yuvtab_2568[buf0[i]>>7];
  816. int U=((uvbuf0[i/2]*uvalpha1+uvbuf1[i/2]*uvalpha)>>19);
  817. int V=((uvbuf0[i/2+2048]*uvalpha1+uvbuf1[i/2+2048]*uvalpha)>>19);
  818. ((uint16_t*)dest)[0] =
  819. (clip_table[(Y + yuvtab_40cf[U]) >>13]>>3) |
  820. ((clip_table[(Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13]<<2)&0x03E0) |
  821. ((clip_table[(Y + yuvtab_3343[V]) >>13]<<7)&0x7C00);
  822. dest+=2;
  823. }
  824. }
  825. #endif
  826. }
  827. static inline void hyscale(uint16_t *dst, int dstWidth, uint8_t *src, int srcWidth, int xInc)
  828. {
  829. int i;
  830. unsigned int xpos=0;
  831. // *** horizontal scale Y line to temp buffer
  832. #ifdef ARCH_X86
  833. #ifdef HAVE_MMX2
  834. if(canMMX2BeUsed)
  835. {
  836. asm volatile(
  837. "pxor %%mm7, %%mm7 \n\t"
  838. "pxor %%mm2, %%mm2 \n\t" // 2*xalpha
  839. "movd %5, %%mm6 \n\t" // xInc&0xFFFF
  840. "punpcklwd %%mm6, %%mm6 \n\t"
  841. "punpcklwd %%mm6, %%mm6 \n\t"
  842. "movq %%mm6, %%mm2 \n\t"
  843. "psllq $16, %%mm2 \n\t"
  844. "paddw %%mm6, %%mm2 \n\t"
  845. "psllq $16, %%mm2 \n\t"
  846. "paddw %%mm6, %%mm2 \n\t"
  847. "psllq $16, %%mm2 \n\t" //0,t,2t,3t t=xInc&0xFF
  848. "movq %%mm2, temp0 \n\t"
  849. "movd %4, %%mm6 \n\t" //(xInc*4)&0xFFFF
  850. "punpcklwd %%mm6, %%mm6 \n\t"
  851. "punpcklwd %%mm6, %%mm6 \n\t"
  852. "xorl %%eax, %%eax \n\t" // i
  853. "movl %0, %%esi \n\t" // src
  854. "movl %1, %%edi \n\t" // buf1
  855. "movl %3, %%edx \n\t" // (xInc*4)>>16
  856. "xorl %%ecx, %%ecx \n\t"
  857. "xorl %%ebx, %%ebx \n\t"
  858. "movw %4, %%bx \n\t" // (xInc*4)&0xFFFF
  859. #define FUNNY_Y_CODE \
  860. PREFETCH" 1024(%%esi) \n\t"\
  861. PREFETCH" 1056(%%esi) \n\t"\
  862. PREFETCH" 1088(%%esi) \n\t"\
  863. "call funnyYCode \n\t"\
  864. "movq temp0, %%mm2 \n\t"\
  865. "xorl %%ecx, %%ecx \n\t"
  866. FUNNY_Y_CODE
  867. FUNNY_Y_CODE
  868. FUNNY_Y_CODE
  869. FUNNY_Y_CODE
  870. FUNNY_Y_CODE
  871. FUNNY_Y_CODE
  872. FUNNY_Y_CODE
  873. FUNNY_Y_CODE
  874. :: "m" (src), "m" (dst), "m" (dstWidth), "m" ((xInc*4)>>16),
  875. "m" ((xInc*4)&0xFFFF), "m" (xInc&0xFFFF)
  876. : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi"
  877. );
  878. for(i=dstWidth-1; (i*xInc)>>16 >=srcWidth-1; i--) dst[i] = src[srcWidth-1]*128;
  879. }
  880. else
  881. {
  882. #endif
  883. //NO MMX just normal asm ...
  884. asm volatile(
  885. "xorl %%eax, %%eax \n\t" // i
  886. "xorl %%ebx, %%ebx \n\t" // xx
  887. "xorl %%ecx, %%ecx \n\t" // 2*xalpha
  888. "1: \n\t"
  889. "movzbl (%0, %%ebx), %%edi \n\t" //src[xx]
  890. "movzbl 1(%0, %%ebx), %%esi \n\t" //src[xx+1]
  891. "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
  892. "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
  893. "shll $16, %%edi \n\t"
  894. "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
  895. "movl %1, %%edi \n\t"
  896. "shrl $9, %%esi \n\t"
  897. "movw %%si, (%%edi, %%eax, 2) \n\t"
  898. "addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF
  899. "adcl %3, %%ebx \n\t" //xx+= xInc>>8 + carry
  900. "movzbl (%0, %%ebx), %%edi \n\t" //src[xx]
  901. "movzbl 1(%0, %%ebx), %%esi \n\t" //src[xx+1]
  902. "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
  903. "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
  904. "shll $16, %%edi \n\t"
  905. "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
  906. "movl %1, %%edi \n\t"
  907. "shrl $9, %%esi \n\t"
  908. "movw %%si, 2(%%edi, %%eax, 2) \n\t"
  909. "addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF
  910. "adcl %3, %%ebx \n\t" //xx+= xInc>>8 + carry
  911. "addl $2, %%eax \n\t"
  912. "cmpl %2, %%eax \n\t"
  913. " jb 1b \n\t"
  914. :: "r" (src), "m" (dst), "m" (dstWidth), "m" (xInc>>16), "m" (xInc&0xFFFF)
  915. : "%eax", "%ebx", "%ecx", "%edi", "%esi"
  916. );
  917. #ifdef HAVE_MMX2
  918. } //if MMX2 cant be used
  919. #endif
  920. #else
  921. for(i=0;i<dstWidth;i++){
  922. register unsigned int xx=xpos>>16;
  923. register unsigned int xalpha=(xpos&0xFFFF)>>9;
  924. dst[i]=(src[xx]*(xalpha^127)+src[xx+1]*xalpha);
  925. xpos+=xInc;
  926. }
  927. #endif
  928. }
  929. inline static void hcscale(uint16_t *dst, int dstWidth,
  930. uint8_t *src1, uint8_t *src2, int srcWidth, int xInc)
  931. {
  932. int xpos=0;
  933. int i;
  934. #ifdef ARCH_X86
  935. #ifdef HAVE_MMX2
  936. if(canMMX2BeUsed)
  937. {
  938. asm volatile(
  939. "pxor %%mm7, %%mm7 \n\t"
  940. "pxor %%mm2, %%mm2 \n\t" // 2*xalpha
  941. "movd %5, %%mm6 \n\t" // xInc&0xFFFF
  942. "punpcklwd %%mm6, %%mm6 \n\t"
  943. "punpcklwd %%mm6, %%mm6 \n\t"
  944. "movq %%mm6, %%mm2 \n\t"
  945. "psllq $16, %%mm2 \n\t"
  946. "paddw %%mm6, %%mm2 \n\t"
  947. "psllq $16, %%mm2 \n\t"
  948. "paddw %%mm6, %%mm2 \n\t"
  949. "psllq $16, %%mm2 \n\t" //0,t,2t,3t t=xInc&0xFFFF
  950. "movq %%mm2, temp0 \n\t"
  951. "movd %4, %%mm6 \n\t" //(xInc*4)&0xFFFF
  952. "punpcklwd %%mm6, %%mm6 \n\t"
  953. "punpcklwd %%mm6, %%mm6 \n\t"
  954. "xorl %%eax, %%eax \n\t" // i
  955. "movl %0, %%esi \n\t" // src
  956. "movl %1, %%edi \n\t" // buf1
  957. "movl %3, %%edx \n\t" // (xInc*4)>>16
  958. "xorl %%ecx, %%ecx \n\t"
  959. "xorl %%ebx, %%ebx \n\t"
  960. "movw %4, %%bx \n\t" // (xInc*4)&0xFFFF
  961. #define FUNNYUVCODE \
  962. PREFETCH" 1024(%%esi) \n\t"\
  963. PREFETCH" 1056(%%esi) \n\t"\
  964. PREFETCH" 1088(%%esi) \n\t"\
  965. "call funnyUVCode \n\t"\
  966. "movq temp0, %%mm2 \n\t"\
  967. "xorl %%ecx, %%ecx \n\t"
  968. FUNNYUVCODE
  969. FUNNYUVCODE
  970. FUNNYUVCODE
  971. FUNNYUVCODE
  972. FUNNYUVCODE
  973. FUNNYUVCODE
  974. FUNNYUVCODE
  975. FUNNYUVCODE
  976. "xorl %%eax, %%eax \n\t" // i
  977. "movl %6, %%esi \n\t" // src
  978. "movl %1, %%edi \n\t" // buf1
  979. "addl $4096, %%edi \n\t"
  980. FUNNYUVCODE
  981. FUNNYUVCODE
  982. FUNNYUVCODE
  983. FUNNYUVCODE
  984. FUNNYUVCODE
  985. FUNNYUVCODE
  986. FUNNYUVCODE
  987. FUNNYUVCODE
  988. :: "m" (src1), "m" (dst), "m" (dstWidth), "m" ((xInc*4)>>16),
  989. "m" ((xInc*4)&0xFFFF), "m" (xInc&0xFFFF), "m" (src2)
  990. : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi"
  991. );
  992. for(i=dstWidth-1; (i*xInc)>>16 >=srcWidth/2-1; i--)
  993. {
  994. dst[i] = src1[srcWidth/2-1]*128;
  995. dst[i+2048] = src2[srcWidth/2-1]*128;
  996. }
  997. }
  998. else
  999. {
  1000. #endif
  1001. asm volatile(
  1002. "xorl %%eax, %%eax \n\t" // i
  1003. "xorl %%ebx, %%ebx \n\t" // xx
  1004. "xorl %%ecx, %%ecx \n\t" // 2*xalpha
  1005. "1: \n\t"
  1006. "movl %0, %%esi \n\t"
  1007. "movzbl (%%esi, %%ebx), %%edi \n\t" //src[xx]
  1008. "movzbl 1(%%esi, %%ebx), %%esi \n\t" //src[xx+1]
  1009. "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
  1010. "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
  1011. "shll $16, %%edi \n\t"
  1012. "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
  1013. "movl %1, %%edi \n\t"
  1014. "shrl $9, %%esi \n\t"
  1015. "movw %%si, (%%edi, %%eax, 2) \n\t"
  1016. "movzbl (%5, %%ebx), %%edi \n\t" //src[xx]
  1017. "movzbl 1(%5, %%ebx), %%esi \n\t" //src[xx+1]
  1018. "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
  1019. "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
  1020. "shll $16, %%edi \n\t"
  1021. "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
  1022. "movl %1, %%edi \n\t"
  1023. "shrl $9, %%esi \n\t"
  1024. "movw %%si, 4096(%%edi, %%eax, 2)\n\t"
  1025. "addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF
  1026. "adcl %3, %%ebx \n\t" //xx+= xInc>>8 + carry
  1027. "addl $1, %%eax \n\t"
  1028. "cmpl %2, %%eax \n\t"
  1029. " jb 1b \n\t"
  1030. :: "m" (src1), "m" (dst), "m" (dstWidth), "m" (xInc>>16), "m" (xInc&0xFFFF),
  1031. "r" (src2)
  1032. : "%eax", "%ebx", "%ecx", "%edi", "%esi"
  1033. );
  1034. #ifdef HAVE_MMX2
  1035. } //if MMX2 cant be used
  1036. #endif
  1037. #else
  1038. for(i=0;i<dstWidth;i++){
  1039. register unsigned int xx=xpos>>16;
  1040. register unsigned int xalpha=(xpos&0xFFFF)>>9;
  1041. dst[i]=(src1[xx]*(xalpha^127)+src1[xx+1]*xalpha);
  1042. dst[i+2048]=(src2[xx]*(xalpha^127)+src2[xx+1]*xalpha);
  1043. xpos+=xInc;
  1044. }
  1045. #endif
  1046. }
  1047. // *** bilinear scaling and yuv->rgb or yuv->yuv conversion of yv12 slices:
  1048. // *** Note: it's called multiple times while decoding a frame, first time y==0
  1049. // *** Designed to upscale, but may work for downscale too.
  1050. // s_xinc = (src_width << 16) / dst_width
  1051. // s_yinc = (src_height << 16) / dst_height
  1052. void SwScale_YV12slice(unsigned char* srcptr[],int stride[], int y, int h,
  1053. uint8_t* dstptr[], int dststride, int dstw, int dstbpp,
  1054. unsigned int s_xinc,unsigned int s_yinc){
  1055. // scaling factors:
  1056. //static int s_yinc=(vo_dga_src_height<<16)/vo_dga_vp_height;
  1057. //static int s_xinc=(vo_dga_src_width<<8)/vo_dga_vp_width;
  1058. unsigned int s_xinc2;
  1059. static int s_srcypos; // points to the dst Pixels center in the source (0 is the center of pixel 0,0 in src)
  1060. static int s_ypos;
  1061. // last horzontally interpolated lines, used to avoid unnecessary calculations
  1062. static int s_last_ypos;
  1063. static int s_last_y1pos;
  1064. static int static_dstw;
  1065. #ifdef HAVE_MMX2
  1066. // used to detect a horizontal size change
  1067. static int old_dstw= -1;
  1068. static int old_s_xinc= -1;
  1069. #endif
  1070. int srcWidth= (dstw*s_xinc + 0x8000)>>16;
  1071. int dstUVw= fullUVIpol ? dstw : dstw/2;
  1072. #ifdef HAVE_MMX2
  1073. canMMX2BeUsed= (s_xinc <= 0x10000 && (dstw&31)==0 && (srcWidth&15)==0) ? 1 : 0;
  1074. #endif
  1075. // match pixel 0 of the src to pixel 0 of dst and match pixel n-2 of src to pixel n-2 of dst
  1076. // n-2 is the last chrominance sample available
  1077. // FIXME this is not perfect, but noone shuld notice the difference, the more correct variant
  1078. // would be like the vertical one, but that would require some special code for the
  1079. // first and last pixel
  1080. if(canMMX2BeUsed) s_xinc+= 20;
  1081. else s_xinc = ((srcWidth-2)<<16)/(dstw-2) - 20;
  1082. if(fullUVIpol && !dstbpp==12) s_xinc2= s_xinc>>1;
  1083. else s_xinc2= s_xinc;
  1084. // force calculation of the horizontal interpolation of the first line
  1085. if(y==0){
  1086. s_last_ypos=-99;
  1087. s_last_y1pos=-99;
  1088. s_srcypos= s_yinc/2 - 0x8000;
  1089. s_ypos=0;
  1090. #ifdef HAVE_MMX2
  1091. // cant downscale !!!
  1092. if((old_s_xinc != s_xinc || old_dstw!=dstw) && canMMX2BeUsed)
  1093. {
  1094. uint8_t *fragment;
  1095. int imm8OfPShufW1;
  1096. int imm8OfPShufW2;
  1097. int fragmentLength;
  1098. int xpos, xx, xalpha, i;
  1099. old_s_xinc= s_xinc;
  1100. old_dstw= dstw;
  1101. static_dstw= dstw;
  1102. // create an optimized horizontal scaling routine
  1103. //code fragment
  1104. asm volatile(
  1105. "jmp 9f \n\t"
  1106. // Begin
  1107. "0: \n\t"
  1108. "movq (%%esi), %%mm0 \n\t" //FIXME Alignment
  1109. "movq %%mm0, %%mm1 \n\t"
  1110. "psrlq $8, %%mm0 \n\t"
  1111. "punpcklbw %%mm7, %%mm1 \n\t"
  1112. "movq %%mm2, %%mm3 \n\t"
  1113. "punpcklbw %%mm7, %%mm0 \n\t"
  1114. "addw %%bx, %%cx \n\t" //2*xalpha += (4*s_xinc)&0xFFFF
  1115. "pshufw $0xFF, %%mm1, %%mm1 \n\t"
  1116. "1: \n\t"
  1117. "adcl %%edx, %%esi \n\t" //xx+= (4*s_xinc)>>16 + carry
  1118. "pshufw $0xFF, %%mm0, %%mm0 \n\t"
  1119. "2: \n\t"
  1120. "psrlw $9, %%mm3 \n\t"
  1121. "psubw %%mm1, %%mm0 \n\t"
  1122. "pmullw %%mm3, %%mm0 \n\t"
  1123. "paddw %%mm6, %%mm2 \n\t" // 2*alpha += xpos&0xFFFF
  1124. "psllw $7, %%mm1 \n\t"
  1125. "paddw %%mm1, %%mm0 \n\t"
  1126. "movq %%mm0, (%%edi, %%eax) \n\t"
  1127. "addl $8, %%eax \n\t"
  1128. // End
  1129. "9: \n\t"
  1130. // "int $3\n\t"
  1131. "leal 0b, %0 \n\t"
  1132. "leal 1b, %1 \n\t"
  1133. "leal 2b, %2 \n\t"
  1134. "decl %1 \n\t"
  1135. "decl %2 \n\t"
  1136. "subl %0, %1 \n\t"
  1137. "subl %0, %2 \n\t"
  1138. "leal 9b, %3 \n\t"
  1139. "subl %0, %3 \n\t"
  1140. :"=r" (fragment), "=r" (imm8OfPShufW1), "=r" (imm8OfPShufW2),
  1141. "=r" (fragmentLength)
  1142. );
  1143. xpos= 0; //s_xinc/2 - 0x8000; // difference between pixel centers
  1144. /* choose xinc so that all 8 parts fit exactly
  1145. Note: we cannot use just 1 part because it would not fit in the code cache */
  1146. // s_xinc2_diff= -((((s_xinc2*(dstw/8))&0xFFFF))/(dstw/8))-10;
  1147. // s_xinc_diff= -((((s_xinc*(dstw/8))&0xFFFF))/(dstw/8));
  1148. #ifdef ALT_ERROR
  1149. // s_xinc2_diff+= ((0x10000/(dstw/8)));
  1150. #endif
  1151. // s_xinc_diff= s_xinc2_diff*2;
  1152. // s_xinc2+= s_xinc2_diff;
  1153. // s_xinc+= s_xinc_diff;
  1154. // old_s_xinc= s_xinc;
  1155. for(i=0; i<dstw/8; i++)
  1156. {
  1157. int xx=xpos>>16;
  1158. if((i&3) == 0)
  1159. {
  1160. int a=0;
  1161. int b=((xpos+s_xinc)>>16) - xx;
  1162. int c=((xpos+s_xinc*2)>>16) - xx;
  1163. int d=((xpos+s_xinc*3)>>16) - xx;
  1164. memcpy(funnyYCode + fragmentLength*i/4, fragment, fragmentLength);
  1165. funnyYCode[fragmentLength*i/4 + imm8OfPShufW1]=
  1166. funnyYCode[fragmentLength*i/4 + imm8OfPShufW2]=
  1167. a | (b<<2) | (c<<4) | (d<<6);
  1168. // if we dont need to read 8 bytes than dont :), reduces the chance of
  1169. // crossing a cache line
  1170. if(d<3) funnyYCode[fragmentLength*i/4 + 1]= 0x6E;
  1171. funnyYCode[fragmentLength*(i+4)/4]= RET;
  1172. }
  1173. xpos+=s_xinc;
  1174. }
  1175. xpos= 0; //s_xinc2/2 - 0x10000; // difference between centers of chrom samples
  1176. for(i=0; i<dstUVw/8; i++)
  1177. {
  1178. int xx=xpos>>16;
  1179. if((i&3) == 0)
  1180. {
  1181. int a=0;
  1182. int b=((xpos+s_xinc2)>>16) - xx;
  1183. int c=((xpos+s_xinc2*2)>>16) - xx;
  1184. int d=((xpos+s_xinc2*3)>>16) - xx;
  1185. memcpy(funnyUVCode + fragmentLength*i/4, fragment, fragmentLength);
  1186. funnyUVCode[fragmentLength*i/4 + imm8OfPShufW1]=
  1187. funnyUVCode[fragmentLength*i/4 + imm8OfPShufW2]=
  1188. a | (b<<2) | (c<<4) | (d<<6);
  1189. // if we dont need to read 8 bytes than dont :), reduces the chance of
  1190. // crossing a cache line
  1191. if(d<3) funnyUVCode[fragmentLength*i/4 + 1]= 0x6E;
  1192. funnyUVCode[fragmentLength*(i+4)/4]= RET;
  1193. }
  1194. xpos+=s_xinc2;
  1195. }
  1196. // funnyCode[0]= RET;
  1197. }
  1198. #endif // HAVE_MMX2
  1199. } // reset counters
  1200. while(1){
  1201. unsigned char *dest =dstptr[0]+dststride*s_ypos;
  1202. unsigned char *uDest=dstptr[1]+(dststride>>1)*(s_ypos>>1);
  1203. unsigned char *vDest=dstptr[2]+(dststride>>1)*(s_ypos>>1);
  1204. int y0=(s_srcypos + 0xFFFF)>>16; // first luminance source line number below the dst line
  1205. // points to the dst Pixels center in the source (0 is the center of pixel 0,0 in src)
  1206. int srcuvpos= dstbpp==12 ? s_srcypos + s_yinc/2 - 0x8000 :
  1207. s_srcypos - 0x8000;
  1208. int y1=(srcuvpos + 0x1FFFF)>>17; // first chrominance source line number below the dst line
  1209. int yalpha=((s_srcypos-1)&0xFFFF)>>4;
  1210. int uvalpha=((srcuvpos-1)&0x1FFFF)>>5;
  1211. uint16_t *buf0=pix_buf_y[y0&1]; // top line of the interpolated slice
  1212. uint16_t *buf1=pix_buf_y[((y0+1)&1)]; // bottom line of the interpolated slice
  1213. uint16_t *uvbuf0=pix_buf_uv[y1&1]; // top line of the interpolated slice
  1214. uint16_t *uvbuf1=pix_buf_uv[(y1+1)&1]; // bottom line of the interpolated slice
  1215. int i;
  1216. if(y0>=y+h) break; // FIXME wrong, skips last lines, but they are dupliactes anyway
  1217. if((y0&1) && dstbpp==12) uvalpha=-1; // there is no alpha if there is no line
  1218. s_ypos++; s_srcypos+=s_yinc;
  1219. //only interpolate the src line horizontally if we didnt do it allready
  1220. if(s_last_ypos!=y0)
  1221. {
  1222. unsigned char *src;
  1223. // skip if first line has been horiz scaled alleady
  1224. if(s_last_ypos != y0-1)
  1225. {
  1226. // check if first line is before any available src lines
  1227. if(y0-1 < y) src=srcptr[0]+(0 )*stride[0];
  1228. else src=srcptr[0]+(y0-y-1)*stride[0];
  1229. hyscale(buf0, dstw, src, srcWidth, s_xinc);
  1230. }
  1231. // check if second line is after any available src lines
  1232. if(y0-y >= h) src=srcptr[0]+(h-1)*stride[0];
  1233. else src=srcptr[0]+(y0-y)*stride[0];
  1234. // the min() is required to avoid reuseing lines which where not available
  1235. s_last_ypos= MIN(y0, y+h-1);
  1236. hyscale(buf1, dstw, src, srcWidth, s_xinc);
  1237. }
  1238. // printf("%d %d %d %d\n", y, y1, s_last_y1pos, h);
  1239. // *** horizontal scale U and V lines to temp buffer
  1240. if(s_last_y1pos!=y1)
  1241. {
  1242. uint8_t *src1, *src2;
  1243. // skip if first line has been horiz scaled alleady
  1244. if(s_last_y1pos != y1-1)
  1245. {
  1246. // check if first line is before any available src lines
  1247. if(y1-y/2-1 < 0)
  1248. {
  1249. src1= srcptr[1]+(0)*stride[1];
  1250. src2= srcptr[2]+(0)*stride[2];
  1251. }else{
  1252. src1= srcptr[1]+(y1-y/2-1)*stride[1];
  1253. src2= srcptr[2]+(y1-y/2-1)*stride[2];
  1254. }
  1255. hcscale(uvbuf0, dstUVw, src1, src2, srcWidth, s_xinc2);
  1256. }
  1257. // check if second line is after any available src lines
  1258. if(y1 - y/2 >= h/2)
  1259. {
  1260. src1= srcptr[1]+(h/2-1)*stride[1];
  1261. src2= srcptr[2]+(h/2-1)*stride[2];
  1262. }else{
  1263. src1= srcptr[1]+(y1-y/2)*stride[1];
  1264. src2= srcptr[2]+(y1-y/2)*stride[2];
  1265. }
  1266. hcscale(uvbuf1, dstUVw, src1, src2, srcWidth, s_xinc2);
  1267. // the min() is required to avoid reuseing lines which where not available
  1268. s_last_y1pos= MIN(y1, y/2+h/2-1);
  1269. }
  1270. if(dstbpp==12) //YV12
  1271. yuv2yuv(buf0, buf1, uvbuf0, uvbuf1, dest, uDest, vDest, dstw, yalpha, uvalpha);
  1272. else if(ABS(s_yinc - 0x10000) < 10)
  1273. yuv2rgb1(buf0, buf1, uvbuf0, uvbuf1, dest, dstw, yalpha, uvalpha, dstbpp);
  1274. else
  1275. yuv2rgbX(buf0, buf1, uvbuf0, uvbuf1, dest, dstw, yalpha, uvalpha, dstbpp);
  1276. #ifdef HAVE_MMX
  1277. b16Dither= b16Dither1;
  1278. b16Dither1= b16Dither2;
  1279. b16Dither2= b16Dither;
  1280. g16Dither= g16Dither1;
  1281. g16Dither1= g16Dither2;
  1282. g16Dither2= g16Dither;
  1283. #endif
  1284. }
  1285. #ifdef HAVE_MMX
  1286. __asm __volatile(SFENCE:::"memory");
  1287. __asm __volatile(EMMS);
  1288. #endif
  1289. }
  1290. void SwScale_Init(){
  1291. // generating tables:
  1292. int i;
  1293. for(i=0;i<256;i++){
  1294. clip_table[i]=0;
  1295. clip_table[i+256]=i;
  1296. clip_table[i+512]=255;
  1297. yuvtab_2568[i]=(0x2568*(i-16))+(256<<13);
  1298. yuvtab_3343[i]=0x3343*(i-128);
  1299. yuvtab_0c92[i]=-0x0c92*(i-128);
  1300. yuvtab_1a1e[i]=-0x1a1e*(i-128);
  1301. yuvtab_40cf[i]=0x40cf*(i-128);
  1302. }
  1303. }