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.

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