2 // Software scaling and colorspace conversion routines for MPlayer
7 #undef HAVE_MMX2 //code is buggy
10 #define RET 0xC3 //near return opcode
12 // temporary storage for 4 yuv lines:
13 // 16bit for now (mmx likes it more compact)
14 static uint16_t pix_buf_y[4][2048];
15 static uint16_t pix_buf_uv[2][2048*2];
17 // clipping helper table for C implementations:
18 static unsigned char clip_table[768];
20 // yuv->rgb conversion tables:
21 static int yuvtab_2568[256];
22 static int yuvtab_3343[256];
23 static int yuvtab_0c92[256];
24 static int yuvtab_1a1e[256];
25 static int yuvtab_40cf[256];
27 static uint64_t yCoeff= 0x2568256825682568LL;
28 static uint64_t ubCoeff= 0x3343334333433343LL;
29 static uint64_t vrCoeff= 0x40cf40cf40cf40cfLL;
30 static uint64_t ugCoeff= 0xE5E2E5E2E5E2E5E2LL;
31 static uint64_t vgCoeff= 0xF36EF36EF36EF36ELL;
32 static uint64_t w80= 0x0080008000800080LL;
33 static uint64_t w10= 0x0010001000100010LL;
34 static uint64_t bm00000111=0x0000000000FFFFFFLL;
35 static uint64_t bm11111000=0xFFFFFFFFFF000000LL;
37 static uint64_t b16Dither= 0x0004000400040004LL;
38 static uint64_t b16Dither1=0x0004000400040004LL;
39 static uint64_t b16Dither2=0x0602060206020602LL;
40 static uint64_t g16Dither= 0x0002000200020002LL;
41 static uint64_t g16Dither1=0x0002000200020002LL;
42 static uint64_t g16Dither2=0x0301030103010301LL;
44 static uint64_t b16Mask= 0x001F001F001F001FLL;
45 static uint64_t g16Mask= 0x07E007E007E007E0LL;
46 static uint64_t r16Mask= 0xF800F800F800F800LL;
47 static uint64_t temp0;
49 static uint8_t funnyYCode[10000];
50 static uint8_t funnyUVCode[10000];
54 // *** bilinear scaling and yuv->rgb conversion of yv12 slices:
55 // *** Note: it's called multiple times while decoding a frame, first time y==0
56 // *** Designed to upscale, but may work for downscale too.
57 // s_xinc = (src_width << 8) / dst_width
58 // s_yinc = (src_height << 16) / dst_height
59 void SwScale_YV12slice_brg24(unsigned char* srcptr[],int stride[], int y, int h,
60 unsigned char* dstptr, int dststride, int dstw, int dstbpp,
61 unsigned int s_xinc,unsigned int s_yinc){
64 //static int s_yinc=(vo_dga_src_height<<16)/vo_dga_vp_height;
65 //static int s_xinc=(vo_dga_src_width<<8)/vo_dga_vp_width;
67 unsigned int s_xinc2=s_xinc>>1;
71 static int s_last_ypos;
72 static int static_dstw;
75 static int old_dstw= -1;
76 static int old_s_xinc= -1;
79 s_xinc&= -2; //clear last bit or uv and y might be shifted relative to each other
87 if(old_s_xinc != s_xinc || old_dstw!=dstw)
94 int xpos, xx, xalpha, i;
101 // create an optimized horizontal scaling routine
106 // printf("%d, %d\n", fragmentLength,imm8OfPShufW1);
112 "movq (%%esi, %%ebx), %%mm0 \n\t" //FIXME Alignment
113 "movq %%mm0, %%mm1 \n\t"
114 "psrlq $8, %%mm0 \n\t"
115 "punpcklbw %%mm7, %%mm1 \n\t"
116 "punpcklbw %%mm7, %%mm0 \n\t"
117 "pshufw $0xFF, %%mm1, %%mm1 \n\t"
119 "pshufw $0xFF, %%mm0, %%mm0 \n\t"
121 "psubw %%mm1, %%mm0 \n\t"
122 "psraw $1, %%mm0 \n\t"
123 "pmullw %%mm2, %%mm0 \n\t"
124 "psllw $7, %%mm1 \n\t"
125 "paddw %%mm1, %%mm0 \n\t"
126 "movq %%mm0, (%%edi, %%eax) \n\t"
127 "paddb %%mm6, %%mm2 \n\t" // 2*alpha += xpos&0xFF
129 "addb %%ch, %%cl \n\t" //2*xalpha += (4*s_xinc)&0xFF
130 "adcl %%edx, %%ebx \n\t" //xx+= (4*s_xinc)>>8 + carry
132 "addl $8, %%eax \n\t"
145 :"=r" (fragment), "=r" (imm8OfPShufW1), "=r" (imm8OfPShufW2),
146 "=r" (fragmentLength)
150 //FIXME choose size and or xinc so that they fit exactly
151 for(i=0; i<dstw/8; i++)
158 int b=((xpos+s_xinc)>>8) - xx;
159 int c=((xpos+s_xinc*2)>>8) - xx;
160 int d=((xpos+s_xinc*3)>>8) - xx;
162 memcpy(funnyYCode + fragmentLength*i/4, fragment, fragmentLength);
164 funnyYCode[fragmentLength*i/4 + imm8OfPShufW1]=
165 funnyYCode[fragmentLength*i/4 + imm8OfPShufW2]=
166 a | (b<<2) | (c<<4) | (d<<6);
168 funnyYCode[fragmentLength*(i+4)/4]= RET;
174 //FIXME choose size and or xinc so that they fit exactly
175 for(i=0; i<dstw/8; i++)
182 int b=((xpos+s_xinc2)>>8) - xx;
183 int c=((xpos+s_xinc2*2)>>8) - xx;
184 int d=((xpos+s_xinc2*3)>>8) - xx;
186 memcpy(funnyUVCode + fragmentLength*i/4, fragment, fragmentLength);
188 funnyUVCode[fragmentLength*i/4 + imm8OfPShufW1]=
189 funnyUVCode[fragmentLength*i/4 + imm8OfPShufW2]=
190 a | (b<<2) | (c<<4) | (d<<6);
192 funnyUVCode[fragmentLength*(i+4)/4]= RET;
196 // funnyCode[0]= RET;
204 unsigned char *dest=dstptr+dststride*s_ypos;
205 int y0=2+(s_srcypos>>16);
206 int y1=1+(s_srcypos>>17);
207 int yalpha=(s_srcypos&0xFFFF)>>7;
208 int yalpha1=yalpha^511;
209 int uvalpha=((s_srcypos>>1)&0xFFFF)>>7;
210 int uvalpha1=uvalpha^511;
211 uint16_t *buf0=pix_buf_y[y0&3];
212 uint16_t *buf1=pix_buf_y[((y0+1)&3)];
213 uint16_t *uvbuf0=pix_buf_uv[y1&1];
214 uint16_t *uvbuf1=pix_buf_uv[(y1&1)^1];
219 s_ypos++; s_srcypos+=s_yinc;
222 unsigned char *src=srcptr[0]+(y0-y)*stride[0];
225 // *** horizontal scale Y line to temp buffer
226 // this loop should be rewritten in MMX assembly!!!!
229 "pxor %%mm7, %%mm7 \n\t"
230 "pxor %%mm2, %%mm2 \n\t" // 2*xalpha
231 "movd %5, %%mm6 \n\t" // s_xinc&0xFF
232 "punpcklwd %%mm6, %%mm6 \n\t"
233 "punpcklwd %%mm6, %%mm6 \n\t"
234 "movq %%mm6, %%mm2 \n\t"
235 "psllq $16, %%mm2 \n\t"
236 "paddb %%mm6, %%mm2 \n\t"
237 "psllq $16, %%mm2 \n\t"
238 "paddb %%mm6, %%mm2 \n\t"
239 "psllq $16, %%mm2 \n\t" //0,t,2t,3t t=s_xinc&0xFF
240 "movq %%mm2, temp0 \n\t"
241 "movd %4, %%mm6 \n\t" //(s_xinc*4)&0xFF
242 "punpcklwd %%mm6, %%mm6 \n\t"
243 "punpcklwd %%mm6, %%mm6 \n\t"
244 "xorl %%eax, %%eax \n\t" // i
245 "xorl %%ebx, %%ebx \n\t" // xx
246 "movl %0, %%esi \n\t" // src
247 "movl %1, %%edi \n\t" // buf1
248 "movl %3, %%edx \n\t" // (s_xinc*4)>>8
249 "xorl %%ecx, %%ecx \n\t"
250 "movb %4, %%ch \n\t" // (s_xinc*4)&0xFF
252 "call funnyYCode \n\t"
253 "movq temp0, %%mm2 \n\t"
254 "xorb %%cl, %%cl \n\t"
255 "call funnyYCode \n\t"
256 "movq temp0, %%mm2 \n\t"
257 "xorb %%cl, %%cl \n\t"
258 "call funnyYCode \n\t"
259 "movq temp0, %%mm2 \n\t"
260 "xorb %%cl, %%cl \n\t"
261 "call funnyYCode \n\t"
262 "movq temp0, %%mm2 \n\t"
263 "xorb %%cl, %%cl \n\t"
264 "call funnyYCode \n\t"
265 "movq temp0, %%mm2 \n\t"
266 "xorb %%cl, %%cl \n\t"
267 "call funnyYCode \n\t"
268 "movq temp0, %%mm2 \n\t"
269 "xorb %%cl, %%cl \n\t"
270 "call funnyYCode \n\t"
271 "movq temp0, %%mm2 \n\t"
272 "xorb %%cl, %%cl \n\t"
273 "call funnyYCode \n\t"
274 :: "m" (src), "m" (buf1), "m" (dstw), "m" ((s_xinc*4)>>8),
275 "m" ((s_xinc*4)&0xFF), "m" (s_xinc&0xFF)
276 : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi"
279 #elif defined (ARCH_X86)
280 //NO MMX just normal asm ... FIXME try/write funny MMX2 variant
283 "xorl %%eax, %%eax \n\t" // i
284 "xorl %%ebx, %%ebx \n\t" // xx
285 "xorl %%ecx, %%ecx \n\t" // 2*xalpha
287 "movzbl (%0, %%ebx), %%edi \n\t" //src[xx]
288 "movzbl 1(%0, %%ebx), %%esi \n\t" //src[xx+1]
289 "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
290 "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
291 "shll $8, %%edi \n\t"
292 "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
293 "movl %1, %%edi \n\t"
294 "shrl $1, %%esi \n\t"
295 "movw %%si, (%%edi, %%eax, 2) \n\t"
296 "addb %4, %%cl \n\t" //2*xalpha += s_xinc&0xFF
297 "adcl %3, %%ebx \n\t" //xx+= s_xinc>>8 + carry
299 "movzbl (%0, %%ebx), %%edi \n\t" //src[xx]
300 "movzbl 1(%0, %%ebx), %%esi \n\t" //src[xx+1]
301 "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
302 "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
303 "shll $8, %%edi \n\t"
304 "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
305 "movl %1, %%edi \n\t"
306 "shrl $1, %%esi \n\t"
307 "movw %%si, 2(%%edi, %%eax, 2) \n\t"
308 "addb %4, %%cl \n\t" //2*xalpha += s_xinc&0xFF
309 "adcl %3, %%ebx \n\t" //xx+= s_xinc>>8 + carry
312 "addl $2, %%eax \n\t"
313 "cmpl %2, %%eax \n\t"
317 :: "r" (src), "m" (buf1), "m" (dstw), "m" (s_xinc>>8), "m" (s_xinc&0xFF)
318 : "%eax", "%ebx", "%ecx", "%edi", "%esi"
322 register unsigned int xx=xpos>>8;
323 register unsigned int xalpha=(xpos&0xFF)>>1;
324 buf1[i]=(src[xx]*(xalpha^127)+src[xx+1]*xalpha);
328 // *** horizontal scale U and V lines to temp buffer
330 unsigned char *src1=srcptr[1]+(y1-y/2)*stride[1];
331 unsigned char *src2=srcptr[2]+(y1-y/2)*stride[2];
333 // this loop should be rewritten in MMX assembly!!!!
336 "pxor %%mm7, %%mm7 \n\t"
337 "pxor %%mm2, %%mm2 \n\t" // 2*xalpha
338 "movd %5, %%mm6 \n\t" // s_xinc&0xFF
339 "punpcklwd %%mm6, %%mm6 \n\t"
340 "punpcklwd %%mm6, %%mm6 \n\t"
341 "movq %%mm6, %%mm2 \n\t"
342 "psllq $16, %%mm2 \n\t"
343 "paddb %%mm6, %%mm2 \n\t"
344 "psllq $16, %%mm2 \n\t"
345 "paddb %%mm6, %%mm2 \n\t"
346 "psllq $16, %%mm2 \n\t" //0,t,2t,3t t=s_xinc&0xFF
347 "movq %%mm2, temp0 \n\t"
348 "movd %4, %%mm6 \n\t" //(s_xinc*4)&0xFF
349 "punpcklwd %%mm6, %%mm6 \n\t"
350 "punpcklwd %%mm6, %%mm6 \n\t"
351 "xorl %%eax, %%eax \n\t" // i
352 "xorl %%ebx, %%ebx \n\t" // xx
353 "movl %0, %%esi \n\t" // src
354 "movl %1, %%edi \n\t" // buf1
355 "movl %3, %%edx \n\t" // (s_xinc*4)>>8
356 "xorl %%ecx, %%ecx \n\t"
357 "movb %4, %%ch \n\t" // (s_xinc*4)&0xFF
359 "call funnyUVCode \n\t"
360 "movq temp0, %%mm2 \n\t"
361 "xorb %%cl, %%cl \n\t"
362 "call funnyUVCode \n\t"
363 "movq temp0, %%mm2 \n\t"
364 "xorb %%cl, %%cl \n\t"
365 "call funnyUVCode \n\t"
366 "movq temp0, %%mm2 \n\t"
367 "xorb %%cl, %%cl \n\t"
368 "call funnyUVCode \n\t"
369 "movq temp0, %%mm2 \n\t"
370 "xorb %%cl, %%cl \n\t"
371 "call funnyUVCode \n\t"
372 "movq temp0, %%mm2 \n\t"
373 "xorb %%cl, %%cl \n\t"
374 "call funnyUVCode \n\t"
375 "movq temp0, %%mm2 \n\t"
376 "xorb %%cl, %%cl \n\t"
377 "call funnyUVCode \n\t"
378 "movq temp0, %%mm2 \n\t"
379 "xorb %%cl, %%cl \n\t"
380 "call funnyUVCode \n\t"
382 "xorl %%eax, %%eax \n\t" // i
383 "xorl %%ebx, %%ebx \n\t" // xx
384 "movl %6, %%esi \n\t" // src
385 "movl %1, %%edi \n\t" // buf1
386 "addl $4096, %%edi \n\t"
388 "call funnyUVCode \n\t"
389 "movq temp0, %%mm2 \n\t"
390 "xorb %%cl, %%cl \n\t"
391 "call funnyUVCode \n\t"
392 "movq temp0, %%mm2 \n\t"
393 "xorb %%cl, %%cl \n\t"
394 "call funnyUVCode \n\t"
395 "movq temp0, %%mm2 \n\t"
396 "xorb %%cl, %%cl \n\t"
397 "call funnyUVCode \n\t"
398 "movq temp0, %%mm2 \n\t"
399 "xorb %%cl, %%cl \n\t"
400 "call funnyUVCode \n\t"
401 "movq temp0, %%mm2 \n\t"
402 "xorb %%cl, %%cl \n\t"
403 "call funnyUVCode \n\t"
404 "movq temp0, %%mm2 \n\t"
405 "xorb %%cl, %%cl \n\t"
406 "call funnyUVCode \n\t"
407 "movq temp0, %%mm2 \n\t"
408 "xorb %%cl, %%cl \n\t"
409 "call funnyUVCode \n\t"
411 :: "m" (src1), "m" (uvbuf1), "m" (dstw), "m" ((s_xinc2*4)>>8),
412 "m" ((s_xinc2*4)&0xFF), "m" (s_xinc2&0xFF), "m" (src2)
413 : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi"
416 #elif defined (ARCH_X86)
418 "xorl %%eax, %%eax \n\t" // i
419 "xorl %%ebx, %%ebx \n\t" // xx
420 "xorl %%ecx, %%ecx \n\t" // 2*xalpha
422 "movl %0, %%esi \n\t"
423 "movzbl (%%esi, %%ebx), %%edi \n\t" //src[xx]
424 "movzbl 1(%%esi, %%ebx), %%esi \n\t" //src[xx+1]
425 "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
426 "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
427 "shll $8, %%edi \n\t"
428 "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
429 "movl %1, %%edi \n\t"
430 "shrl $1, %%esi \n\t"
431 "movw %%si, (%%edi, %%eax, 2) \n\t"
433 "movzbl (%5, %%ebx), %%edi \n\t" //src[xx]
434 "movzbl 1(%5, %%ebx), %%esi \n\t" //src[xx+1]
435 "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
436 "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
437 "shll $8, %%edi \n\t"
438 "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
439 "movl %1, %%edi \n\t"
440 "shrl $1, %%esi \n\t"
441 "movw %%si, 4096(%%edi, %%eax, 2)\n\t"
443 "addb %4, %%cl \n\t" //2*xalpha += s_xinc&0xFF
444 "adcl %3, %%ebx \n\t" //xx+= s_xinc>>8 + carry
445 "addl $1, %%eax \n\t"
446 "cmpl %2, %%eax \n\t"
450 :: "m" (src1), "m" (uvbuf1), "m" (dstw), "m" (s_xinc2>>8), "m" (s_xinc2&0xFF),
452 : "%eax", "%ebx", "%ecx", "%edi", "%esi"
456 register unsigned int xx=xpos>>8;
457 register unsigned int xalpha=(xpos&0xFF)>>1;
458 uvbuf1[i]=(src1[xx]*(xalpha^127)+src1[xx+1]*xalpha);
459 uvbuf1[i+2048]=(src2[xx]*(xalpha^127)+src2[xx+1]*xalpha);
467 // Note1: this code can be resticted to n*8 (or n*16) width lines to simplify optimization...
468 // Re: Note1: ok n*4 for now
469 // Note2: instead of using lookup tabs, mmx version could do the multiply...
471 // Note3: maybe we should make separated 15/16, 24 and 32bpp version of this:
472 // Re: done (32 & 16) and 16 has dithering :) but 16 is untested
474 //FIXME write lq version with less uv ...
475 //FIXME reorder / optimize
480 #define YSCALEYUV2RGB \
481 "pxor %%mm7, %%mm7 \n\t"\
482 "movd %6, %%mm6 \n\t" /*yalpha1*/\
483 "punpcklwd %%mm6, %%mm6 \n\t"\
484 "punpcklwd %%mm6, %%mm6 \n\t"\
485 "movd %7, %%mm5 \n\t" /*uvalpha1*/\
486 "punpcklwd %%mm5, %%mm5 \n\t"\
487 "punpcklwd %%mm5, %%mm5 \n\t"\
488 "xorl %%eax, %%eax \n\t"\
490 "movq (%0, %%eax, 2), %%mm0 \n\t" /*buf0[eax]*/\
491 "movq (%1, %%eax, 2), %%mm1 \n\t" /*buf1[eax]*/\
492 "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\
493 "pmulhw %%mm6, %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
494 "psraw $7, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>7*/\
495 "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
496 "psubw w10, %%mm1 \n\t" /* Y-16*/\
497 "psllw $3, %%mm1 \n\t" /* (y-16)*8*/\
498 "pmulhw yCoeff, %%mm1 \n\t"\
500 "movq (%2, %%eax,2), %%mm2 \n\t" /* uvbuf0[eax]*/\
501 "movq (%3, %%eax,2), %%mm3 \n\t" /* uvbuf1[eax]*/\
502 "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\
503 "pmulhw %%mm5, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\
504 "psraw $7, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>7*/\
505 "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\
506 "psubw w80, %%mm3 \n\t" /* (U-128)*/\
507 "psllw $3, %%mm3 \n\t" /*(U-128)8*/\
509 "movq 4096(%2, %%eax,2), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\
510 "movq 4096(%3, %%eax,2), %%mm0 \n\t" /* uvbuf1[eax+2048]*/\
511 "psubw %%mm0, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\
512 "pmulhw %%mm5, %%mm4 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\
513 "psraw $7, %%mm0 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>7*/\
514 "paddw %%mm4, %%mm0 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\
515 "psubw w80, %%mm0 \n\t" /* (V-128)*/\
516 "psllw $3, %%mm0 \n\t" /* (V-128)8*/\
518 "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
519 "pmulhw ubCoeff, %%mm3 \n\t"\
520 "paddw %%mm1, %%mm3 \n\t" /* B*/\
522 "movq %%mm0, %%mm4 \n\t" /* (V-128)8*/\
523 "pmulhw vrCoeff, %%mm0 \n\t"\
524 "paddw %%mm1, %%mm0 \n\t" /* R*/\
526 "pmulhw ugCoeff, %%mm2 \n\t"\
527 "pmulhw vgCoeff, %%mm4 \n\t"\
528 "paddw %%mm4, %%mm2 \n\t"\
529 "paddw %%mm2, %%mm1 \n\t" /* G*/\
531 "packuswb %%mm3, %%mm3 \n\t"\
532 "packuswb %%mm0, %%mm0 \n\t"\
533 "packuswb %%mm1, %%mm1 \n\t"
536 "punpcklbw %%mm1, %%mm3 \n\t" // BGBGBGBG
537 "punpcklbw %%mm7, %%mm0 \n\t" // R0R0R0R0
539 "movq %%mm3, %%mm1 \n\t"
540 "punpcklwd %%mm0, %%mm3 \n\t" // BGR0BGR0
541 "punpckhwd %%mm0, %%mm1 \n\t" // BGR0BGR0
543 "movntq %%mm3, (%4, %%eax, 4) \n\t"
544 "movntq %%mm1, 8(%4, %%eax, 4) \n\t"
546 "movq %%mm3, (%4, %%eax, 4) \n\t"
547 "movq %%mm1, 8(%4, %%eax, 4) \n\t"
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"
591 "movntq %%mm3, (%%ebx, %%eax, 2)\n\t"
592 "movntq %%mm1, 8(%%ebx, %%eax, 2)\n\t"
594 "movd %%mm3, (%%ebx, %%eax, 2) \n\t"
595 "psrlq $32, %%mm3 \n\t"
596 "movd %%mm3, 4(%%ebx, %%eax, 2) \n\t"
597 "movd %%mm1, 8(%%ebx, %%eax, 2) \n\t"
599 "addl $4, %%eax \n\t"
600 "cmpl %5, %%eax \n\t"
603 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "m" (dest), "m" (dstw),
604 "m" (yalpha1), "m" (uvalpha1)
613 "paddusb g16Dither, %%mm1 \n\t"
614 "paddusb b16Dither, %%mm0 \n\t"
615 "paddusb b16Dither, %%mm3 \n\t"
616 "punpcklbw %%mm7, %%mm1 \n\t" // 0G0G0G0G
617 "punpcklbw %%mm7, %%mm3 \n\t" // 0B0B0B0B
618 "punpcklbw %%mm7, %%mm0 \n\t" // 0R0R0R0R
620 "psrlw $3, %%mm3 \n\t"
621 "psllw $3, %%mm1 \n\t"
622 "psllw $8, %%mm0 \n\t"
623 "pand g16Mask, %%mm1 \n\t"
624 "pand r16Mask, %%mm0 \n\t"
626 "por %%mm3, %%mm1 \n\t"
627 "por %%mm1, %%mm0 \n\t"
629 "movntq %%mm0, (%4, %%eax, 2) \n\t"
631 "movq %%mm0, (%4, %%eax, 2) \n\t"
633 "addl $4, %%eax \n\t"
634 "cmpl %5, %%eax \n\t"
637 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
638 "m" (yalpha1), "m" (uvalpha1)
643 if(dstbpp==32 || dstbpp==24)
646 // vertical linear interpolation && yuv2rgb in a single step:
647 int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>16)];
648 int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>16);
649 int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>16);
650 dest[0]=clip_table[((Y + yuvtab_3343[U]) >>13)];
651 dest[1]=clip_table[((Y + yuvtab_0c92[V] + yuvtab_1a1e[U]) >>13)];
652 dest[2]=clip_table[((Y + yuvtab_40cf[V]) >>13)];
659 // vertical linear interpolation && yuv2rgb in a single step:
660 int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>16)];
661 int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>16);
662 int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>16);
664 ((uint16_t*)dest)[0] =
665 (clip_table[((Y + yuvtab_3343[U]) >>13)]>>3) |
666 (clip_table[((Y + yuvtab_0c92[V] + yuvtab_1a1e[U]) >>13)]<<3)&0x07E0 |
667 (clip_table[((Y + yuvtab_40cf[V]) >>13)]<<8)&0xF800;
671 else if(dstbpp==15) //15bit FIXME how do i figure out if its 15 or 16?
674 // vertical linear interpolation && yuv2rgb in a single step:
675 int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>16)];
676 int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>16);
677 int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>16);
679 ((uint16_t*)dest)[0] =
680 (clip_table[((Y + yuvtab_3343[U]) >>13)]>>3) |
681 (clip_table[((Y + yuvtab_0c92[V] + yuvtab_1a1e[U]) >>13)]<<2)&0x03E0 |
682 (clip_table[((Y + yuvtab_40cf[V]) >>13)]<<7)&0x7C00;
688 b16Dither= b16Dither1;
689 b16Dither1= b16Dither2;
690 b16Dither2= b16Dither;
692 g16Dither= g16Dither1;
693 g16Dither1= g16Dither2;
694 g16Dither2= g16Dither;
698 asm volatile("femms");
699 #elif defined (HAVE_MMX)
700 asm volatile("emms");
708 // generating tables:
713 clip_table[i+512]=255;
714 yuvtab_2568[i]=(0x2568*(i-16))+(256<<13);
715 yuvtab_3343[i]=0x3343*(i-128);
716 yuvtab_0c92[i]=-0x0c92*(i-128);
717 yuvtab_1a1e[i]=-0x1a1e*(i-128);
718 yuvtab_40cf[i]=0x40cf*(i-128);