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)
16 #define RET 0xC3 //near return opcode
20 known BUGS with known cause (no bugreports please!)
21 code reads 1 sample too much (might cause a sig11)
24 check alignment off everything
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;
50 // temporary storage for 4 yuv lines:
51 // 16bit for now (mmx likes it more compact)
52 static uint16_t pix_buf_y[4][2048];
53 static uint16_t pix_buf_uv[2][2048*2];
55 // clipping helper table for C implementations:
56 static unsigned char clip_table[768];
58 // yuv->rgb conversion tables:
59 static int yuvtab_2568[256];
60 static int yuvtab_3343[256];
61 static int yuvtab_0c92[256];
62 static int yuvtab_1a1e[256];
63 static int yuvtab_40cf[256];
66 static uint8_t funnyYCode[10000];
67 static uint8_t funnyUVCode[10000];
70 // *** bilinear scaling and yuv->rgb conversion of yv12 slices:
71 // *** Note: it's called multiple times while decoding a frame, first time y==0
72 // *** Designed to upscale, but may work for downscale too.
73 // s_xinc = (src_width << 16) / dst_width
74 // s_yinc = (src_height << 16) / dst_height
75 void SwScale_YV12slice_brg24(unsigned char* srcptr[],int stride[], int y, int h,
76 unsigned char* dstptr, int dststride, int dstw, int dstbpp,
77 unsigned int s_xinc,unsigned int s_yinc){
80 //static int s_yinc=(vo_dga_src_height<<16)/vo_dga_vp_height;
81 //static int s_xinc=(vo_dga_src_width<<8)/vo_dga_vp_width;
85 static int s_srcypos; // points to the dst Pixels center in the source (0 is the center of pixel 0,0 in src)
88 // last horzontally interpolated lines, used to avoid unnecessary calculations
89 static int s_last_ypos;
90 static int s_last_y1pos;
92 static int static_dstw;
95 // used to detect a horizontal size change
96 static int old_dstw= -1;
97 static int old_s_xinc= -1;
101 int srcWidth= (dstw*s_xinc + 0x8000)>>16;
104 canMMX2BeUsed= (s_xinc <= 0x10000 && (dstw&31)==0 && (srcWidth&15)==0) ? 1 : 0;
107 // match pixel 0 of the src to pixel 0 of dst and match pixel n-2 of src to pixel n-2 of dst
108 // n-2 is the last chrominance sample available
109 // FIXME this is not perfect, but noone shuld notice the difference, the more correct variant
110 // would be like the vertical one, but that would require some special code for the
111 // first and last pixel
112 if(canMMX2BeUsed) s_xinc+= 20;
113 else s_xinc = ((srcWidth-2)<<16)/(dstw-2) - 20;
116 // force calculation of the horizontal interpolation of the first line
124 // cant downscale !!!
125 if((old_s_xinc != s_xinc || old_dstw!=dstw) && canMMX2BeUsed)
132 int xpos, xx, xalpha, i;
139 // create an optimized horizontal scaling routine
147 "movq (%%esi), %%mm0 \n\t" //FIXME Alignment
148 "movq %%mm0, %%mm1 \n\t"
149 "psrlq $8, %%mm0 \n\t"
150 "punpcklbw %%mm7, %%mm1 \n\t"
151 "movq %%mm2, %%mm3 \n\t"
152 "punpcklbw %%mm7, %%mm0 \n\t"
153 "addw %%bx, %%cx \n\t" //2*xalpha += (4*s_xinc)&0xFFFF
154 "pshufw $0xFF, %%mm1, %%mm1 \n\t"
156 "adcl %%edx, %%esi \n\t" //xx+= (4*s_xinc)>>16 + carry
157 "pshufw $0xFF, %%mm0, %%mm0 \n\t"
159 "psrlw $9, %%mm3 \n\t"
160 "psubw %%mm1, %%mm0 \n\t"
161 "pmullw %%mm3, %%mm0 \n\t"
162 "paddw %%mm6, %%mm2 \n\t" // 2*alpha += xpos&0xFFFF
163 "psllw $7, %%mm1 \n\t"
164 "paddw %%mm1, %%mm0 \n\t"
166 "movq %%mm0, (%%edi, %%eax) \n\t"
168 "addl $8, %%eax \n\t"
181 :"=r" (fragment), "=r" (imm8OfPShufW1), "=r" (imm8OfPShufW2),
182 "=r" (fragmentLength)
185 xpos= 0; //s_xinc/2 - 0x8000; // difference between pixel centers
187 /* choose xinc so that all 8 parts fit exactly
188 Note: we cannot use just 1 part because it would not fit in the code cache */
189 // s_xinc2_diff= -((((s_xinc2*(dstw/8))&0xFFFF))/(dstw/8))-10;
190 // s_xinc_diff= -((((s_xinc*(dstw/8))&0xFFFF))/(dstw/8));
192 // s_xinc2_diff+= ((0x10000/(dstw/8)));
194 // s_xinc_diff= s_xinc2_diff*2;
196 // s_xinc2+= s_xinc2_diff;
197 // s_xinc+= s_xinc_diff;
199 // old_s_xinc= s_xinc;
201 for(i=0; i<dstw/8; i++)
208 int b=((xpos+s_xinc)>>16) - xx;
209 int c=((xpos+s_xinc*2)>>16) - xx;
210 int d=((xpos+s_xinc*3)>>16) - xx;
212 memcpy(funnyYCode + fragmentLength*i/4, fragment, fragmentLength);
214 funnyYCode[fragmentLength*i/4 + imm8OfPShufW1]=
215 funnyYCode[fragmentLength*i/4 + imm8OfPShufW2]=
216 a | (b<<2) | (c<<4) | (d<<6);
218 funnyYCode[fragmentLength*(i+4)/4]= RET;
223 xpos= 0; //s_xinc2/2 - 0x10000; // difference between centers of chrom samples
224 for(i=0; i<dstw/8; i++)
231 int b=((xpos+s_xinc2)>>16) - xx;
232 int c=((xpos+s_xinc2*2)>>16) - xx;
233 int d=((xpos+s_xinc2*3)>>16) - xx;
235 memcpy(funnyUVCode + fragmentLength*i/4, fragment, fragmentLength);
237 funnyUVCode[fragmentLength*i/4 + imm8OfPShufW1]=
238 funnyUVCode[fragmentLength*i/4 + imm8OfPShufW2]=
239 a | (b<<2) | (c<<4) | (d<<6);
241 funnyUVCode[fragmentLength*(i+4)/4]= RET;
245 // funnyCode[0]= RET;
253 unsigned char *dest=dstptr+dststride*s_ypos;
254 int y0=(s_srcypos + 0xFFFF)>>16; // first luminance source line number below the dst line
255 // points to the dst Pixels center in the source (0 is the center of pixel 0,0 in src)
256 int srcuvpos= s_srcypos + s_yinc/2 - 0x8000;
257 int y1=(srcuvpos + 0x1FFFF)>>17; // first chrominance source line number below the dst line
258 int yalpha=((s_srcypos-1)&0xFFFF)>>7;
259 int yalpha1=yalpha^511;
260 int uvalpha=((srcuvpos-1)&0x1FFFF)>>8;
261 int uvalpha1=uvalpha^511;
262 uint16_t *buf0=pix_buf_y[y0&1]; // top line of the interpolated slice
263 uint16_t *buf1=pix_buf_y[((y0+1)&1)]; // bottom line of the interpolated slice
264 uint16_t *uvbuf0=pix_buf_uv[y1&1]; // top line of the interpolated slice
265 uint16_t *uvbuf1=pix_buf_uv[(y1+1)&1]; // bottom line of the interpolated slice
268 // if this is before the first line than use only the first src line
269 if(y0==0) buf0= buf1;
270 if(y1==0) uvbuf0= uvbuf1; // yes we do have to check this, its not the same as y0==0
272 if(y0>=y+h) break; // FIXME wrong, skips last lines, but they are dupliactes anyway
274 // if this is after the last line than use only the last src line
287 s_ypos++; s_srcypos+=s_yinc;
289 //only interpolate the src line horizontally if we didnt do it allready
291 unsigned char *src=srcptr[0]+(y0-y)*stride[0];
294 // *** horizontal scale Y line to temp buffer
301 "pxor %%mm7, %%mm7 \n\t"
302 "pxor %%mm2, %%mm2 \n\t" // 2*xalpha
303 "movd %5, %%mm6 \n\t" // s_xinc&0xFFFF
304 "punpcklwd %%mm6, %%mm6 \n\t"
305 "punpcklwd %%mm6, %%mm6 \n\t"
306 "movq %%mm6, %%mm2 \n\t"
307 "psllq $16, %%mm2 \n\t"
308 "paddw %%mm6, %%mm2 \n\t"
309 "psllq $16, %%mm2 \n\t"
310 "paddw %%mm6, %%mm2 \n\t"
311 "psllq $16, %%mm2 \n\t" //0,t,2t,3t t=s_xinc&0xFF
312 "movq %%mm2, temp0 \n\t"
313 "movd %4, %%mm6 \n\t" //(s_xinc*4)&0xFFFF
314 "punpcklwd %%mm6, %%mm6 \n\t"
315 "punpcklwd %%mm6, %%mm6 \n\t"
316 "xorl %%eax, %%eax \n\t" // i
317 "movl %0, %%esi \n\t" // src
318 "movl %1, %%edi \n\t" // buf1
319 "movl %3, %%edx \n\t" // (s_xinc*4)>>16
320 "xorl %%ecx, %%ecx \n\t"
321 "xorl %%ebx, %%ebx \n\t"
322 "movw %4, %%bx \n\t" // (s_xinc*4)&0xFFFF
324 "call funnyYCode \n\t"
325 "movq temp0, %%mm2 \n\t"
326 "xorl %%ecx, %%ecx \n\t"
327 "call funnyYCode \n\t"
328 "movq temp0, %%mm2 \n\t"
329 "xorl %%ecx, %%ecx \n\t"
330 "call funnyYCode \n\t"
331 "movq temp0, %%mm2 \n\t"
332 "xorl %%ecx, %%ecx \n\t"
333 "call funnyYCode \n\t"
334 "movq temp0, %%mm2 \n\t"
335 "xorl %%ecx, %%ecx \n\t"
336 "call funnyYCode \n\t"
337 "movq temp0, %%mm2 \n\t"
338 "xorl %%ecx, %%ecx \n\t"
339 "call funnyYCode \n\t"
340 "movq temp0, %%mm2 \n\t"
341 "xorl %%ecx, %%ecx \n\t"
342 "call funnyYCode \n\t"
343 "movq temp0, %%mm2 \n\t"
344 "xorl %%ecx, %%ecx \n\t"
345 "call funnyYCode \n\t"
346 :: "m" (src), "m" (buf1), "m" (dstw), "m" ((s_xinc*4)>>16),
347 "m" ((s_xinc*4)&0xFFFF), "m" (s_xinc&0xFFFF)
348 : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi"
350 for(i=dstw-1; (i*s_xinc)>>16 >=srcWidth-1; i--) buf1[i] = src[srcWidth-1]*128;
355 //NO MMX just normal asm ... FIXME try/write funny MMX2 variant
358 "xorl %%eax, %%eax \n\t" // i
359 "xorl %%ebx, %%ebx \n\t" // xx
360 "xorl %%ecx, %%ecx \n\t" // 2*xalpha
362 "movzbl (%0, %%ebx), %%edi \n\t" //src[xx]
363 "movzbl 1(%0, %%ebx), %%esi \n\t" //src[xx+1]
364 "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
365 "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
366 "shll $16, %%edi \n\t"
367 "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
368 "movl %1, %%edi \n\t"
369 "shrl $9, %%esi \n\t"
370 "movw %%si, (%%edi, %%eax, 2) \n\t"
371 "addw %4, %%cx \n\t" //2*xalpha += s_xinc&0xFF
372 "adcl %3, %%ebx \n\t" //xx+= s_xinc>>8 + carry
374 "movzbl (%0, %%ebx), %%edi \n\t" //src[xx]
375 "movzbl 1(%0, %%ebx), %%esi \n\t" //src[xx+1]
376 "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
377 "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
378 "shll $16, %%edi \n\t"
379 "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
380 "movl %1, %%edi \n\t"
381 "shrl $9, %%esi \n\t"
382 "movw %%si, 2(%%edi, %%eax, 2) \n\t"
383 "addw %4, %%cx \n\t" //2*xalpha += s_xinc&0xFF
384 "adcl %3, %%ebx \n\t" //xx+= s_xinc>>8 + carry
387 "addl $2, %%eax \n\t"
388 "cmpl %2, %%eax \n\t"
392 :: "r" (src), "m" (buf1), "m" (dstw), "m" (s_xinc>>16), "m" (s_xinc&0xFFFF)
393 : "%eax", "%ebx", "%ecx", "%edi", "%esi"
396 } //if MMX2 cant be used
400 register unsigned int xx=xpos>>16;
401 register unsigned int xalpha=(xpos&0xFFFF)>>9;
402 buf1[i]=(src[xx]*(xalpha^127)+src[xx+1]*xalpha);
407 // *** horizontal scale U and V lines to temp buffer
408 if(s_last_y1pos!=y1){
409 unsigned char *src1=srcptr[1]+(y1-y/2)*stride[1];
410 unsigned char *src2=srcptr[2]+(y1-y/2)*stride[2];
418 "pxor %%mm7, %%mm7 \n\t"
419 "pxor %%mm2, %%mm2 \n\t" // 2*xalpha
420 "movd %5, %%mm6 \n\t" // s_xinc&0xFFFF
421 "punpcklwd %%mm6, %%mm6 \n\t"
422 "punpcklwd %%mm6, %%mm6 \n\t"
423 "movq %%mm6, %%mm2 \n\t"
424 "psllq $16, %%mm2 \n\t"
425 "paddw %%mm6, %%mm2 \n\t"
426 "psllq $16, %%mm2 \n\t"
427 "paddw %%mm6, %%mm2 \n\t"
428 "psllq $16, %%mm2 \n\t" //0,t,2t,3t t=s_xinc&0xFFFF
429 "movq %%mm2, temp0 \n\t"
430 "movd %4, %%mm6 \n\t" //(s_xinc*4)&0xFFFF
431 "punpcklwd %%mm6, %%mm6 \n\t"
432 "punpcklwd %%mm6, %%mm6 \n\t"
433 "xorl %%eax, %%eax \n\t" // i
434 "movl %0, %%esi \n\t" // src
435 "movl %1, %%edi \n\t" // buf1
436 "movl %3, %%edx \n\t" // (s_xinc*4)>>16
437 "xorl %%ecx, %%ecx \n\t"
438 "xorl %%ebx, %%ebx \n\t"
439 "movw %4, %%bx \n\t" // (s_xinc*4)&0xFFFF
442 #define FUNNYUVCODE \
443 "call funnyUVCode \n\t"\
444 "movq temp0, %%mm2 \n\t"\
445 "xorl %%ecx, %%ecx \n\t"
459 "xorl %%eax, %%eax \n\t" // i
460 "movl %6, %%esi \n\t" // src
461 "movl %1, %%edi \n\t" // buf1
462 "addl $4096, %%edi \n\t"
474 :: "m" (src1), "m" (uvbuf1), "m" (dstw), "m" ((s_xinc2*4)>>16),
475 "m" ((s_xinc2*4)&0xFFFF), "m" (s_xinc2&0xFFFF), "m" (src2)
476 : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi"
478 for(i=dstw-1; (i*s_xinc2)>>16 >=srcWidth/2-1; i--)
480 uvbuf1[i] = src1[srcWidth/2-1]*128;
481 uvbuf1[i+2048] = src2[srcWidth/2-1]*128;
488 "xorl %%eax, %%eax \n\t" // i
489 "xorl %%ebx, %%ebx \n\t" // xx
490 "xorl %%ecx, %%ecx \n\t" // 2*xalpha
492 "movl %0, %%esi \n\t"
493 "movzbl (%%esi, %%ebx), %%edi \n\t" //src[xx]
494 "movzbl 1(%%esi, %%ebx), %%esi \n\t" //src[xx+1]
495 "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
496 "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
497 "shll $16, %%edi \n\t"
498 "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
499 "movl %1, %%edi \n\t"
500 "shrl $9, %%esi \n\t"
501 "movw %%si, (%%edi, %%eax, 2) \n\t"
503 "movzbl (%5, %%ebx), %%edi \n\t" //src[xx]
504 "movzbl 1(%5, %%ebx), %%esi \n\t" //src[xx+1]
505 "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx]
506 "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha
507 "shll $16, %%edi \n\t"
508 "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha)
509 "movl %1, %%edi \n\t"
510 "shrl $9, %%esi \n\t"
511 "movw %%si, 4096(%%edi, %%eax, 2)\n\t"
513 "addw %4, %%cx \n\t" //2*xalpha += s_xinc&0xFF
514 "adcl %3, %%ebx \n\t" //xx+= s_xinc>>8 + carry
515 "addl $1, %%eax \n\t"
516 "cmpl %2, %%eax \n\t"
520 :: "m" (src1), "m" (uvbuf1), "m" (dstw), "m" (s_xinc2>>16), "m" (s_xinc2&0xFFFF),
522 : "%eax", "%ebx", "%ecx", "%edi", "%esi"
525 } //if MMX2 cant be used
529 register unsigned int xx=xpos>>16;
530 register unsigned int xalpha=(xpos&0xFFFF)>>9;
531 uvbuf1[i]=(src1[xx]*(xalpha^127)+src1[xx+1]*xalpha);
532 uvbuf1[i+2048]=(src2[xx]*(xalpha^127)+src2[xx+1]*xalpha);
536 // if this is the line before the first line
537 if(s_srcypos == s_xinc - 0x8000)
539 s_srcypos= s_yinc/2 - 0x8000;
545 // Note1: this code can be resticted to n*8 (or n*16) width lines to simplify optimization...
546 // Re: Note1: ok n*4 for now
547 // Note2: instead of using lookup tabs, mmx version could do the multiply...
549 // Note3: maybe we should make separated 15/16, 24 and 32bpp version of this:
550 // Re: done (32 & 16) and 16 has dithering :) but 16 is untested
552 //FIXME write lq version with less uv ...
553 //FIXME reorder / optimize
558 #define YSCALEYUV2RGB \
559 "pxor %%mm7, %%mm7 \n\t"\
560 "movd %6, %%mm6 \n\t" /*yalpha1*/\
561 "punpcklwd %%mm6, %%mm6 \n\t"\
562 "punpcklwd %%mm6, %%mm6 \n\t"\
563 "movd %7, %%mm5 \n\t" /*uvalpha1*/\
564 "punpcklwd %%mm5, %%mm5 \n\t"\
565 "punpcklwd %%mm5, %%mm5 \n\t"\
566 "xorl %%eax, %%eax \n\t"\
568 "movq (%0, %%eax, 2), %%mm0 \n\t" /*buf0[eax]*/\
569 "movq (%1, %%eax, 2), %%mm1 \n\t" /*buf1[eax]*/\
570 "movq (%2, %%eax,2), %%mm2 \n\t" /* uvbuf0[eax]*/\
571 "movq (%3, %%eax,2), %%mm3 \n\t" /* uvbuf1[eax]*/\
572 "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\
573 "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\
574 "pmulhw %%mm6, %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\
575 "pmulhw %%mm5, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\
576 "psraw $7, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>7*/\
577 "movq 4096(%2, %%eax,2), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\
578 "psraw $7, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>7*/\
579 "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\
580 "movq 4096(%3, %%eax,2), %%mm0 \n\t" /* uvbuf1[eax+2048]*/\
581 "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\
582 "psubw %%mm0, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\
583 "psubw w10, %%mm1 \n\t" /* Y-16*/\
584 "psubw w80, %%mm3 \n\t" /* (U-128)*/\
585 "psllw $3, %%mm1 \n\t" /* (y-16)*8*/\
586 "psllw $3, %%mm3 \n\t" /*(U-128)8*/\
587 "pmulhw yCoeff, %%mm1 \n\t"\
590 "pmulhw %%mm5, %%mm4 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\
591 "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\
592 "pmulhw ubCoeff, %%mm3 \n\t"\
593 "psraw $7, %%mm0 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>7*/\
594 "pmulhw ugCoeff, %%mm2 \n\t"\
595 "paddw %%mm4, %%mm0 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\
596 "psubw w80, %%mm0 \n\t" /* (V-128)*/\
597 "psllw $3, %%mm0 \n\t" /* (V-128)8*/\
600 "movq %%mm0, %%mm4 \n\t" /* (V-128)8*/\
601 "pmulhw vrCoeff, %%mm0 \n\t"\
602 "pmulhw vgCoeff, %%mm4 \n\t"\
603 "paddw %%mm1, %%mm3 \n\t" /* B*/\
604 "paddw %%mm1, %%mm0 \n\t" /* R*/\
605 "packuswb %%mm3, %%mm3 \n\t"\
607 "packuswb %%mm0, %%mm0 \n\t"\
608 "paddw %%mm4, %%mm2 \n\t"\
609 "paddw %%mm2, %%mm1 \n\t" /* G*/\
611 "packuswb %%mm1, %%mm1 \n\t"
614 "punpcklbw %%mm1, %%mm3 \n\t" // BGBGBGBG
615 "punpcklbw %%mm7, %%mm0 \n\t" // R0R0R0R0
617 "movq %%mm3, %%mm1 \n\t"
618 "punpcklwd %%mm0, %%mm3 \n\t" // BGR0BGR0
619 "punpckhwd %%mm0, %%mm1 \n\t" // BGR0BGR0
621 "movntq %%mm3, (%4, %%eax, 4) \n\t"
622 "movntq %%mm1, 8(%4, %%eax, 4) \n\t"
624 "movq %%mm3, (%4, %%eax, 4) \n\t"
625 "movq %%mm1, 8(%4, %%eax, 4) \n\t"
627 "addl $4, %%eax \n\t"
628 "cmpl %5, %%eax \n\t"
632 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
633 "m" (yalpha1), "m" (uvalpha1)
644 "punpcklbw %%mm1, %%mm3 \n\t" // BGBGBGBG
645 "punpcklbw %%mm7, %%mm0 \n\t" // R0R0R0R0
647 "movq %%mm3, %%mm1 \n\t"
648 "punpcklwd %%mm0, %%mm3 \n\t" // BGR0BGR0
649 "punpckhwd %%mm0, %%mm1 \n\t" // BGR0BGR0
651 "movq %%mm3, %%mm2 \n\t" // BGR0BGR0
652 "psrlq $8, %%mm3 \n\t" // GR0BGR00
653 "pand bm00000111, %%mm2 \n\t" // BGR00000
654 "pand bm11111000, %%mm3 \n\t" // 000BGR00
655 "por %%mm2, %%mm3 \n\t" // BGRBGR00
656 "movq %%mm1, %%mm2 \n\t"
657 "psllq $48, %%mm1 \n\t" // 000000BG
658 "por %%mm1, %%mm3 \n\t" // BGRBGRBG
660 "movq %%mm2, %%mm1 \n\t" // BGR0BGR0
661 "psrld $16, %%mm2 \n\t" // R000R000
662 "psrlq $24, %%mm1 \n\t" // 0BGR0000
663 "por %%mm2, %%mm1 \n\t" // RBGRR000
665 "movl %4, %%ebx \n\t"
666 "addl %%eax, %%ebx \n\t"
669 "movntq %%mm3, (%%ebx, %%eax, 2)\n\t"
670 "movntq %%mm1, 8(%%ebx, %%eax, 2)\n\t"
672 "movd %%mm3, (%%ebx, %%eax, 2) \n\t"
673 "psrlq $32, %%mm3 \n\t"
674 "movd %%mm3, 4(%%ebx, %%eax, 2) \n\t"
675 "movd %%mm1, 8(%%ebx, %%eax, 2) \n\t"
677 "addl $4, %%eax \n\t"
678 "cmpl %5, %%eax \n\t"
681 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "m" (dest), "m" (dstw),
682 "m" (yalpha1), "m" (uvalpha1)
692 "paddusb g16Dither, %%mm1 \n\t"
693 "paddusb b16Dither, %%mm0 \n\t"
694 "paddusb b16Dither, %%mm3 \n\t"
696 "punpcklbw %%mm7, %%mm1 \n\t" // 0G0G0G0G
697 "punpcklbw %%mm7, %%mm3 \n\t" // 0B0B0B0B
698 "punpcklbw %%mm7, %%mm0 \n\t" // 0R0R0R0R
700 "psrlw $3, %%mm3 \n\t"
701 "psllw $3, %%mm1 \n\t"
702 "psllw $8, %%mm0 \n\t"
703 "pand g16Mask, %%mm1 \n\t"
704 "pand r16Mask, %%mm0 \n\t"
706 "por %%mm3, %%mm1 \n\t"
707 "por %%mm1, %%mm0 \n\t"
709 "movntq %%mm0, (%4, %%eax, 2) \n\t"
711 "movq %%mm0, (%4, %%eax, 2) \n\t"
713 "addl $4, %%eax \n\t"
714 "cmpl %5, %%eax \n\t"
717 :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstw),
718 "m" (yalpha1), "m" (uvalpha1)
723 if(dstbpp==32 || dstbpp==24)
726 // vertical linear interpolation && yuv2rgb in a single step:
727 int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>16)];
728 int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>16);
729 int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>16);
730 dest[0]=clip_table[((Y + yuvtab_3343[U]) >>13)];
731 dest[1]=clip_table[((Y + yuvtab_0c92[V] + yuvtab_1a1e[U]) >>13)];
732 dest[2]=clip_table[((Y + yuvtab_40cf[V]) >>13)];
739 // vertical linear interpolation && yuv2rgb in a single step:
740 int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>16)];
741 int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>16);
742 int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>16);
744 ((uint16_t*)dest)[0] =
745 (clip_table[((Y + yuvtab_3343[U]) >>13)]>>3) |
746 (clip_table[((Y + yuvtab_0c92[V] + yuvtab_1a1e[U]) >>13)]<<3)&0x07E0 |
747 (clip_table[((Y + yuvtab_40cf[V]) >>13)]<<8)&0xF800;
751 else if(dstbpp==15) //15bit FIXME how do i figure out if its 15 or 16?
754 // vertical linear interpolation && yuv2rgb in a single step:
755 int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>16)];
756 int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>16);
757 int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>16);
759 ((uint16_t*)dest)[0] =
760 (clip_table[((Y + yuvtab_3343[U]) >>13)]>>3) |
761 (clip_table[((Y + yuvtab_0c92[V] + yuvtab_1a1e[U]) >>13)]<<2)&0x03E0 |
762 (clip_table[((Y + yuvtab_40cf[V]) >>13)]<<7)&0x7C00;
768 b16Dither= b16Dither1;
769 b16Dither1= b16Dither2;
770 b16Dither2= b16Dither;
772 g16Dither= g16Dither1;
773 g16Dither1= g16Dither2;
774 g16Dither2= g16Dither;
778 asm volatile("femms");
779 #elif defined (HAVE_MMX)
780 asm volatile("emms");
786 // generating tables:
791 clip_table[i+512]=255;
792 yuvtab_2568[i]=(0x2568*(i-16))+(256<<13);
793 yuvtab_3343[i]=0x3343*(i-128);
794 yuvtab_0c92[i]=-0x0c92*(i-128);
795 yuvtab_1a1e[i]=-0x1a1e*(i-128);
796 yuvtab_40cf[i]=0x40cf*(i-128);