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 "leal (%%eax, %%eax, 2), %%ebx \n\t"\
478 MOVNTQ(%%mm0, (%4, %%ebx))\
479 MOVNTQ(%%mm2, 8(%4, %%ebx))\
480 MOVNTQ(%%mm3, 16(%4, %%ebx))\
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)
746 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
747 "m" (yalpha1), "m" (uvalpha1)
755 /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
757 "paddusb b16Dither, %%mm2 \n\t"
758 "paddusb b16Dither, %%mm4 \n\t"
759 "paddusb b16Dither, %%mm5 \n\t"
764 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
765 "m" (yalpha1), "m" (uvalpha1)
773 /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
775 "paddusb g16Dither, %%mm2 \n\t"
776 "paddusb b16Dither, %%mm4 \n\t"
777 "paddusb b16Dither, %%mm5 \n\t"
782 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
783 "m" (yalpha1), "m" (uvalpha1)
788 asm volatile ("\n\t"::: "memory");
793 for(i=0; i<dstw-1; i+=2){
794 // vertical linear interpolation && yuv2rgb in a single step:
795 int Y1=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
796 int Y2=yuvtab_2568[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19)];
797 int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
798 int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19);
800 int Cb= yuvtab_40cf[U];
801 int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U];
802 int Cr= yuvtab_3343[V];
804 dest[4*i+0]=clip_table[((Y1 + Cb) >>13)];
805 dest[4*i+1]=clip_table[((Y1 + Cg) >>13)];
806 dest[4*i+2]=clip_table[((Y1 + Cr) >>13)];
808 dest[4*i+4]=clip_table[((Y2 + Cb) >>13)];
809 dest[4*i+5]=clip_table[((Y2 + Cg) >>13)];
810 dest[4*i+6]=clip_table[((Y2 + Cr) >>13)];
816 for(i=0; i<dstw-1; i+=2){
817 // vertical linear interpolation && yuv2rgb in a single step:
818 int Y1=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
819 int Y2=yuvtab_2568[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19)];
820 int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
821 int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19);
823 int Cb= yuvtab_40cf[U];
824 int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U];
825 int Cr= yuvtab_3343[V];
827 dest[0]=clip_table[((Y1 + Cb) >>13)];
828 dest[1]=clip_table[((Y1 + Cg) >>13)];
829 dest[2]=clip_table[((Y1 + Cr) >>13)];
831 dest[3]=clip_table[((Y2 + Cb) >>13)];
832 dest[4]=clip_table[((Y2 + Cg) >>13)];
833 dest[5]=clip_table[((Y2 + Cr) >>13)];
840 for(i=0; i<dstw-1; i+=2){
841 // vertical linear interpolation && yuv2rgb in a single step:
842 int Y1=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
843 int Y2=yuvtab_2568[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19)];
844 int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
845 int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19);
847 int Cb= yuvtab_40cf[U];
848 int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U];
849 int Cr= yuvtab_3343[V];
851 ((uint16_t*)dest)[i] =
852 clip_table16b[(Y1 + Cb) >>13] |
853 clip_table16g[(Y1 + Cg) >>13] |
854 clip_table16r[(Y1 + Cr) >>13];
856 ((uint16_t*)dest)[i+1] =
857 clip_table16b[(Y2 + Cb) >>13] |
858 clip_table16g[(Y2 + Cg) >>13] |
859 clip_table16r[(Y2 + Cr) >>13];
865 for(i=0; i<dstw-1; i+=2){
866 // vertical linear interpolation && yuv2rgb in a single step:
867 int Y1=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)];
868 int Y2=yuvtab_2568[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19)];
869 int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
870 int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19);
872 int Cb= yuvtab_40cf[U];
873 int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U];
874 int Cr= yuvtab_3343[V];
876 ((uint16_t*)dest)[i] =
877 clip_table15b[(Y1 + Cb) >>13] |
878 clip_table15g[(Y1 + Cg) >>13] |
879 clip_table15r[(Y1 + Cr) >>13];
881 ((uint16_t*)dest)[i+1] =
882 clip_table15b[(Y2 + Cb) >>13] |
883 clip_table15g[(Y2 + Cg) >>13] |
884 clip_table15r[(Y2 + Cr) >>13];
892 * YV12 to RGB without scaling or interpolating
894 static inline void yuv2rgb1(uint16_t *buf0, uint16_t *buf1, uint16_t *uvbuf0, uint16_t *uvbuf1,
895 uint8_t *dest, int dstw, int yalpha, int uvalpha, int dstbpp)
897 int uvalpha1=uvalpha^4095;
899 int yalpha1=yalpha^4095;
902 if(fullUVIpol || allwaysIpol)
904 yuv2rgbX(buf0, buf1, uvbuf0, uvbuf1, dest, dstw, yalpha, uvalpha, dstbpp);
907 if( yalpha > 2048 ) buf0 = buf1;
910 if( uvalpha < 2048 ) // note this is not correct (shifts chrominance by 0.5 pixels) but its a bit faster
917 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
918 "m" (yalpha1), "m" (uvalpha1)
927 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
928 "m" (yalpha1), "m" (uvalpha1)
936 /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
938 "paddusb b16Dither, %%mm2 \n\t"
939 "paddusb b16Dither, %%mm4 \n\t"
940 "paddusb b16Dither, %%mm5 \n\t"
943 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
944 "m" (yalpha1), "m" (uvalpha1)
952 /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
954 "paddusb g16Dither, %%mm2 \n\t"
955 "paddusb b16Dither, %%mm4 \n\t"
956 "paddusb b16Dither, %%mm5 \n\t"
960 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
961 "m" (yalpha1), "m" (uvalpha1)
973 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
974 "m" (yalpha1), "m" (uvalpha1)
983 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
984 "m" (yalpha1), "m" (uvalpha1)
992 /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
994 "paddusb b16Dither, %%mm2 \n\t"
995 "paddusb b16Dither, %%mm4 \n\t"
996 "paddusb b16Dither, %%mm5 \n\t"
999 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
1000 "m" (yalpha1), "m" (uvalpha1)
1008 /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
1010 "paddusb g16Dither, %%mm2 \n\t"
1011 "paddusb b16Dither, %%mm4 \n\t"
1012 "paddusb b16Dither, %%mm5 \n\t"
1016 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
1017 "m" (yalpha1), "m" (uvalpha1)
1023 //FIXME write 2 versions (for even & odd lines)
1024 asm volatile ("\n\t"::: "memory");
1029 for(i=0; i<dstw-1; i+=2){
1030 // vertical linear interpolation && yuv2rgb in a single step:
1031 int Y1=yuvtab_2568[buf0[i]>>7];
1032 int Y2=yuvtab_2568[buf0[i+1]>>7];
1033 int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
1034 int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19);
1036 int Cb= yuvtab_40cf[U];
1037 int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U];
1038 int Cr= yuvtab_3343[V];
1040 dest[4*i+0]=clip_table[((Y1 + Cb) >>13)];
1041 dest[4*i+1]=clip_table[((Y1 + Cg) >>13)];
1042 dest[4*i+2]=clip_table[((Y1 + Cr) >>13)];
1044 dest[4*i+4]=clip_table[((Y2 + Cb) >>13)];
1045 dest[4*i+5]=clip_table[((Y2 + Cg) >>13)];
1046 dest[4*i+6]=clip_table[((Y2 + Cr) >>13)];
1052 for(i=0; i<dstw-1; i+=2){
1053 // vertical linear interpolation && yuv2rgb in a single step:
1054 int Y1=yuvtab_2568[buf0[i]>>7];
1055 int Y2=yuvtab_2568[buf0[i+1]>>7];
1056 int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
1057 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];
1063 dest[0]=clip_table[((Y1 + Cb) >>13)];
1064 dest[1]=clip_table[((Y1 + Cg) >>13)];
1065 dest[2]=clip_table[((Y1 + Cr) >>13)];
1067 dest[3]=clip_table[((Y2 + Cb) >>13)];
1068 dest[4]=clip_table[((Y2 + Cg) >>13)];
1069 dest[5]=clip_table[((Y2 + Cr) >>13)];
1076 for(i=0; i<dstw-1; i+=2){
1077 // vertical linear interpolation && yuv2rgb in a single step:
1078 int Y1=yuvtab_2568[buf0[i]>>7];
1079 int Y2=yuvtab_2568[buf0[i+1]>>7];
1080 int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
1081 int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19);
1083 int Cb= yuvtab_40cf[U];
1084 int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U];
1085 int Cr= yuvtab_3343[V];
1087 ((uint16_t*)dest)[i] =
1088 clip_table16b[(Y1 + Cb) >>13] |
1089 clip_table16g[(Y1 + Cg) >>13] |
1090 clip_table16r[(Y1 + Cr) >>13];
1092 ((uint16_t*)dest)[i+1] =
1093 clip_table16b[(Y2 + Cb) >>13] |
1094 clip_table16g[(Y2 + Cg) >>13] |
1095 clip_table16r[(Y2 + Cr) >>13];
1101 for(i=0; i<dstw-1; i+=2){
1102 // vertical linear interpolation && yuv2rgb in a single step:
1103 int Y1=yuvtab_2568[buf0[i]>>7];
1104 int Y2=yuvtab_2568[buf0[i+1]>>7];
1105 int U=((uvbuf0[i>>1]*uvalpha1+uvbuf1[i>>1]*uvalpha)>>19);
1106 int V=((uvbuf0[(i>>1)+2048]*uvalpha1+uvbuf1[(i>>1)+2048]*uvalpha)>>19);
1108 int Cb= yuvtab_40cf[U];
1109 int Cg= yuvtab_1a1e[V] + yuvtab_0c92[U];
1110 int Cr= yuvtab_3343[V];
1112 ((uint16_t*)dest)[i] =
1113 clip_table15b[(Y1 + Cb) >>13] |
1114 clip_table15g[(Y1 + Cg) >>13] |
1115 clip_table15r[(Y1 + Cr) >>13];
1117 ((uint16_t*)dest)[i+1] =
1118 clip_table15b[(Y2 + Cb) >>13] |
1119 clip_table15g[(Y2 + Cg) >>13] |
1120 clip_table15r[(Y2 + Cr) >>13];
1127 static inline void hyscale(uint16_t *dst, int dstWidth, uint8_t *src, int srcWidth, int xInc)
1129 // *** horizontal scale Y line to temp buffer
1136 "pxor %%mm7, %%mm7 \n\t"
1137 "pxor %%mm2, %%mm2 \n\t" // 2*xalpha
1138 "movd %5, %%mm6 \n\t" // xInc&0xFFFF
1139 "punpcklwd %%mm6, %%mm6 \n\t"
1140 "punpcklwd %%mm6, %%mm6 \n\t"
1141 "movq %%mm6, %%mm2 \n\t"
1142 "psllq $16, %%mm2 \n\t"
1143 "paddw %%mm6, %%mm2 \n\t"
1144 "psllq $16, %%mm2 \n\t"
1145 "paddw %%mm6, %%mm2 \n\t"
1146 "psllq $16, %%mm2 \n\t" //0,t,2t,3t t=xInc&0xFF
1147 "movq %%mm2, temp0 \n\t"
1148 "movd %4, %%mm6 \n\t" //(xInc*4)&0xFFFF
1149 "punpcklwd %%mm6, %%mm6 \n\t"
1150 "punpcklwd %%mm6, %%mm6 \n\t"
1151 "xorl %%eax, %%eax \n\t" // i
1152 "movl %0, %%esi \n\t" // src
1153 "movl %1, %%edi \n\t" // buf1
1154 "movl %3, %%edx \n\t" // (xInc*4)>>16
1155 "xorl %%ecx, %%ecx \n\t"
1156 "xorl %%ebx, %%ebx \n\t"
1157 "movw %4, %%bx \n\t" // (xInc*4)&0xFFFF
1159 #define FUNNY_Y_CODE \
1160 PREFETCH" 1024(%%esi) \n\t"\
1161 PREFETCH" 1056(%%esi) \n\t"\
1162 PREFETCH" 1088(%%esi) \n\t"\
1163 "call funnyYCode \n\t"\
1164 "movq temp0, %%mm2 \n\t"\
1165 "xorl %%ecx, %%ecx \n\t"
1176 :: "m" (src), "m" (dst), "m" (dstWidth), "m" ((xInc*4)>>16),
1177 "m" ((xInc*4)&0xFFFF), "m" (xInc&0xFFFF)
1178 : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi"
1180 for(i=dstWidth-1; (i*xInc)>>16 >=srcWidth-1; i--) dst[i] = src[srcWidth-1]*128;
1185 //NO MMX just normal asm ...
1187 "xorl %%eax, %%eax \n\t" // i
1188 "xorl %%ebx, %%ebx \n\t" // xx
1189 "xorl %%ecx, %%ecx \n\t" // 2*xalpha
1191 "movzbl (%0, %%ebx), %%edi \n\t" //src[xx]
1192 "movzbl 1(%0, %%ebx), %%esi \n\t" //src[xx+1]
1193 "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
1194 "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
1195 "shll $16, %%edi \n\t"
1196 "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
1197 "movl %1, %%edi \n\t"
1198 "shrl $9, %%esi \n\t"
1199 "movw %%si, (%%edi, %%eax, 2) \n\t"
1200 "addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF
1201 "adcl %3, %%ebx \n\t" //xx+= xInc>>8 + carry
1203 "movzbl (%0, %%ebx), %%edi \n\t" //src[xx]
1204 "movzbl 1(%0, %%ebx), %%esi \n\t" //src[xx+1]
1205 "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
1206 "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
1207 "shll $16, %%edi \n\t"
1208 "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
1209 "movl %1, %%edi \n\t"
1210 "shrl $9, %%esi \n\t"
1211 "movw %%si, 2(%%edi, %%eax, 2) \n\t"
1212 "addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF
1213 "adcl %3, %%ebx \n\t" //xx+= xInc>>8 + carry
1216 "addl $2, %%eax \n\t"
1217 "cmpl %2, %%eax \n\t"
1221 :: "r" (src), "m" (dst), "m" (dstWidth), "m" (xInc>>16), "m" (xInc&0xFFFF)
1222 : "%eax", "%ebx", "%ecx", "%edi", "%esi"
1225 } //if MMX2 cant be used
1229 unsigned int xpos=0;
1230 for(i=0;i<dstWidth;i++)
1232 register unsigned int xx=xpos>>16;
1233 register unsigned int xalpha=(xpos&0xFFFF)>>9;
1234 dst[i]= (src[xx]<<7) + (src[xx+1] - src[xx])*xalpha;
1240 inline static void hcscale(uint16_t *dst, int dstWidth,
1241 uint8_t *src1, uint8_t *src2, int srcWidth, int xInc)
1249 "pxor %%mm7, %%mm7 \n\t"
1250 "pxor %%mm2, %%mm2 \n\t" // 2*xalpha
1251 "movd %5, %%mm6 \n\t" // xInc&0xFFFF
1252 "punpcklwd %%mm6, %%mm6 \n\t"
1253 "punpcklwd %%mm6, %%mm6 \n\t"
1254 "movq %%mm6, %%mm2 \n\t"
1255 "psllq $16, %%mm2 \n\t"
1256 "paddw %%mm6, %%mm2 \n\t"
1257 "psllq $16, %%mm2 \n\t"
1258 "paddw %%mm6, %%mm2 \n\t"
1259 "psllq $16, %%mm2 \n\t" //0,t,2t,3t t=xInc&0xFFFF
1260 "movq %%mm2, temp0 \n\t"
1261 "movd %4, %%mm6 \n\t" //(xInc*4)&0xFFFF
1262 "punpcklwd %%mm6, %%mm6 \n\t"
1263 "punpcklwd %%mm6, %%mm6 \n\t"
1264 "xorl %%eax, %%eax \n\t" // i
1265 "movl %0, %%esi \n\t" // src
1266 "movl %1, %%edi \n\t" // buf1
1267 "movl %3, %%edx \n\t" // (xInc*4)>>16
1268 "xorl %%ecx, %%ecx \n\t"
1269 "xorl %%ebx, %%ebx \n\t"
1270 "movw %4, %%bx \n\t" // (xInc*4)&0xFFFF
1272 #define FUNNYUVCODE \
1273 PREFETCH" 1024(%%esi) \n\t"\
1274 PREFETCH" 1056(%%esi) \n\t"\
1275 PREFETCH" 1088(%%esi) \n\t"\
1276 "call funnyUVCode \n\t"\
1277 "movq temp0, %%mm2 \n\t"\
1278 "xorl %%ecx, %%ecx \n\t"
1289 "xorl %%eax, %%eax \n\t" // i
1290 "movl %6, %%esi \n\t" // src
1291 "movl %1, %%edi \n\t" // buf1
1292 "addl $4096, %%edi \n\t"
1304 :: "m" (src1), "m" (dst), "m" (dstWidth), "m" ((xInc*4)>>16),
1305 "m" ((xInc*4)&0xFFFF), "m" (xInc&0xFFFF), "m" (src2)
1306 : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi"
1308 for(i=dstWidth-1; (i*xInc)>>16 >=srcWidth/2-1; i--)
1310 dst[i] = src1[srcWidth/2-1]*128;
1311 dst[i+2048] = src2[srcWidth/2-1]*128;
1318 "xorl %%eax, %%eax \n\t" // i
1319 "xorl %%ebx, %%ebx \n\t" // xx
1320 "xorl %%ecx, %%ecx \n\t" // 2*xalpha
1322 "movl %0, %%esi \n\t"
1323 "movzbl (%%esi, %%ebx), %%edi \n\t" //src[xx]
1324 "movzbl 1(%%esi, %%ebx), %%esi \n\t" //src[xx+1]
1325 "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
1326 "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
1327 "shll $16, %%edi \n\t"
1328 "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
1329 "movl %1, %%edi \n\t"
1330 "shrl $9, %%esi \n\t"
1331 "movw %%si, (%%edi, %%eax, 2) \n\t"
1333 "movzbl (%5, %%ebx), %%edi \n\t" //src[xx]
1334 "movzbl 1(%5, %%ebx), %%esi \n\t" //src[xx+1]
1335 "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
1336 "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
1337 "shll $16, %%edi \n\t"
1338 "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
1339 "movl %1, %%edi \n\t"
1340 "shrl $9, %%esi \n\t"
1341 "movw %%si, 4096(%%edi, %%eax, 2)\n\t"
1343 "addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF
1344 "adcl %3, %%ebx \n\t" //xx+= xInc>>8 + carry
1345 "addl $1, %%eax \n\t"
1346 "cmpl %2, %%eax \n\t"
1349 :: "m" (src1), "m" (dst), "m" (dstWidth), "m" (xInc>>16), "m" (xInc&0xFFFF),
1351 : "%eax", "%ebx", "%ecx", "%edi", "%esi"
1354 } //if MMX2 cant be used
1358 unsigned int xpos=0;
1359 for(i=0;i<dstWidth;i++)
1361 register unsigned int xx=xpos>>16;
1362 register unsigned int xalpha=(xpos&0xFFFF)>>9;
1363 dst[i]=(src1[xx]*(xalpha^127)+src1[xx+1]*xalpha);
1364 dst[i+2048]=(src2[xx]*(xalpha^127)+src2[xx+1]*xalpha);
1366 dst[i]= (src1[xx]<<7) + (src1[xx+1] - src1[xx])*xalpha;
1367 dst[i+2048]=(src2[xx]<<7) + (src2[xx+1] - src2[xx])*xalpha;
1375 // *** bilinear scaling and yuv->rgb or yuv->yuv conversion of yv12 slices:
1376 // *** Note: it's called multiple times while decoding a frame, first time y==0
1377 // *** Designed to upscale, but may work for downscale too.
1378 // s_xinc = (src_width << 16) / dst_width
1379 // s_yinc = (src_height << 16) / dst_height
1380 void SwScale_YV12slice(unsigned char* srcptr[],int stride[], int y, int h,
1381 uint8_t* dstptr[], int dststride, int dstw, int dstbpp,
1382 unsigned int s_xinc,unsigned int s_yinc){
1385 //static int s_yinc=(vo_dga_src_height<<16)/vo_dga_vp_height;
1386 //static int s_xinc=(vo_dga_src_width<<8)/vo_dga_vp_width;
1388 unsigned int s_xinc2;
1390 static int s_srcypos; // points to the dst Pixels center in the source (0 is the center of pixel 0,0 in src)
1393 // last horzontally interpolated lines, used to avoid unnecessary calculations
1394 static int s_last_ypos;
1395 static int s_last_y1pos;
1398 // used to detect a horizontal size change
1399 static int old_dstw= -1;
1400 static int old_s_xinc= -1;
1407 if(((dstw + 7)&(~7)) >= dststride) dstw&= ~7;
1409 srcWidth= (dstw*s_xinc + 0x8000)>>16;
1410 dstUVw= fullUVIpol ? dstw : dstw/2;
1413 canMMX2BeUsed= (s_xinc <= 0x10000 && (dstw&31)==0 && (srcWidth&15)==0) ? 1 : 0;
1416 // match pixel 0 of the src to pixel 0 of dst and match pixel n-2 of src to pixel n-2 of dst
1417 // n-2 is the last chrominance sample available
1418 // FIXME this is not perfect, but noone shuld notice the difference, the more correct variant
1419 // would be like the vertical one, but that would require some special code for the
1420 // first and last pixel
1421 if(canMMX2BeUsed) s_xinc+= 20;
1422 else s_xinc = ((srcWidth-2)<<16)/(dstw-2) - 20;
1424 if(fullUVIpol && !(dstbpp==12)) s_xinc2= s_xinc>>1;
1425 else s_xinc2= s_xinc;
1426 // force calculation of the horizontal interpolation of the first line
1429 // printf("dstw %d, srcw %d, mmx2 %d\n", dstw, srcWidth, canMMX2BeUsed);
1432 s_srcypos= s_yinc/2 - 0x8000;
1435 // clean the buffers so that no green stuff is drawen if the width is not sane (%8=0)
1436 for(i=dstw-2; i<dstw+20; i++)
1438 pix_buf_uv[0][i] = pix_buf_uv[1][i]
1439 = pix_buf_uv[0][2048+i] = pix_buf_uv[1][2048+i] = 128*128;
1440 pix_buf_uv[0][i/2] = pix_buf_uv[1][i/2]
1441 = pix_buf_uv[0][2048+i/2] = pix_buf_uv[1][2048+i/2] = 128*128;
1442 pix_buf_y[0][i]= pix_buf_y[1][i]= 0;
1446 // cant downscale !!!
1447 if((old_s_xinc != s_xinc || old_dstw!=dstw) && canMMX2BeUsed)
1459 // create an optimized horizontal scaling routine
1467 "movq (%%esi), %%mm0 \n\t" //FIXME Alignment
1468 "movq %%mm0, %%mm1 \n\t"
1469 "psrlq $8, %%mm0 \n\t"
1470 "punpcklbw %%mm7, %%mm1 \n\t"
1471 "movq %%mm2, %%mm3 \n\t"
1472 "punpcklbw %%mm7, %%mm0 \n\t"
1473 "addw %%bx, %%cx \n\t" //2*xalpha += (4*s_xinc)&0xFFFF
1474 "pshufw $0xFF, %%mm1, %%mm1 \n\t"
1476 "adcl %%edx, %%esi \n\t" //xx+= (4*s_xinc)>>16 + carry
1477 "pshufw $0xFF, %%mm0, %%mm0 \n\t"
1479 "psrlw $9, %%mm3 \n\t"
1480 "psubw %%mm1, %%mm0 \n\t"
1481 "pmullw %%mm3, %%mm0 \n\t"
1482 "paddw %%mm6, %%mm2 \n\t" // 2*alpha += xpos&0xFFFF
1483 "psllw $7, %%mm1 \n\t"
1484 "paddw %%mm1, %%mm0 \n\t"
1486 "movq %%mm0, (%%edi, %%eax) \n\t"
1488 "addl $8, %%eax \n\t"
1501 :"=r" (fragment), "=r" (imm8OfPShufW1), "=r" (imm8OfPShufW2),
1502 "=r" (fragmentLength)
1505 xpos= 0; //s_xinc/2 - 0x8000; // difference between pixel centers
1507 /* choose xinc so that all 8 parts fit exactly
1508 Note: we cannot use just 1 part because it would not fit in the code cache */
1509 // s_xinc2_diff= -((((s_xinc2*(dstw/8))&0xFFFF))/(dstw/8))-10;
1510 // s_xinc_diff= -((((s_xinc*(dstw/8))&0xFFFF))/(dstw/8));
1512 // s_xinc2_diff+= ((0x10000/(dstw/8)));
1514 // s_xinc_diff= s_xinc2_diff*2;
1516 // s_xinc2+= s_xinc2_diff;
1517 // s_xinc+= s_xinc_diff;
1519 // old_s_xinc= s_xinc;
1521 for(i=0; i<dstw/8; i++)
1528 int b=((xpos+s_xinc)>>16) - xx;
1529 int c=((xpos+s_xinc*2)>>16) - xx;
1530 int d=((xpos+s_xinc*3)>>16) - xx;
1532 memcpy(funnyYCode + fragmentLength*i/4, fragment, fragmentLength);
1534 funnyYCode[fragmentLength*i/4 + imm8OfPShufW1]=
1535 funnyYCode[fragmentLength*i/4 + imm8OfPShufW2]=
1536 a | (b<<2) | (c<<4) | (d<<6);
1538 // if we dont need to read 8 bytes than dont :), reduces the chance of
1539 // crossing a cache line
1540 if(d<3) funnyYCode[fragmentLength*i/4 + 1]= 0x6E;
1542 funnyYCode[fragmentLength*(i+4)/4]= RET;
1547 xpos= 0; //s_xinc2/2 - 0x10000; // difference between centers of chrom samples
1548 for(i=0; i<dstUVw/8; i++)
1555 int b=((xpos+s_xinc2)>>16) - xx;
1556 int c=((xpos+s_xinc2*2)>>16) - xx;
1557 int d=((xpos+s_xinc2*3)>>16) - xx;
1559 memcpy(funnyUVCode + fragmentLength*i/4, fragment, fragmentLength);
1561 funnyUVCode[fragmentLength*i/4 + imm8OfPShufW1]=
1562 funnyUVCode[fragmentLength*i/4 + imm8OfPShufW2]=
1563 a | (b<<2) | (c<<4) | (d<<6);
1565 // if we dont need to read 8 bytes than dont :), reduces the chance of
1566 // crossing a cache line
1567 if(d<3) funnyUVCode[fragmentLength*i/4 + 1]= 0x6E;
1569 funnyUVCode[fragmentLength*(i+4)/4]= RET;
1573 // funnyCode[0]= RET;
1580 unsigned char *dest =dstptr[0]+dststride*s_ypos;
1581 unsigned char *uDest=dstptr[1]+(dststride>>1)*(s_ypos>>1);
1582 unsigned char *vDest=dstptr[2]+(dststride>>1)*(s_ypos>>1);
1584 int y0=(s_srcypos + 0xFFFF)>>16; // first luminance source line number below the dst line
1585 // points to the dst Pixels center in the source (0 is the center of pixel 0,0 in src)
1586 int srcuvpos= dstbpp==12 ? s_srcypos + s_yinc/2 - 0x8000 :
1588 int y1=(srcuvpos + 0x1FFFF)>>17; // first chrominance source line number below the dst line
1589 int yalpha=((s_srcypos-1)&0xFFFF)>>4;
1590 int uvalpha=((srcuvpos-1)&0x1FFFF)>>5;
1591 uint16_t *buf0=pix_buf_y[y0&1]; // top line of the interpolated slice
1592 uint16_t *buf1=pix_buf_y[((y0+1)&1)]; // bottom line of the interpolated slice
1593 uint16_t *uvbuf0=pix_buf_uv[y1&1]; // top line of the interpolated slice
1594 uint16_t *uvbuf1=pix_buf_uv[(y1+1)&1]; // bottom line of the interpolated slice
1596 if(y0>=y+h) break; // FIXME wrong, skips last lines, but they are dupliactes anyway
1598 if((y0&1) && dstbpp==12) uvalpha=-1; // there is no alpha if there is no line
1600 s_ypos++; s_srcypos+=s_yinc;
1602 //only interpolate the src line horizontally if we didnt do it allready
1606 // skip if first line has been horiz scaled alleady
1607 if(s_last_ypos != y0-1)
1609 // check if first line is before any available src lines
1610 if(y0-1 < y) src=srcptr[0]+(0 )*stride[0];
1611 else src=srcptr[0]+(y0-y-1)*stride[0];
1613 hyscale(buf0, dstw, src, srcWidth, s_xinc);
1615 // check if second line is after any available src lines
1616 if(y0-y >= h) src=srcptr[0]+(h-1)*stride[0];
1617 else src=srcptr[0]+(y0-y)*stride[0];
1619 // the min() is required to avoid reuseing lines which where not available
1620 s_last_ypos= MIN(y0, y+h-1);
1621 hyscale(buf1, dstw, src, srcWidth, s_xinc);
1623 // printf("%d %d %d %d\n", y, y1, s_last_y1pos, h);
1624 // *** horizontal scale U and V lines to temp buffer
1625 if(s_last_y1pos!=y1)
1627 uint8_t *src1, *src2;
1628 // skip if first line has been horiz scaled alleady
1629 if(s_last_y1pos != y1-1)
1631 // check if first line is before any available src lines
1634 src1= srcptr[1]+(0)*stride[1];
1635 src2= srcptr[2]+(0)*stride[2];
1637 src1= srcptr[1]+(y1-y/2-1)*stride[1];
1638 src2= srcptr[2]+(y1-y/2-1)*stride[2];
1640 hcscale(uvbuf0, dstUVw, src1, src2, srcWidth, s_xinc2);
1643 // check if second line is after any available src lines
1646 src1= srcptr[1]+(h/2-1)*stride[1];
1647 src2= srcptr[2]+(h/2-1)*stride[2];
1649 src1= srcptr[1]+(y1-y/2)*stride[1];
1650 src2= srcptr[2]+(y1-y/2)*stride[2];
1652 hcscale(uvbuf1, dstUVw, src1, src2, srcWidth, s_xinc2);
1654 // the min() is required to avoid reuseing lines which where not available
1655 s_last_y1pos= MIN(y1, y/2+h/2-1);
1658 if(dstbpp==12) //YV12
1659 yuv2yuv(buf0, buf1, uvbuf0, uvbuf1, dest, uDest, vDest, dstw, yalpha, uvalpha);
1660 else if(ABS(s_yinc - 0x10000) < 10)
1661 yuv2rgb1(buf0, buf1, uvbuf0, uvbuf1, dest, dstw, yalpha, uvalpha, dstbpp);
1663 yuv2rgbX(buf0, buf1, uvbuf0, uvbuf1, dest, dstw, yalpha, uvalpha, dstbpp);
1666 b16Dither= b16Dither1;
1667 b16Dither1= b16Dither2;
1668 b16Dither2= b16Dither;
1670 g16Dither= g16Dither1;
1671 g16Dither1= g16Dither2;
1672 g16Dither2= g16Dither;
1677 __asm __volatile(SFENCE:::"memory");
1678 __asm __volatile(EMMS:::"memory");
1683 void SwScale_Init(){
1684 // generating tables:
1688 clip_table[i+256]=i;
1689 clip_table[i+512]=255;
1690 yuvtab_2568[i]=(0x2568*(i-16))+(256<<13);
1691 yuvtab_3343[i]=0x3343*(i-128);
1692 yuvtab_0c92[i]=-0x0c92*(i-128);
1693 yuvtab_1a1e[i]=-0x1a1e*(i-128);
1694 yuvtab_40cf[i]=0x40cf*(i-128);
1697 for(i=0; i<768; i++)
1699 int v= clip_table[i];
1700 clip_table16b[i]= v>>3;
1701 clip_table16g[i]= (v<<3)&0x07E0;
1702 clip_table16r[i]= (v<<8)&0xF800;
1703 clip_table15b[i]= v>>3;
1704 clip_table15g[i]= (v<<2)&0x03E0;
1705 clip_table15r[i]= (v<<7)&0x7C00;