2 // Software scaling and colorspace conversion routines for MPlayer
4 // Orginal C implementation by A'rpi/ESP-team <arpi@thot.banki.hu>
5 // current version mostly by Michael Niedermayer (michaelni@gmx.at)
6 // the parts written by michael are under GNU GPL
10 #include "../config.h"
12 #include "../mmx_defs.h"
21 //disables the unscaled height version
24 #define RET 0xC3 //near return opcode
28 known BUGS with known cause (no bugreports please!, but patches are welcome :) )
29 horizontal MMX2 scaler reads 1-7 samples too much (might cause a sig11)
31 Supported output formats BGR15 BGR16 BGR24 BGR32
32 BGR15 & BGR16 MMX verions support dithering
33 Special versions: fast Y 1:1 scaling (no interpolation in y direction)
36 more intelligent missalignment avoidance for the horizontal scaler
39 change the distance of the u & v buffer
42 #define ABS(a) ((a) > 0 ? (a) : (-(a)))
43 #define MIN(a,b) ((a) > (b) ? (b) : (a))
44 #define MAX(a,b) ((a) < (b) ? (b) : (a))
47 #define PAVGB(a,b) "pavgb " #a ", " #b " \n\t"
48 #elif defined (HAVE_3DNOW)
49 #define PAVGB(a,b) "pavgusb " #a ", " #b " \n\t"
53 #define MOVNTQ(a,b) "movntq " #a ", " #b " \n\t"
55 #define MOVNTQ(a,b) "movq " #a ", " #b " \n\t"
60 static uint64_t __attribute__((aligned(8))) yCoeff= 0x2568256825682568LL;
61 static uint64_t __attribute__((aligned(8))) vrCoeff= 0x3343334333433343LL;
62 static uint64_t __attribute__((aligned(8))) ubCoeff= 0x40cf40cf40cf40cfLL;
63 static uint64_t __attribute__((aligned(8))) vgCoeff= 0xE5E2E5E2E5E2E5E2LL;
64 static uint64_t __attribute__((aligned(8))) ugCoeff= 0xF36EF36EF36EF36ELL;
65 static uint64_t __attribute__((aligned(8))) bF8= 0xF8F8F8F8F8F8F8F8LL;
66 static uint64_t __attribute__((aligned(8))) bFC= 0xFCFCFCFCFCFCFCFCLL;
67 static uint64_t __attribute__((aligned(8))) w400= 0x0400040004000400LL;
68 static uint64_t __attribute__((aligned(8))) w80= 0x0080008000800080LL;
69 static uint64_t __attribute__((aligned(8))) w10= 0x0010001000100010LL;
70 static uint64_t __attribute__((aligned(8))) bm00001111=0x00000000FFFFFFFFLL;
71 static uint64_t __attribute__((aligned(8))) bm00000111=0x0000000000FFFFFFLL;
72 static uint64_t __attribute__((aligned(8))) bm11111000=0xFFFFFFFFFF000000LL;
74 static uint64_t __attribute__((aligned(8))) b16Dither= 0x0004000400040004LL;
75 static uint64_t __attribute__((aligned(8))) b16Dither1=0x0004000400040004LL;
76 static uint64_t __attribute__((aligned(8))) b16Dither2=0x0602060206020602LL;
77 static uint64_t __attribute__((aligned(8))) g16Dither= 0x0002000200020002LL;
78 static uint64_t __attribute__((aligned(8))) g16Dither1=0x0002000200020002LL;
79 static uint64_t __attribute__((aligned(8))) g16Dither2=0x0301030103010301LL;
81 static uint64_t __attribute__((aligned(8))) b16Mask= 0x001F001F001F001FLL;
82 static uint64_t __attribute__((aligned(8))) g16Mask= 0x07E007E007E007E0LL;
83 static uint64_t __attribute__((aligned(8))) r16Mask= 0xF800F800F800F800LL;
84 static uint64_t __attribute__((aligned(8))) b15Mask= 0x001F001F001F001FLL;
85 static uint64_t __attribute__((aligned(8))) g15Mask= 0x03E003E003E003E0LL;
86 static uint64_t __attribute__((aligned(8))) r15Mask= 0x7C007C007C007C00LL;
88 static uint64_t __attribute__((aligned(8))) temp0;
89 static uint64_t __attribute__((aligned(8))) asm_yalpha1;
90 static uint64_t __attribute__((aligned(8))) asm_uvalpha1;
93 // temporary storage for 4 yuv lines:
94 // 16bit for now (mmx likes it more compact)
96 static uint16_t __attribute__((aligned(8))) pix_buf_y[4][2048];
97 static uint16_t __attribute__((aligned(8))) pix_buf_uv[2][2048*2];
99 static uint16_t pix_buf_y[4][2048];
100 static uint16_t pix_buf_uv[2][2048*2];
103 // clipping helper table for C implementations:
104 static unsigned char clip_table[768];
106 static unsigned short clip_table16b[768];
107 static unsigned short clip_table16g[768];
108 static unsigned short clip_table16r[768];
109 static unsigned short clip_table15b[768];
110 static unsigned short clip_table15g[768];
111 static unsigned short clip_table15r[768];
113 // yuv->rgb conversion tables:
114 static int yuvtab_2568[256];
115 static int yuvtab_3343[256];
116 static int yuvtab_0c92[256];
117 static int yuvtab_1a1e[256];
118 static int yuvtab_40cf[256];
121 static uint8_t funnyYCode[10000];
122 static uint8_t funnyUVCode[10000];
125 static int canMMX2BeUsed=0;
127 #define FULL_YSCALEYUV2RGB \
128 "pxor %%mm7, %%mm7 \n\t"\
129 "movd %6, %%mm6 \n\t" /*yalpha1*/\
130 "punpcklwd %%mm6, %%mm6 \n\t"\
131 "punpcklwd %%mm6, %%mm6 \n\t"\
132 "movd %7, %%mm5 \n\t" /*uvalpha1*/\
133 "punpcklwd %%mm5, %%mm5 \n\t"\
134 "punpcklwd %%mm5, %%mm5 \n\t"\
135 "xorl %%eax, %%eax \n\t"\
137 "movq (%0, %%eax, 2), %%mm0 \n\t" /*buf0[eax]*/\
138 "movq (%1, %%eax, 2), %%mm1 \n\t" /*buf1[eax]*/\
139 "movq (%2, %%eax,2), %%mm2 \n\t" /* uvbuf0[eax]*/\
140 "movq (%3, %%eax,2), %%mm3 \n\t" /* uvbuf1[eax]*/\
141 "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\
142 "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\
143 "pmulhw %%mm6, %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
144 "pmulhw %%mm5, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\
145 "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
146 "movq 4096(%2, %%eax,2), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\
147 "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
148 "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
149 "movq 4096(%3, %%eax,2), %%mm0 \n\t" /* uvbuf1[eax+2048]*/\
150 "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\
151 "psubw %%mm0, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\
152 "psubw w80, %%mm1 \n\t" /* 8(Y-16)*/\
153 "psubw w400, %%mm3 \n\t" /* 8(U-128)*/\
154 "pmulhw yCoeff, %%mm1 \n\t"\
157 "pmulhw %%mm5, %%mm4 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\
158 "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
159 "pmulhw ubCoeff, %%mm3 \n\t"\
160 "psraw $4, %%mm0 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
161 "pmulhw ugCoeff, %%mm2 \n\t"\
162 "paddw %%mm4, %%mm0 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\
163 "psubw w400, %%mm0 \n\t" /* (V-128)8*/\
166 "movq %%mm0, %%mm4 \n\t" /* (V-128)8*/\
167 "pmulhw vrCoeff, %%mm0 \n\t"\
168 "pmulhw vgCoeff, %%mm4 \n\t"\
169 "paddw %%mm1, %%mm3 \n\t" /* B*/\
170 "paddw %%mm1, %%mm0 \n\t" /* R*/\
171 "packuswb %%mm3, %%mm3 \n\t"\
173 "packuswb %%mm0, %%mm0 \n\t"\
174 "paddw %%mm4, %%mm2 \n\t"\
175 "paddw %%mm2, %%mm1 \n\t" /* G*/\
177 "packuswb %%mm1, %%mm1 \n\t"
179 #define YSCALEYUV2RGB \
180 "movd %6, %%mm6 \n\t" /*yalpha1*/\
181 "punpcklwd %%mm6, %%mm6 \n\t"\
182 "punpcklwd %%mm6, %%mm6 \n\t"\
183 "movq %%mm6, asm_yalpha1 \n\t"\
184 "movd %7, %%mm5 \n\t" /*uvalpha1*/\
185 "punpcklwd %%mm5, %%mm5 \n\t"\
186 "punpcklwd %%mm5, %%mm5 \n\t"\
187 "movq %%mm5, asm_uvalpha1 \n\t"\
188 "xorl %%eax, %%eax \n\t"\
190 "movq (%2, %%eax), %%mm2 \n\t" /* uvbuf0[eax]*/\
191 "movq (%3, %%eax), %%mm3 \n\t" /* uvbuf1[eax]*/\
192 "movq 4096(%2, %%eax), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
193 "movq 4096(%3, %%eax), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
194 "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\
195 "psubw %%mm4, %%mm5 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\
196 "movq asm_uvalpha1, %%mm0 \n\t"\
197 "pmulhw %%mm0, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\
198 "pmulhw %%mm0, %%mm5 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\
199 "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
200 "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
201 "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\
202 "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\
203 "psubw w400, %%mm3 \n\t" /* (U-128)8*/\
204 "psubw w400, %%mm4 \n\t" /* (V-128)8*/\
205 "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
206 "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
207 "pmulhw ugCoeff, %%mm3 \n\t"\
208 "pmulhw vgCoeff, %%mm4 \n\t"\
209 /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
210 "movq (%0, %%eax, 2), %%mm0 \n\t" /*buf0[eax]*/\
211 "movq (%1, %%eax, 2), %%mm1 \n\t" /*buf1[eax]*/\
212 "movq 8(%0, %%eax, 2), %%mm6 \n\t" /*buf0[eax]*/\
213 "movq 8(%1, %%eax, 2), %%mm7 \n\t" /*buf1[eax]*/\
214 "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\
215 "psubw %%mm7, %%mm6 \n\t" /* buf0[eax] - buf1[eax]*/\
216 "pmulhw asm_yalpha1, %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
217 "pmulhw asm_yalpha1, %%mm6 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
218 "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
219 "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
220 "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
221 "paddw %%mm6, %%mm7 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
222 "pmulhw ubCoeff, %%mm2 \n\t"\
223 "pmulhw vrCoeff, %%mm5 \n\t"\
224 "psubw w80, %%mm1 \n\t" /* 8(Y-16)*/\
225 "psubw w80, %%mm7 \n\t" /* 8(Y-16)*/\
226 "pmulhw yCoeff, %%mm1 \n\t"\
227 "pmulhw yCoeff, %%mm7 \n\t"\
228 /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
229 "paddw %%mm3, %%mm4 \n\t"\
230 "movq %%mm2, %%mm0 \n\t"\
231 "movq %%mm5, %%mm6 \n\t"\
232 "movq %%mm4, %%mm3 \n\t"\
233 "punpcklwd %%mm2, %%mm2 \n\t"\
234 "punpcklwd %%mm5, %%mm5 \n\t"\
235 "punpcklwd %%mm4, %%mm4 \n\t"\
236 "paddw %%mm1, %%mm2 \n\t"\
237 "paddw %%mm1, %%mm5 \n\t"\
238 "paddw %%mm1, %%mm4 \n\t"\
239 "punpckhwd %%mm0, %%mm0 \n\t"\
240 "punpckhwd %%mm6, %%mm6 \n\t"\
241 "punpckhwd %%mm3, %%mm3 \n\t"\
242 "paddw %%mm7, %%mm0 \n\t"\
243 "paddw %%mm7, %%mm6 \n\t"\
244 "paddw %%mm7, %%mm3 \n\t"\
245 /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
246 "packuswb %%mm0, %%mm2 \n\t"\
247 "packuswb %%mm6, %%mm5 \n\t"\
248 "packuswb %%mm3, %%mm4 \n\t"\
249 "pxor %%mm7, %%mm7 \n\t"
251 #define YSCALEYUV2RGB1 \
252 "xorl %%eax, %%eax \n\t"\
254 "movq (%2, %%eax), %%mm3 \n\t" /* uvbuf0[eax]*/\
255 "movq 4096(%2, %%eax), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\
256 "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\
257 "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\
258 "psubw w400, %%mm3 \n\t" /* (U-128)8*/\
259 "psubw w400, %%mm4 \n\t" /* (V-128)8*/\
260 "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
261 "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
262 "pmulhw ugCoeff, %%mm3 \n\t"\
263 "pmulhw vgCoeff, %%mm4 \n\t"\
264 /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
265 "movq (%0, %%eax, 2), %%mm1 \n\t" /*buf0[eax]*/\
266 "movq 8(%0, %%eax, 2), %%mm7 \n\t" /*buf0[eax]*/\
267 "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
268 "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
269 "pmulhw ubCoeff, %%mm2 \n\t"\
270 "pmulhw vrCoeff, %%mm5 \n\t"\
271 "psubw w80, %%mm1 \n\t" /* 8(Y-16)*/\
272 "psubw w80, %%mm7 \n\t" /* 8(Y-16)*/\
273 "pmulhw yCoeff, %%mm1 \n\t"\
274 "pmulhw yCoeff, %%mm7 \n\t"\
275 /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
276 "paddw %%mm3, %%mm4 \n\t"\
277 "movq %%mm2, %%mm0 \n\t"\
278 "movq %%mm5, %%mm6 \n\t"\
279 "movq %%mm4, %%mm3 \n\t"\
280 "punpcklwd %%mm2, %%mm2 \n\t"\
281 "punpcklwd %%mm5, %%mm5 \n\t"\
282 "punpcklwd %%mm4, %%mm4 \n\t"\
283 "paddw %%mm1, %%mm2 \n\t"\
284 "paddw %%mm1, %%mm5 \n\t"\
285 "paddw %%mm1, %%mm4 \n\t"\
286 "punpckhwd %%mm0, %%mm0 \n\t"\
287 "punpckhwd %%mm6, %%mm6 \n\t"\
288 "punpckhwd %%mm3, %%mm3 \n\t"\
289 "paddw %%mm7, %%mm0 \n\t"\
290 "paddw %%mm7, %%mm6 \n\t"\
291 "paddw %%mm7, %%mm3 \n\t"\
292 /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
293 "packuswb %%mm0, %%mm2 \n\t"\
294 "packuswb %%mm6, %%mm5 \n\t"\
295 "packuswb %%mm3, %%mm4 \n\t"\
296 "pxor %%mm7, %%mm7 \n\t"
298 // do vertical chrominance interpolation
299 #define YSCALEYUV2RGB1b \
300 "xorl %%eax, %%eax \n\t"\
302 "movq (%2, %%eax), %%mm2 \n\t" /* uvbuf0[eax]*/\
303 "movq (%3, %%eax), %%mm3 \n\t" /* uvbuf1[eax]*/\
304 "movq 4096(%2, %%eax), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\
305 "movq 4096(%3, %%eax), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\
306 "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\
307 "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\
308 "psrlw $5, %%mm3 \n\t"\
309 "psrlw $5, %%mm4 \n\t"\
310 "psubw w400, %%mm3 \n\t" /* (U-128)8*/\
311 "psubw w400, %%mm4 \n\t" /* (V-128)8*/\
312 "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
313 "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\
314 "pmulhw ugCoeff, %%mm3 \n\t"\
315 "pmulhw vgCoeff, %%mm4 \n\t"\
316 /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\
317 "movq (%0, %%eax, 2), %%mm1 \n\t" /*buf0[eax]*/\
318 "movq 8(%0, %%eax, 2), %%mm7 \n\t" /*buf0[eax]*/\
319 "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
320 "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\
321 "pmulhw ubCoeff, %%mm2 \n\t"\
322 "pmulhw vrCoeff, %%mm5 \n\t"\
323 "psubw w80, %%mm1 \n\t" /* 8(Y-16)*/\
324 "psubw w80, %%mm7 \n\t" /* 8(Y-16)*/\
325 "pmulhw yCoeff, %%mm1 \n\t"\
326 "pmulhw yCoeff, %%mm7 \n\t"\
327 /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\
328 "paddw %%mm3, %%mm4 \n\t"\
329 "movq %%mm2, %%mm0 \n\t"\
330 "movq %%mm5, %%mm6 \n\t"\
331 "movq %%mm4, %%mm3 \n\t"\
332 "punpcklwd %%mm2, %%mm2 \n\t"\
333 "punpcklwd %%mm5, %%mm5 \n\t"\
334 "punpcklwd %%mm4, %%mm4 \n\t"\
335 "paddw %%mm1, %%mm2 \n\t"\
336 "paddw %%mm1, %%mm5 \n\t"\
337 "paddw %%mm1, %%mm4 \n\t"\
338 "punpckhwd %%mm0, %%mm0 \n\t"\
339 "punpckhwd %%mm6, %%mm6 \n\t"\
340 "punpckhwd %%mm3, %%mm3 \n\t"\
341 "paddw %%mm7, %%mm0 \n\t"\
342 "paddw %%mm7, %%mm6 \n\t"\
343 "paddw %%mm7, %%mm3 \n\t"\
344 /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\
345 "packuswb %%mm0, %%mm2 \n\t"\
346 "packuswb %%mm6, %%mm5 \n\t"\
347 "packuswb %%mm3, %%mm4 \n\t"\
348 "pxor %%mm7, %%mm7 \n\t"
351 /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\
352 "movq %%mm2, %%mm1 \n\t" /* B */\
353 "movq %%mm5, %%mm6 \n\t" /* R */\
354 "punpcklbw %%mm4, %%mm2 \n\t" /* GBGBGBGB 0 */\
355 "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R 0 */\
356 "punpckhbw %%mm4, %%mm1 \n\t" /* GBGBGBGB 2 */\
357 "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R 2 */\
358 "movq %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */\
359 "movq %%mm1, %%mm3 \n\t" /* GBGBGBGB 2 */\
360 "punpcklwd %%mm5, %%mm0 \n\t" /* 0RGB0RGB 0 */\
361 "punpckhwd %%mm5, %%mm2 \n\t" /* 0RGB0RGB 1 */\
362 "punpcklwd %%mm6, %%mm1 \n\t" /* 0RGB0RGB 2 */\
363 "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\
365 MOVNTQ(%%mm0, (%4, %%eax, 4))\
366 MOVNTQ(%%mm2, 8(%4, %%eax, 4))\
367 MOVNTQ(%%mm1, 16(%4, %%eax, 4))\
368 MOVNTQ(%%mm3, 24(%4, %%eax, 4))\
370 "addl $8, %%eax \n\t"\
371 "cmpl %5, %%eax \n\t"\
375 "pand bF8, %%mm2 \n\t" /* B */\
376 "pand bFC, %%mm4 \n\t" /* G */\
377 "pand bF8, %%mm5 \n\t" /* R */\
378 "psrlq $3, %%mm2 \n\t"\
380 "movq %%mm2, %%mm1 \n\t"\
381 "movq %%mm4, %%mm3 \n\t"\
383 "punpcklbw %%mm7, %%mm3 \n\t"\
384 "punpcklbw %%mm5, %%mm2 \n\t"\
385 "punpckhbw %%mm7, %%mm4 \n\t"\
386 "punpckhbw %%mm5, %%mm1 \n\t"\
388 "psllq $3, %%mm3 \n\t"\
389 "psllq $3, %%mm4 \n\t"\
391 "por %%mm3, %%mm2 \n\t"\
392 "por %%mm4, %%mm1 \n\t"\
394 MOVNTQ(%%mm2, (%4, %%eax, 2))\
395 MOVNTQ(%%mm1, 8(%4, %%eax, 2))\
397 "addl $8, %%eax \n\t"\
398 "cmpl %5, %%eax \n\t"\
402 "pand bF8, %%mm2 \n\t" /* B */\
403 "pand bF8, %%mm4 \n\t" /* G */\
404 "pand bF8, %%mm5 \n\t" /* R */\
405 "psrlq $3, %%mm2 \n\t"\
406 "psrlq $1, %%mm5 \n\t"\
408 "movq %%mm2, %%mm1 \n\t"\
409 "movq %%mm4, %%mm3 \n\t"\
411 "punpcklbw %%mm7, %%mm3 \n\t"\
412 "punpcklbw %%mm5, %%mm2 \n\t"\
413 "punpckhbw %%mm7, %%mm4 \n\t"\
414 "punpckhbw %%mm5, %%mm1 \n\t"\
416 "psllq $2, %%mm3 \n\t"\
417 "psllq $2, %%mm4 \n\t"\
419 "por %%mm3, %%mm2 \n\t"\
420 "por %%mm4, %%mm1 \n\t"\
422 MOVNTQ(%%mm2, (%4, %%eax, 2))\
423 MOVNTQ(%%mm1, 8(%4, %%eax, 2))\
425 "addl $8, %%eax \n\t"\
426 "cmpl %5, %%eax \n\t"\
429 // FIXME find a faster way to shuffle it to BGR24
431 /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\
432 "movq %%mm2, %%mm1 \n\t" /* B */\
433 "movq %%mm5, %%mm6 \n\t" /* R */\
434 "punpcklbw %%mm4, %%mm2 \n\t" /* GBGBGBGB 0 */\
435 "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R 0 */\
436 "punpckhbw %%mm4, %%mm1 \n\t" /* GBGBGBGB 2 */\
437 "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R 2 */\
438 "movq %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */\
439 "movq %%mm1, %%mm3 \n\t" /* GBGBGBGB 2 */\
440 "punpcklwd %%mm5, %%mm0 \n\t" /* 0RGB0RGB 0 */\
441 "punpckhwd %%mm5, %%mm2 \n\t" /* 0RGB0RGB 1 */\
442 "punpcklwd %%mm6, %%mm1 \n\t" /* 0RGB0RGB 2 */\
443 "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\
445 "movq %%mm0, %%mm4 \n\t" /* 0RGB0RGB 0 */\
446 "psrlq $8, %%mm0 \n\t" /* 00RGB0RG 0 */\
447 "pand bm00000111, %%mm4 \n\t" /* 00000RGB 0 */\
448 "pand bm11111000, %%mm0 \n\t" /* 00RGB000 0.5 */\
449 "por %%mm4, %%mm0 \n\t" /* 00RGBRGB 0 */\
450 "movq %%mm2, %%mm4 \n\t" /* 0RGB0RGB 1 */\
451 "psllq $48, %%mm2 \n\t" /* GB000000 1 */\
452 "por %%mm2, %%mm0 \n\t" /* GBRGBRGB 0 */\
454 "movq %%mm4, %%mm2 \n\t" /* 0RGB0RGB 1 */\
455 "psrld $16, %%mm4 \n\t" /* 000R000R 1 */\
456 "psrlq $24, %%mm2 \n\t" /* 0000RGB0 1.5 */\
457 "por %%mm4, %%mm2 \n\t" /* 000RRGBR 1 */\
458 "pand bm00001111, %%mm2 \n\t" /* 0000RGBR 1 */\
459 "movq %%mm1, %%mm4 \n\t" /* 0RGB0RGB 2 */\
460 "psrlq $8, %%mm1 \n\t" /* 00RGB0RG 2 */\
461 "pand bm00000111, %%mm4 \n\t" /* 00000RGB 2 */\
462 "pand bm11111000, %%mm1 \n\t" /* 00RGB000 2.5 */\
463 "por %%mm4, %%mm1 \n\t" /* 00RGBRGB 2 */\
464 "movq %%mm1, %%mm4 \n\t" /* 00RGBRGB 2 */\
465 "psllq $32, %%mm1 \n\t" /* BRGB0000 2 */\
466 "por %%mm1, %%mm2 \n\t" /* BRGBRGBR 1 */\
468 "psrlq $32, %%mm4 \n\t" /* 000000RG 2.5 */\
469 "movq %%mm3, %%mm5 \n\t" /* 0RGB0RGB 3 */\
470 "psrlq $8, %%mm3 \n\t" /* 00RGB0RG 3 */\
471 "pand bm00000111, %%mm5 \n\t" /* 00000RGB 3 */\
472 "pand bm11111000, %%mm3 \n\t" /* 00RGB000 3.5 */\
473 "por %%mm5, %%mm3 \n\t" /* 00RGBRGB 3 */\
474 "psllq $16, %%mm3 \n\t" /* RGBRGB00 3 */\
475 "por %%mm4, %%mm3 \n\t" /* RGBRGBRG 2.5 */\
477 MOVNTQ(%%mm0, (%%ebx))\
478 MOVNTQ(%%mm2, 8(%%ebx))\
479 MOVNTQ(%%mm3, 16(%%ebx))\
480 "addl $24, %%ebx \n\t"\
482 "addl $8, %%eax \n\t"\
483 "cmpl %5, %%eax \n\t"\
487 void in_asm_used_var_warning_killer()
489 int i= yCoeff+vrCoeff+ubCoeff+vgCoeff+ugCoeff+bF8+bFC+w400+w80+w10+
490 bm00001111+bm00000111+bm11111000+b16Dither+b16Dither1+b16Dither2+g16Dither+g16Dither1+
491 g16Dither2+b16Mask+g16Mask+r16Mask+b15Mask+g15Mask+r15Mask+temp0+asm_yalpha1+ asm_uvalpha1;
496 static inline void yuv2yuv(uint16_t *buf0, uint16_t *buf1, uint16_t *uvbuf0, uint16_t *uvbuf1,
497 uint8_t *dest, uint8_t *uDest, uint8_t *vDest, int dstw, int yalpha, int uvalpha)
499 int yalpha1=yalpha^4095;
500 int uvalpha1=uvalpha^4095;
503 asm volatile ("\n\t"::: "memory");
507 ((uint8_t*)dest)[i] = (buf0[i]*yalpha1+buf1[i]*yalpha)>>19;
512 for(i=0; i<(dstw>>1); i++)
514 ((uint8_t*)uDest)[i] = (uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19;
515 ((uint8_t*)vDest)[i] = (uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19;
521 * vertical scale YV12 to RGB
523 static inline void yuv2rgbX(uint16_t *buf0, uint16_t *buf1, uint16_t *uvbuf0, uint16_t *uvbuf1,
524 uint8_t *dest, int dstw, int yalpha, int uvalpha, int dstbpp)
526 int yalpha1=yalpha^4095;
527 int uvalpha1=uvalpha^4095;
539 "punpcklbw %%mm1, %%mm3 \n\t" // BGBGBGBG
540 "punpcklbw %%mm7, %%mm0 \n\t" // R0R0R0R0
542 "movq %%mm3, %%mm1 \n\t"
543 "punpcklwd %%mm0, %%mm3 \n\t" // BGR0BGR0
544 "punpckhwd %%mm0, %%mm1 \n\t" // BGR0BGR0
546 MOVNTQ(%%mm3, (%4, %%eax, 4))
547 MOVNTQ(%%mm1, 8(%4, %%eax, 4))
549 "addl $4, %%eax \n\t"
550 "cmpl %5, %%eax \n\t"
554 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
555 "m" (yalpha1), "m" (uvalpha1)
566 "punpcklbw %%mm1, %%mm3 \n\t" // BGBGBGBG
567 "punpcklbw %%mm7, %%mm0 \n\t" // R0R0R0R0
569 "movq %%mm3, %%mm1 \n\t"
570 "punpcklwd %%mm0, %%mm3 \n\t" // BGR0BGR0
571 "punpckhwd %%mm0, %%mm1 \n\t" // BGR0BGR0
573 "movq %%mm3, %%mm2 \n\t" // BGR0BGR0
574 "psrlq $8, %%mm3 \n\t" // GR0BGR00
575 "pand bm00000111, %%mm2 \n\t" // BGR00000
576 "pand bm11111000, %%mm3 \n\t" // 000BGR00
577 "por %%mm2, %%mm3 \n\t" // BGRBGR00
578 "movq %%mm1, %%mm2 \n\t"
579 "psllq $48, %%mm1 \n\t" // 000000BG
580 "por %%mm1, %%mm3 \n\t" // BGRBGRBG
582 "movq %%mm2, %%mm1 \n\t" // BGR0BGR0
583 "psrld $16, %%mm2 \n\t" // R000R000
584 "psrlq $24, %%mm1 \n\t" // 0BGR0000
585 "por %%mm2, %%mm1 \n\t" // RBGRR000
587 "movl %4, %%ebx \n\t"
588 "addl %%eax, %%ebx \n\t"
592 "movntq %%mm3, (%%ebx, %%eax, 2)\n\t"
593 "movntq %%mm1, 8(%%ebx, %%eax, 2)\n\t"
595 "movd %%mm3, (%%ebx, %%eax, 2) \n\t"
596 "psrlq $32, %%mm3 \n\t"
597 "movd %%mm3, 4(%%ebx, %%eax, 2) \n\t"
598 "movd %%mm1, 8(%%ebx, %%eax, 2) \n\t"
600 "addl $4, %%eax \n\t"
601 "cmpl %5, %%eax \n\t"
604 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "m" (dest), "m" (dstw),
605 "m" (yalpha1), "m" (uvalpha1)
615 "paddusb b16Dither, %%mm1 \n\t"
616 "paddusb b16Dither, %%mm0 \n\t"
617 "paddusb b16Dither, %%mm3 \n\t"
619 "punpcklbw %%mm7, %%mm1 \n\t" // 0G0G0G0G
620 "punpcklbw %%mm7, %%mm3 \n\t" // 0B0B0B0B
621 "punpcklbw %%mm7, %%mm0 \n\t" // 0R0R0R0R
623 "psrlw $3, %%mm3 \n\t"
624 "psllw $2, %%mm1 \n\t"
625 "psllw $7, %%mm0 \n\t"
626 "pand g15Mask, %%mm1 \n\t"
627 "pand r15Mask, %%mm0 \n\t"
629 "por %%mm3, %%mm1 \n\t"
630 "por %%mm1, %%mm0 \n\t"
632 MOVNTQ(%%mm0, (%4, %%eax, 2))
634 "addl $4, %%eax \n\t"
635 "cmpl %5, %%eax \n\t"
638 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
639 "m" (yalpha1), "m" (uvalpha1)
649 "paddusb g16Dither, %%mm1 \n\t"
650 "paddusb b16Dither, %%mm0 \n\t"
651 "paddusb b16Dither, %%mm3 \n\t"
653 "punpcklbw %%mm7, %%mm1 \n\t" // 0G0G0G0G
654 "punpcklbw %%mm7, %%mm3 \n\t" // 0B0B0B0B
655 "punpcklbw %%mm7, %%mm0 \n\t" // 0R0R0R0R
657 "psrlw $3, %%mm3 \n\t"
658 "psllw $3, %%mm1 \n\t"
659 "psllw $8, %%mm0 \n\t"
660 "pand g16Mask, %%mm1 \n\t"
661 "pand r16Mask, %%mm0 \n\t"
663 "por %%mm3, %%mm1 \n\t"
664 "por %%mm1, %%mm0 \n\t"
666 MOVNTQ(%%mm0, (%4, %%eax, 2))
668 "addl $4, %%eax \n\t"
669 "cmpl %5, %%eax \n\t"
672 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
673 "m" (yalpha1), "m" (uvalpha1)
678 asm volatile ("\n\t"::: "memory");
680 if(dstbpp==32 || dstbpp==24)
684 // vertical linear interpolation && yuv2rgb in a single step:
685 int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
686 int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19);
687 int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19);
688 dest[0]=clip_table[((Y + yuvtab_40cf[U]) >>13)];
689 dest[1]=clip_table[((Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13)];
690 dest[2]=clip_table[((Y + yuvtab_3343[V]) >>13)];
698 // vertical linear interpolation && yuv2rgb in a single step:
699 int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
700 int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19);
701 int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19);
703 ((uint16_t*)dest)[i] =
704 clip_table16b[(Y + yuvtab_40cf[U]) >>13] |
705 clip_table16g[(Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13] |
706 clip_table16r[(Y + yuvtab_3343[V]) >>13];
713 // vertical linear interpolation && yuv2rgb in a single step:
714 int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
715 int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19);
716 int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19);
718 ((uint16_t*)dest)[i] =
719 clip_table15b[(Y + yuvtab_40cf[U]) >>13] |
720 clip_table15g[(Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13] |
721 clip_table15r[(Y + yuvtab_3343[V]) >>13];
735 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
736 "m" (yalpha1), "m" (uvalpha1)
743 "movl %4, %%ebx \n\t"
747 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "m" (dest), "m" (dstw),
748 "m" (yalpha1), "m" (uvalpha1)
756 /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
758 "paddusb b16Dither, %%mm2 \n\t"
759 "paddusb b16Dither, %%mm4 \n\t"
760 "paddusb b16Dither, %%mm5 \n\t"
765 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
766 "m" (yalpha1), "m" (uvalpha1)
774 /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
776 "paddusb g16Dither, %%mm2 \n\t"
777 "paddusb b16Dither, %%mm4 \n\t"
778 "paddusb b16Dither, %%mm5 \n\t"
783 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
784 "m" (yalpha1), "m" (uvalpha1)
789 asm volatile ("\n\t"::: "memory");
794 for(i=0; i<dstw-1; i+=2){
795 // vertical linear interpolation && yuv2rgb in a single step:
796 int Y1=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
797 int Y2=yuvtab_2568[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19)];
798 int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
799 int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19);
801 int Cb= yuvtab_40cf[U];
802 int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U];
803 int Cr= yuvtab_3343[V];
805 dest[4*i+0]=clip_table[((Y1 + Cb) >>13)];
806 dest[4*i+1]=clip_table[((Y1 + Cg) >>13)];
807 dest[4*i+2]=clip_table[((Y1 + Cr) >>13)];
809 dest[4*i+4]=clip_table[((Y2 + Cb) >>13)];
810 dest[4*i+5]=clip_table[((Y2 + Cg) >>13)];
811 dest[4*i+6]=clip_table[((Y2 + Cr) >>13)];
817 for(i=0; i<dstw-1; i+=2){
818 // vertical linear interpolation && yuv2rgb in a single step:
819 int Y1=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
820 int Y2=yuvtab_2568[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19)];
821 int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
822 int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19);
824 int Cb= yuvtab_40cf[U];
825 int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U];
826 int Cr= yuvtab_3343[V];
828 dest[0]=clip_table[((Y1 + Cb) >>13)];
829 dest[1]=clip_table[((Y1 + Cg) >>13)];
830 dest[2]=clip_table[((Y1 + Cr) >>13)];
832 dest[3]=clip_table[((Y2 + Cb) >>13)];
833 dest[4]=clip_table[((Y2 + Cg) >>13)];
834 dest[5]=clip_table[((Y2 + Cr) >>13)];
841 for(i=0; i<dstw-1; i+=2){
842 // vertical linear interpolation && yuv2rgb in a single step:
843 int Y1=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
844 int Y2=yuvtab_2568[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19)];
845 int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
846 int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19);
848 int Cb= yuvtab_40cf[U];
849 int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U];
850 int Cr= yuvtab_3343[V];
852 ((uint16_t*)dest)[i] =
853 clip_table16b[(Y1 + Cb) >>13] |
854 clip_table16g[(Y1 + Cg) >>13] |
855 clip_table16r[(Y1 + Cr) >>13];
857 ((uint16_t*)dest)[i+1] =
858 clip_table16b[(Y2 + Cb) >>13] |
859 clip_table16g[(Y2 + Cg) >>13] |
860 clip_table16r[(Y2 + Cr) >>13];
866 for(i=0; i<dstw-1; i+=2){
867 // vertical linear interpolation && yuv2rgb in a single step:
868 int Y1=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
869 int Y2=yuvtab_2568[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19)];
870 int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
871 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];
877 ((uint16_t*)dest)[i] =
878 clip_table15b[(Y1 + Cb) >>13] |
879 clip_table15g[(Y1 + Cg) >>13] |
880 clip_table15r[(Y1 + Cr) >>13];
882 ((uint16_t*)dest)[i+1] =
883 clip_table15b[(Y2 + Cb) >>13] |
884 clip_table15g[(Y2 + Cg) >>13] |
885 clip_table15r[(Y2 + Cr) >>13];
893 * YV12 to RGB without scaling or interpolating
895 static inline void yuv2rgb1(uint16_t *buf0, uint16_t *buf1, uint16_t *uvbuf0, uint16_t *uvbuf1,
896 uint8_t *dest, int dstw, int yalpha, int uvalpha, int dstbpp)
898 int uvalpha1=uvalpha^4095;
900 int yalpha1=yalpha^4095;
903 if(fullUVIpol || allwaysIpol)
905 yuv2rgbX(buf0, buf1, uvbuf0, uvbuf1, dest, dstw, yalpha, uvalpha, dstbpp);
908 if( yalpha > 2048 ) buf0 = buf1;
911 if( uvalpha < 2048 ) // note this is not correct (shifts chrominance by 0.5 pixels) but its a bit faster
918 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
919 "m" (yalpha1), "m" (uvalpha1)
926 "movl %4, %%ebx \n\t"
929 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "m" (dest), "m" (dstw),
930 "m" (yalpha1), "m" (uvalpha1)
938 /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
940 "paddusb b16Dither, %%mm2 \n\t"
941 "paddusb b16Dither, %%mm4 \n\t"
942 "paddusb b16Dither, %%mm5 \n\t"
945 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
946 "m" (yalpha1), "m" (uvalpha1)
954 /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
956 "paddusb g16Dither, %%mm2 \n\t"
957 "paddusb b16Dither, %%mm4 \n\t"
958 "paddusb b16Dither, %%mm5 \n\t"
962 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
963 "m" (yalpha1), "m" (uvalpha1)
975 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
976 "m" (yalpha1), "m" (uvalpha1)
983 "movl %4, %%ebx \n\t"
986 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "m" (dest), "m" (dstw),
987 "m" (yalpha1), "m" (uvalpha1)
995 /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
997 "paddusb b16Dither, %%mm2 \n\t"
998 "paddusb b16Dither, %%mm4 \n\t"
999 "paddusb b16Dither, %%mm5 \n\t"
1002 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
1003 "m" (yalpha1), "m" (uvalpha1)
1011 /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
1013 "paddusb g16Dither, %%mm2 \n\t"
1014 "paddusb b16Dither, %%mm4 \n\t"
1015 "paddusb b16Dither, %%mm5 \n\t"
1019 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
1020 "m" (yalpha1), "m" (uvalpha1)
1026 //FIXME write 2 versions (for even & odd lines)
1027 asm volatile ("\n\t"::: "memory");
1032 for(i=0; i<dstw-1; i+=2){
1033 // vertical linear interpolation && yuv2rgb in a single step:
1034 int Y1=yuvtab_2568[buf0[i]>>7];
1035 int Y2=yuvtab_2568[buf0[i+1]>>7];
1036 int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
1037 int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19);
1039 int Cb= yuvtab_40cf[U];
1040 int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U];
1041 int Cr= yuvtab_3343[V];
1043 dest[4*i+0]=clip_table[((Y1 + Cb) >>13)];
1044 dest[4*i+1]=clip_table[((Y1 + Cg) >>13)];
1045 dest[4*i+2]=clip_table[((Y1 + Cr) >>13)];
1047 dest[4*i+4]=clip_table[((Y2 + Cb) >>13)];
1048 dest[4*i+5]=clip_table[((Y2 + Cg) >>13)];
1049 dest[4*i+6]=clip_table[((Y2 + Cr) >>13)];
1055 for(i=0; i<dstw-1; i+=2){
1056 // vertical linear interpolation && yuv2rgb in a single step:
1057 int Y1=yuvtab_2568[buf0[i]>>7];
1058 int Y2=yuvtab_2568[buf0[i+1]>>7];
1059 int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
1060 int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19);
1062 int Cb= yuvtab_40cf[U];
1063 int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U];
1064 int Cr= yuvtab_3343[V];
1066 dest[0]=clip_table[((Y1 + Cb) >>13)];
1067 dest[1]=clip_table[((Y1 + Cg) >>13)];
1068 dest[2]=clip_table[((Y1 + Cr) >>13)];
1070 dest[3]=clip_table[((Y2 + Cb) >>13)];
1071 dest[4]=clip_table[((Y2 + Cg) >>13)];
1072 dest[5]=clip_table[((Y2 + Cr) >>13)];
1079 for(i=0; i<dstw-1; i+=2){
1080 // vertical linear interpolation && yuv2rgb in a single step:
1081 int Y1=yuvtab_2568[buf0[i]>>7];
1082 int Y2=yuvtab_2568[buf0[i+1]>>7];
1083 int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
1084 int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19);
1086 int Cb= yuvtab_40cf[U];
1087 int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U];
1088 int Cr= yuvtab_3343[V];
1090 ((uint16_t*)dest)[i] =
1091 clip_table16b[(Y1 + Cb) >>13] |
1092 clip_table16g[(Y1 + Cg) >>13] |
1093 clip_table16r[(Y1 + Cr) >>13];
1095 ((uint16_t*)dest)[i+1] =
1096 clip_table16b[(Y2 + Cb) >>13] |
1097 clip_table16g[(Y2 + Cg) >>13] |
1098 clip_table16r[(Y2 + Cr) >>13];
1104 for(i=0; i<dstw-1; i+=2){
1105 // vertical linear interpolation && yuv2rgb in a single step:
1106 int Y1=yuvtab_2568[buf0[i]>>7];
1107 int Y2=yuvtab_2568[buf0[i+1]>>7];
1108 int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
1109 int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19);
1111 int Cb= yuvtab_40cf[U];
1112 int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U];
1113 int Cr= yuvtab_3343[V];
1115 ((uint16_t*)dest)[i] =
1116 clip_table15b[(Y1 + Cb) >>13] |
1117 clip_table15g[(Y1 + Cg) >>13] |
1118 clip_table15r[(Y1 + Cr) >>13];
1120 ((uint16_t*)dest)[i+1] =
1121 clip_table15b[(Y2 + Cb) >>13] |
1122 clip_table15g[(Y2 + Cg) >>13] |
1123 clip_table15r[(Y2 + Cr) >>13];
1130 static inline void hyscale(uint16_t *dst, int dstWidth, uint8_t *src, int srcWidth, int xInc)
1132 // *** horizontal scale Y line to temp buffer
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
1162 #define FUNNY_Y_CODE \
1163 PREFETCH" 1024(%%esi) \n\t"\
1164 PREFETCH" 1056(%%esi) \n\t"\
1165 PREFETCH" 1088(%%esi) \n\t"\
1166 "call funnyYCode \n\t"\
1167 "movq temp0, %%mm2 \n\t"\
1168 "xorl %%ecx, %%ecx \n\t"
1179 :: "m" (src), "m" (dst), "m" (dstWidth), "m" ((xInc*4)>>16),
1180 "m" ((xInc*4)&0xFFFF), "m" (xInc&0xFFFF)
1181 : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi"
1183 for(i=dstWidth-1; (i*xInc)>>16 >=srcWidth-1; i--) dst[i] = src[srcWidth-1]*128;
1188 //NO MMX just normal asm ...
1190 "xorl %%eax, %%eax \n\t" // i
1191 "xorl %%ebx, %%ebx \n\t" // xx
1192 "xorl %%ecx, %%ecx \n\t" // 2*xalpha
1194 "movzbl (%0, %%ebx), %%edi \n\t" //src[xx]
1195 "movzbl 1(%0, %%ebx), %%esi \n\t" //src[xx+1]
1196 "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
1197 "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
1198 "shll $16, %%edi \n\t"
1199 "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
1200 "movl %1, %%edi \n\t"
1201 "shrl $9, %%esi \n\t"
1202 "movw %%si, (%%edi, %%eax, 2) \n\t"
1203 "addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF
1204 "adcl %3, %%ebx \n\t" //xx+= xInc>>8 + carry
1206 "movzbl (%0, %%ebx), %%edi \n\t" //src[xx]
1207 "movzbl 1(%0, %%ebx), %%esi \n\t" //src[xx+1]
1208 "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
1209 "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
1210 "shll $16, %%edi \n\t"
1211 "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
1212 "movl %1, %%edi \n\t"
1213 "shrl $9, %%esi \n\t"
1214 "movw %%si, 2(%%edi, %%eax, 2) \n\t"
1215 "addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF
1216 "adcl %3, %%ebx \n\t" //xx+= xInc>>8 + carry
1219 "addl $2, %%eax \n\t"
1220 "cmpl %2, %%eax \n\t"
1224 :: "r" (src), "m" (dst), "m" (dstWidth), "m" (xInc>>16), "m" (xInc&0xFFFF)
1225 : "%eax", "%ebx", "%ecx", "%edi", "%esi"
1228 } //if MMX2 cant be used
1232 unsigned int xpos=0;
1233 for(i=0;i<dstWidth;i++)
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;
1243 inline static void hcscale(uint16_t *dst, int dstWidth,
1244 uint8_t *src1, uint8_t *src2, int srcWidth, int xInc)
1252 "pxor %%mm7, %%mm7 \n\t"
1253 "pxor %%mm2, %%mm2 \n\t" // 2*xalpha
1254 "movd %5, %%mm6 \n\t" // xInc&0xFFFF
1255 "punpcklwd %%mm6, %%mm6 \n\t"
1256 "punpcklwd %%mm6, %%mm6 \n\t"
1257 "movq %%mm6, %%mm2 \n\t"
1258 "psllq $16, %%mm2 \n\t"
1259 "paddw %%mm6, %%mm2 \n\t"
1260 "psllq $16, %%mm2 \n\t"
1261 "paddw %%mm6, %%mm2 \n\t"
1262 "psllq $16, %%mm2 \n\t" //0,t,2t,3t t=xInc&0xFFFF
1263 "movq %%mm2, temp0 \n\t"
1264 "movd %4, %%mm6 \n\t" //(xInc*4)&0xFFFF
1265 "punpcklwd %%mm6, %%mm6 \n\t"
1266 "punpcklwd %%mm6, %%mm6 \n\t"
1267 "xorl %%eax, %%eax \n\t" // i
1268 "movl %0, %%esi \n\t" // src
1269 "movl %1, %%edi \n\t" // buf1
1270 "movl %3, %%edx \n\t" // (xInc*4)>>16
1271 "xorl %%ecx, %%ecx \n\t"
1272 "xorl %%ebx, %%ebx \n\t"
1273 "movw %4, %%bx \n\t" // (xInc*4)&0xFFFF
1275 #define FUNNYUVCODE \
1276 PREFETCH" 1024(%%esi) \n\t"\
1277 PREFETCH" 1056(%%esi) \n\t"\
1278 PREFETCH" 1088(%%esi) \n\t"\
1279 "call funnyUVCode \n\t"\
1280 "movq temp0, %%mm2 \n\t"\
1281 "xorl %%ecx, %%ecx \n\t"
1292 "xorl %%eax, %%eax \n\t" // i
1293 "movl %6, %%esi \n\t" // src
1294 "movl %1, %%edi \n\t" // buf1
1295 "addl $4096, %%edi \n\t"
1307 :: "m" (src1), "m" (dst), "m" (dstWidth), "m" ((xInc*4)>>16),
1308 "m" ((xInc*4)&0xFFFF), "m" (xInc&0xFFFF), "m" (src2)
1309 : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi"
1311 for(i=dstWidth-1; (i*xInc)>>16 >=srcWidth/2-1; i--)
1313 dst[i] = src1[srcWidth/2-1]*128;
1314 dst[i+2048] = src2[srcWidth/2-1]*128;
1321 "xorl %%eax, %%eax \n\t" // i
1322 "xorl %%ebx, %%ebx \n\t" // xx
1323 "xorl %%ecx, %%ecx \n\t" // 2*xalpha
1325 "movl %0, %%esi \n\t"
1326 "movzbl (%%esi, %%ebx), %%edi \n\t" //src[xx]
1327 "movzbl 1(%%esi, %%ebx), %%esi \n\t" //src[xx+1]
1328 "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
1329 "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
1330 "shll $16, %%edi \n\t"
1331 "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
1332 "movl %1, %%edi \n\t"
1333 "shrl $9, %%esi \n\t"
1334 "movw %%si, (%%edi, %%eax, 2) \n\t"
1336 "movzbl (%5, %%ebx), %%edi \n\t" //src[xx]
1337 "movzbl 1(%5, %%ebx), %%esi \n\t" //src[xx+1]
1338 "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
1339 "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
1340 "shll $16, %%edi \n\t"
1341 "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
1342 "movl %1, %%edi \n\t"
1343 "shrl $9, %%esi \n\t"
1344 "movw %%si, 4096(%%edi, %%eax, 2)\n\t"
1346 "addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF
1347 "adcl %3, %%ebx \n\t" //xx+= xInc>>8 + carry
1348 "addl $1, %%eax \n\t"
1349 "cmpl %2, %%eax \n\t"
1352 :: "m" (src1), "m" (dst), "m" (dstWidth), "m" (xInc>>16), "m" (xInc&0xFFFF),
1354 : "%eax", "%ebx", "%ecx", "%edi", "%esi"
1357 } //if MMX2 cant be used
1361 unsigned int xpos=0;
1362 for(i=0;i<dstWidth;i++)
1364 register unsigned int xx=xpos>>16;
1365 register unsigned int xalpha=(xpos&0xFFFF)>>9;
1366 dst[i]=(src1[xx]*(xalpha^127)+src1[xx+1]*xalpha);
1367 dst[i+2048]=(src2[xx]*(xalpha^127)+src2[xx+1]*xalpha);
1369 dst[i]= (src1[xx]<<7) + (src1[xx+1] - src1[xx])*xalpha;
1370 dst[i+2048]=(src2[xx]<<7) + (src2[xx+1] - src2[xx])*xalpha;
1378 // *** bilinear scaling and yuv->rgb or yuv->yuv conversion of yv12 slices:
1379 // *** Note: it's called multiple times while decoding a frame, first time y==0
1380 // *** Designed to upscale, but may work for downscale too.
1381 // s_xinc = (src_width << 16) / dst_width
1382 // s_yinc = (src_height << 16) / dst_height
1383 void SwScale_YV12slice(unsigned char* srcptr[],int stride[], int y, int h,
1384 uint8_t* dstptr[], int dststride, int dstw, int dstbpp,
1385 unsigned int s_xinc,unsigned int s_yinc){
1388 //static int s_yinc=(vo_dga_src_height<<16)/vo_dga_vp_height;
1389 //static int s_xinc=(vo_dga_src_width<<8)/vo_dga_vp_width;
1391 unsigned int s_xinc2;
1393 static int s_srcypos; // points to the dst Pixels center in the source (0 is the center of pixel 0,0 in src)
1396 // last horzontally interpolated lines, used to avoid unnecessary calculations
1397 static int s_last_ypos;
1398 static int s_last_y1pos;
1401 // used to detect a horizontal size change
1402 static int old_dstw= -1;
1403 static int old_s_xinc= -1;
1410 if(((dstw + 7)&(~7)) >= dststride) dstw&= ~7;
1412 srcWidth= (dstw*s_xinc + 0x8000)>>16;
1413 dstUVw= fullUVIpol ? dstw : dstw/2;
1416 canMMX2BeUsed= (s_xinc <= 0x10000 && (dstw&31)==0 && (srcWidth&15)==0) ? 1 : 0;
1419 // match pixel 0 of the src to pixel 0 of dst and match pixel n-2 of src to pixel n-2 of dst
1420 // n-2 is the last chrominance sample available
1421 // FIXME this is not perfect, but noone shuld notice the difference, the more correct variant
1422 // would be like the vertical one, but that would require some special code for the
1423 // first and last pixel
1424 if(canMMX2BeUsed) s_xinc+= 20;
1425 else s_xinc = ((srcWidth-2)<<16)/(dstw-2) - 20;
1427 if(fullUVIpol && !(dstbpp==12)) s_xinc2= s_xinc>>1;
1428 else s_xinc2= s_xinc;
1429 // force calculation of the horizontal interpolation of the first line
1432 // printf("dstw %d, srcw %d, mmx2 %d\n", dstw, srcWidth, canMMX2BeUsed);
1435 s_srcypos= s_yinc/2 - 0x8000;
1438 // clean the buffers so that no green stuff is drawen if the width is not sane (%8=0)
1439 for(i=dstw-2; i<dstw+20; i++)
1441 pix_buf_uv[0][i] = pix_buf_uv[1][i]
1442 = pix_buf_uv[0][2048+i] = pix_buf_uv[1][2048+i] = 128*128;
1443 pix_buf_uv[0][i/2] = pix_buf_uv[1][i/2]
1444 = pix_buf_uv[0][2048+i/2] = pix_buf_uv[1][2048+i/2] = 128*128;
1445 pix_buf_y[0][i]= pix_buf_y[1][i]= 0;
1449 // cant downscale !!!
1450 if((old_s_xinc != s_xinc || old_dstw!=dstw) && canMMX2BeUsed)
1462 // create an optimized horizontal scaling routine
1470 "movq (%%esi), %%mm0 \n\t" //FIXME Alignment
1471 "movq %%mm0, %%mm1 \n\t"
1472 "psrlq $8, %%mm0 \n\t"
1473 "punpcklbw %%mm7, %%mm1 \n\t"
1474 "movq %%mm2, %%mm3 \n\t"
1475 "punpcklbw %%mm7, %%mm0 \n\t"
1476 "addw %%bx, %%cx \n\t" //2*xalpha += (4*s_xinc)&0xFFFF
1477 "pshufw $0xFF, %%mm1, %%mm1 \n\t"
1479 "adcl %%edx, %%esi \n\t" //xx+= (4*s_xinc)>>16 + carry
1480 "pshufw $0xFF, %%mm0, %%mm0 \n\t"
1482 "psrlw $9, %%mm3 \n\t"
1483 "psubw %%mm1, %%mm0 \n\t"
1484 "pmullw %%mm3, %%mm0 \n\t"
1485 "paddw %%mm6, %%mm2 \n\t" // 2*alpha += xpos&0xFFFF
1486 "psllw $7, %%mm1 \n\t"
1487 "paddw %%mm1, %%mm0 \n\t"
1489 "movq %%mm0, (%%edi, %%eax) \n\t"
1491 "addl $8, %%eax \n\t"
1504 :"=r" (fragment), "=r" (imm8OfPShufW1), "=r" (imm8OfPShufW2),
1505 "=r" (fragmentLength)
1508 xpos= 0; //s_xinc/2 - 0x8000; // difference between pixel centers
1510 /* choose xinc so that all 8 parts fit exactly
1511 Note: we cannot use just 1 part because it would not fit in the code cache */
1512 // s_xinc2_diff= -((((s_xinc2*(dstw/8))&0xFFFF))/(dstw/8))-10;
1513 // s_xinc_diff= -((((s_xinc*(dstw/8))&0xFFFF))/(dstw/8));
1515 // s_xinc2_diff+= ((0x10000/(dstw/8)));
1517 // s_xinc_diff= s_xinc2_diff*2;
1519 // s_xinc2+= s_xinc2_diff;
1520 // s_xinc+= s_xinc_diff;
1522 // old_s_xinc= s_xinc;
1524 for(i=0; i<dstw/8; i++)
1531 int b=((xpos+s_xinc)>>16) - xx;
1532 int c=((xpos+s_xinc*2)>>16) - xx;
1533 int d=((xpos+s_xinc*3)>>16) - xx;
1535 memcpy(funnyYCode + fragmentLength*i/4, fragment, fragmentLength);
1537 funnyYCode[fragmentLength*i/4 + imm8OfPShufW1]=
1538 funnyYCode[fragmentLength*i/4 + imm8OfPShufW2]=
1539 a | (b<<2) | (c<<4) | (d<<6);
1541 // if we dont need to read 8 bytes than dont :), reduces the chance of
1542 // crossing a cache line
1543 if(d<3) funnyYCode[fragmentLength*i/4 + 1]= 0x6E;
1545 funnyYCode[fragmentLength*(i+4)/4]= RET;
1550 xpos= 0; //s_xinc2/2 - 0x10000; // difference between centers of chrom samples
1551 for(i=0; i<dstUVw/8; i++)
1558 int b=((xpos+s_xinc2)>>16) - xx;
1559 int c=((xpos+s_xinc2*2)>>16) - xx;
1560 int d=((xpos+s_xinc2*3)>>16) - xx;
1562 memcpy(funnyUVCode + fragmentLength*i/4, fragment, fragmentLength);
1564 funnyUVCode[fragmentLength*i/4 + imm8OfPShufW1]=
1565 funnyUVCode[fragmentLength*i/4 + imm8OfPShufW2]=
1566 a | (b<<2) | (c<<4) | (d<<6);
1568 // if we dont need to read 8 bytes than dont :), reduces the chance of
1569 // crossing a cache line
1570 if(d<3) funnyUVCode[fragmentLength*i/4 + 1]= 0x6E;
1572 funnyUVCode[fragmentLength*(i+4)/4]= RET;
1576 // funnyCode[0]= RET;
1583 unsigned char *dest =dstptr[0]+dststride*s_ypos;
1584 unsigned char *uDest=dstptr[1]+(dststride>>1)*(s_ypos>>1);
1585 unsigned char *vDest=dstptr[2]+(dststride>>1)*(s_ypos>>1);
1587 int y0=(s_srcypos + 0xFFFF)>>16; // first luminance source line number below the dst line
1588 // points to the dst Pixels center in the source (0 is the center of pixel 0,0 in src)
1589 int srcuvpos= dstbpp==12 ? s_srcypos + s_yinc/2 - 0x8000 :
1591 int y1=(srcuvpos + 0x1FFFF)>>17; // first chrominance source line number below the dst line
1592 int yalpha=((s_srcypos-1)&0xFFFF)>>4;
1593 int uvalpha=((srcuvpos-1)&0x1FFFF)>>5;
1594 uint16_t *buf0=pix_buf_y[y0&1]; // top line of the interpolated slice
1595 uint16_t *buf1=pix_buf_y[((y0+1)&1)]; // bottom line of the interpolated slice
1596 uint16_t *uvbuf0=pix_buf_uv[y1&1]; // top line of the interpolated slice
1597 uint16_t *uvbuf1=pix_buf_uv[(y1+1)&1]; // bottom line of the interpolated slice
1599 if(y0>=y+h) break; // FIXME wrong, skips last lines, but they are dupliactes anyway
1601 if((y0&1) && dstbpp==12) uvalpha=-1; // there is no alpha if there is no line
1603 s_ypos++; s_srcypos+=s_yinc;
1605 //only interpolate the src line horizontally if we didnt do it allready
1609 // skip if first line has been horiz scaled alleady
1610 if(s_last_ypos != y0-1)
1612 // check if first line is before any available src lines
1613 if(y0-1 < y) src=srcptr[0]+(0 )*stride[0];
1614 else src=srcptr[0]+(y0-y-1)*stride[0];
1616 hyscale(buf0, dstw, src, srcWidth, s_xinc);
1618 // check if second line is after any available src lines
1619 if(y0-y >= h) src=srcptr[0]+(h-1)*stride[0];
1620 else src=srcptr[0]+(y0-y)*stride[0];
1622 // the min() is required to avoid reuseing lines which where not available
1623 s_last_ypos= MIN(y0, y+h-1);
1624 hyscale(buf1, dstw, src, srcWidth, s_xinc);
1626 // printf("%d %d %d %d\n", y, y1, s_last_y1pos, h);
1627 // *** horizontal scale U and V lines to temp buffer
1628 if(s_last_y1pos!=y1)
1630 uint8_t *src1, *src2;
1631 // skip if first line has been horiz scaled alleady
1632 if(s_last_y1pos != y1-1)
1634 // check if first line is before any available src lines
1637 src1= srcptr[1]+(0)*stride[1];
1638 src2= srcptr[2]+(0)*stride[2];
1640 src1= srcptr[1]+(y1-y/2-1)*stride[1];
1641 src2= srcptr[2]+(y1-y/2-1)*stride[2];
1643 hcscale(uvbuf0, dstUVw, src1, src2, srcWidth, s_xinc2);
1646 // check if second line is after any available src lines
1649 src1= srcptr[1]+(h/2-1)*stride[1];
1650 src2= srcptr[2]+(h/2-1)*stride[2];
1652 src1= srcptr[1]+(y1-y/2)*stride[1];
1653 src2= srcptr[2]+(y1-y/2)*stride[2];
1655 hcscale(uvbuf1, dstUVw, src1, src2, srcWidth, s_xinc2);
1657 // the min() is required to avoid reuseing lines which where not available
1658 s_last_y1pos= MIN(y1, y/2+h/2-1);
1661 if(dstbpp==12) //YV12
1662 yuv2yuv(buf0, buf1, uvbuf0, uvbuf1, dest, uDest, vDest, dstw, yalpha, uvalpha);
1663 else if(ABS(s_yinc - 0x10000) < 10)
1664 yuv2rgb1(buf0, buf1, uvbuf0, uvbuf1, dest, dstw, yalpha, uvalpha, dstbpp);
1666 yuv2rgbX(buf0, buf1, uvbuf0, uvbuf1, dest, dstw, yalpha, uvalpha, dstbpp);
1669 b16Dither= b16Dither1;
1670 b16Dither1= b16Dither2;
1671 b16Dither2= b16Dither;
1673 g16Dither= g16Dither1;
1674 g16Dither1= g16Dither2;
1675 g16Dither2= g16Dither;
1680 __asm __volatile(SFENCE:::"memory");
1681 __asm __volatile(EMMS:::"memory");
1686 void SwScale_Init(){
1687 // generating tables:
1691 clip_table[i+256]=i;
1692 clip_table[i+512]=255;
1693 yuvtab_2568[i]=(0x2568*(i-16))+(256<<13);
1694 yuvtab_3343[i]=0x3343*(i-128);
1695 yuvtab_0c92[i]=-0x0c92*(i-128);
1696 yuvtab_1a1e[i]=-0x1a1e*(i-128);
1697 yuvtab_40cf[i]=0x40cf*(i-128);
1700 for(i=0; i<768; i++)
1702 int v= clip_table[i];
1703 clip_table16b[i]= v>>3;
1704 clip_table16g[i]= (v<<3)&0x07E0;
1705 clip_table16r[i]= (v<<8)&0xF800;
1706 clip_table15b[i]= v>>3;
1707 clip_table15g[i]= (v<<2)&0x03E0;
1708 clip_table15r[i]= (v<<7)&0x7C00;