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.

1823 lines
54KB

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