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.

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