comparison libswscale/yuv2rgb.c @ 28975:bab0430f2e59

Add YUVA420P -> RGBA/BGRA/ARGB/ABGR unscaled converters
author sdrik
date Fri, 20 Mar 2009 14:14:28 +0000
parents e538af2c69c1
children d78fdafe0def
comparison
equal deleted inserted replaced
28974:341e3ff25281 28975:bab0430f2e59
100 Y = src[2*i]; \ 100 Y = src[2*i]; \
101 dst[6*i+0] = b[Y]; dst[6*i+1] = g[Y]; dst[6*i+2] = r[Y]; \ 101 dst[6*i+0] = b[Y]; dst[6*i+1] = g[Y]; dst[6*i+2] = r[Y]; \
102 Y = src[2*i+1]; \ 102 Y = src[2*i+1]; \
103 dst[6*i+3] = b[Y]; dst[6*i+4] = g[Y]; dst[6*i+5] = r[Y]; 103 dst[6*i+3] = b[Y]; dst[6*i+4] = g[Y]; dst[6*i+5] = r[Y];
104 104
105 #define PUTRGBA(dst,ysrc,asrc,i,o,s) \
106 Y = ysrc[2*i+o]; \
107 dst[2*i ] = r[Y] + g[Y] + b[Y] + (asrc[2*i ]<<s); \
108 Y = ysrc[2*i+1-o]; \
109 dst[2*i+1] = r[Y] + g[Y] + b[Y] + (asrc[2*i+1]<<s);
110
105 #define YUV2RGBFUNC(func_name, dst_type, alpha) \ 111 #define YUV2RGBFUNC(func_name, dst_type, alpha) \
106 static int func_name(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, \ 112 static int func_name(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, \
107 int srcSliceH, uint8_t* dst[], int dstStride[]){\ 113 int srcSliceH, uint8_t* dst[], int dstStride[]){\
108 int y;\ 114 int y;\
109 \ 115 \
110 if (c->srcFormat == PIX_FMT_YUV422P) {\ 116 if (!alpha && c->srcFormat == PIX_FMT_YUV422P) {\
111 srcStride[1] *= 2;\ 117 srcStride[1] *= 2;\
112 srcStride[2] *= 2;\ 118 srcStride[2] *= 2;\
113 }\ 119 }\
114 for (y=0; y<srcSliceH; y+=2) {\ 120 for (y=0; y<srcSliceH; y+=2) {\
115 dst_type *dst_1 = (dst_type*)(dst[0] + (y+srcSliceY )*dstStride[0]);\ 121 dst_type *dst_1 = (dst_type*)(dst[0] + (y+srcSliceY )*dstStride[0]);\
118 dst_type *g;\ 124 dst_type *g;\
119 uint8_t *py_1 = src[0] + y*srcStride[0];\ 125 uint8_t *py_1 = src[0] + y*srcStride[0];\
120 uint8_t *py_2 = py_1 + srcStride[0];\ 126 uint8_t *py_2 = py_1 + srcStride[0];\
121 uint8_t *pu = src[1] + (y>>1)*srcStride[1];\ 127 uint8_t *pu = src[1] + (y>>1)*srcStride[1];\
122 uint8_t *pv = src[2] + (y>>1)*srcStride[2];\ 128 uint8_t *pv = src[2] + (y>>1)*srcStride[2];\
129 uint8_t av_unused *pa_1, *pa_2;\
123 unsigned int h_size = c->dstW>>3;\ 130 unsigned int h_size = c->dstW>>3;\
131 if (alpha){\
132 pa_1 = src[3] + y*srcStride[3];\
133 pa_2 = pa_1 + srcStride[3];\
134 }\
124 while (h_size--) {\ 135 while (h_size--) {\
125 int av_unused U, V;\ 136 int av_unused U, V;\
126 int Y;\ 137 int Y;\
127 138
128 #define ENDYUV2RGBLINE(dst_delta)\ 139 #define ENDYUV2RGBLINE(dst_delta)\
173 LOADCHROMA(1); 184 LOADCHROMA(1);
174 PUTRGB(dst_2,py_2,1,1); 185 PUTRGB(dst_2,py_2,1,1);
175 PUTRGB(dst_1,py_1,1,0); 186 PUTRGB(dst_1,py_1,1,0);
176 ENDYUV2RGBFUNC() 187 ENDYUV2RGBFUNC()
177 188
189 YUV2RGBFUNC(yuva2rgba_c, uint32_t, 1)
190 LOADCHROMA(0);
191 PUTRGBA(dst_1,py_1,pa_1,0,0,24);
192 PUTRGBA(dst_2,py_2,pa_2,0,1,24);
193
194 LOADCHROMA(1);
195 PUTRGBA(dst_2,py_2,pa_1,1,1,24);
196 PUTRGBA(dst_1,py_1,pa_2,1,0,24);
197 LOADCHROMA(1);
198 PUTRGBA(dst_2,py_2,pa_1,1,1,24);
199 PUTRGBA(dst_1,py_1,pa_2,1,0,24);
200
201 LOADCHROMA(2);
202 PUTRGBA(dst_1,py_1,pa_1,2,0,24);
203 PUTRGBA(dst_2,py_2,pa_2,2,1,24);
204
205 LOADCHROMA(3);
206 PUTRGBA(dst_2,py_2,pa_1,3,1,24);
207 PUTRGBA(dst_1,py_1,pa_2,3,0,24);
208 pa_1 += 8;\
209 pa_2 += 8;\
210 ENDYUV2RGBLINE(8)
211 LOADCHROMA(0);
212 PUTRGBA(dst_1,py_1,pa_1,0,0,24);
213 PUTRGBA(dst_2,py_2,pa_2,0,1,24);
214
215 LOADCHROMA(1);
216 PUTRGBA(dst_2,py_2,pa_1,1,1,24);
217 PUTRGBA(dst_1,py_1,pa_2,1,0,24);
218 ENDYUV2RGBFUNC()
219
220 YUV2RGBFUNC(yuva2argb_c, uint32_t, 1)
221 LOADCHROMA(0);
222 PUTRGBA(dst_1,py_1,pa_1,0,0,0);
223 PUTRGBA(dst_2,py_2,pa_2,0,1,0);
224
225 LOADCHROMA(1);
226 PUTRGBA(dst_2,py_2,pa_2,1,1,0);
227 PUTRGBA(dst_1,py_1,pa_1,1,0,0);
228 LOADCHROMA(1);
229 PUTRGBA(dst_2,py_2,pa_2,1,1,0);
230 PUTRGBA(dst_1,py_1,pa_1,1,0,0);
231
232 LOADCHROMA(2);
233 PUTRGBA(dst_1,py_1,pa_1,2,0,0);
234 PUTRGBA(dst_2,py_2,pa_2,2,1,0);
235
236 LOADCHROMA(3);
237 PUTRGBA(dst_2,py_2,pa_2,3,1,0);
238 PUTRGBA(dst_1,py_1,pa_1,3,0,0);
239 pa_1 += 8;\
240 pa_2 += 8;\
241 ENDYUV2RGBLINE(8)
242 LOADCHROMA(0);
243 PUTRGBA(dst_1,py_1,pa_1,0,0,0);
244 PUTRGBA(dst_2,py_2,pa_2,0,1,0);
245
246 LOADCHROMA(1);
247 PUTRGBA(dst_2,py_2,pa_2,1,1,0);
248 PUTRGBA(dst_1,py_1,pa_1,1,0,0);
249 ENDYUV2RGBFUNC()
250
178 YUV2RGBFUNC(yuv2rgb_c_24_rgb, uint8_t, 0) 251 YUV2RGBFUNC(yuv2rgb_c_24_rgb, uint8_t, 0)
179 LOADCHROMA(0); 252 LOADCHROMA(0);
180 PUTRGB24(dst_1,py_1,0); 253 PUTRGB24(dst_1,py_1,0);
181 PUTRGB24(dst_2,py_2,0); 254 PUTRGB24(dst_2,py_2,0);
182 255
431 { 504 {
432 SwsFunc t = NULL; 505 SwsFunc t = NULL;
433 #if (HAVE_MMX2 || HAVE_MMX) && CONFIG_GPL 506 #if (HAVE_MMX2 || HAVE_MMX) && CONFIG_GPL
434 if (c->flags & SWS_CPU_CAPS_MMX2) { 507 if (c->flags & SWS_CPU_CAPS_MMX2) {
435 switch (c->dstFormat) { 508 switch (c->dstFormat) {
436 case PIX_FMT_RGB32: return yuv420_rgb32_MMX2; 509 case PIX_FMT_RGB32:
510 if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P){
511 if (HAVE_7REGS) return yuva420_rgb32_MMX2;
512 }else return yuv420_rgb32_MMX2;
437 case PIX_FMT_BGR24: return yuv420_rgb24_MMX2; 513 case PIX_FMT_BGR24: return yuv420_rgb24_MMX2;
438 case PIX_FMT_RGB565: return yuv420_rgb16_MMX2; 514 case PIX_FMT_RGB565: return yuv420_rgb16_MMX2;
439 case PIX_FMT_RGB555: return yuv420_rgb15_MMX2; 515 case PIX_FMT_RGB555: return yuv420_rgb15_MMX2;
440 } 516 }
441 } 517 }
442 if (c->flags & SWS_CPU_CAPS_MMX) { 518 if (c->flags & SWS_CPU_CAPS_MMX) {
443 switch (c->dstFormat) { 519 switch (c->dstFormat) {
444 case PIX_FMT_RGB32: return yuv420_rgb32_MMX; 520 case PIX_FMT_RGB32:
521 if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P){
522 if (HAVE_7REGS) return yuva420_rgb32_MMX;
523 }else return yuv420_rgb32_MMX;
445 case PIX_FMT_BGR24: return yuv420_rgb24_MMX; 524 case PIX_FMT_BGR24: return yuv420_rgb24_MMX;
446 case PIX_FMT_RGB565: return yuv420_rgb16_MMX; 525 case PIX_FMT_RGB565: return yuv420_rgb16_MMX;
447 case PIX_FMT_RGB555: return yuv420_rgb15_MMX; 526 case PIX_FMT_RGB555: return yuv420_rgb15_MMX;
448 } 527 }
449 } 528 }
468 return t; 547 return t;
469 548
470 av_log(c, AV_LOG_WARNING, "No accelerated colorspace conversion found.\n"); 549 av_log(c, AV_LOG_WARNING, "No accelerated colorspace conversion found.\n");
471 550
472 switch (c->dstFormat) { 551 switch (c->dstFormat) {
473 case PIX_FMT_BGR32_1: 552 case PIX_FMT_ARGB:
474 case PIX_FMT_RGB32_1: 553 case PIX_FMT_ABGR: if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) return yuva2argb_c;
475 case PIX_FMT_BGR32: 554 case PIX_FMT_RGBA:
476 case PIX_FMT_RGB32: return yuv2rgb_c_32; 555 case PIX_FMT_BGRA: return (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) ? yuva2rgba_c : yuv2rgb_c_32;
477 case PIX_FMT_RGB24: return yuv2rgb_c_24_rgb; 556 case PIX_FMT_RGB24: return yuv2rgb_c_24_rgb;
478 case PIX_FMT_BGR24: return yuv2rgb_c_24_bgr; 557 case PIX_FMT_BGR24: return yuv2rgb_c_24_bgr;
479 case PIX_FMT_RGB565: 558 case PIX_FMT_RGB565:
480 case PIX_FMT_BGR565: 559 case PIX_FMT_BGR565:
481 case PIX_FMT_RGB555: 560 case PIX_FMT_RGB555:
532 || c->dstFormat==PIX_FMT_MONOBLACK; 611 || c->dstFormat==PIX_FMT_MONOBLACK;
533 const int bpp = fmt_depth(c->dstFormat); 612 const int bpp = fmt_depth(c->dstFormat);
534 uint8_t *y_table; 613 uint8_t *y_table;
535 uint16_t *y_table16; 614 uint16_t *y_table16;
536 uint32_t *y_table32; 615 uint32_t *y_table32;
537 int i, base, rbase, gbase, bbase, abase; 616 int i, base, rbase, gbase, bbase, abase, needAlpha;
538 const int yoffs = fullRange ? 384 : 326; 617 const int yoffs = fullRange ? 384 : 326;
539 618
540 int64_t crv = inv_table[0]; 619 int64_t crv = inv_table[0];
541 int64_t cbu = inv_table[1]; 620 int64_t cbu = inv_table[1];
542 int64_t cgu = -inv_table[2]; 621 int64_t cgu = -inv_table[2];
658 case 32: 737 case 32:
659 base = (c->dstFormat == PIX_FMT_RGB32_1 || c->dstFormat == PIX_FMT_BGR32_1) ? 8 : 0; 738 base = (c->dstFormat == PIX_FMT_RGB32_1 || c->dstFormat == PIX_FMT_BGR32_1) ? 8 : 0;
660 rbase = base + (isRgb ? 16 : 0); 739 rbase = base + (isRgb ? 16 : 0);
661 gbase = base + 8; 740 gbase = base + 8;
662 bbase = base + (isRgb ? 0 : 16); 741 bbase = base + (isRgb ? 0 : 16);
663 abase = (base + 24) & 31; 742 needAlpha = CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat);
743 if (!needAlpha)
744 abase = (base + 24) & 31;
664 c->yuvTable = av_malloc(1024*3*4); 745 c->yuvTable = av_malloc(1024*3*4);
665 y_table32 = c->yuvTable; 746 y_table32 = c->yuvTable;
666 yb = -(384<<16) - oy; 747 yb = -(384<<16) - oy;
667 for (i = 0; i < 1024; i++) { 748 for (i = 0; i < 1024; i++) {
668 uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16); 749 uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
669 y_table32[i ] = (yval << rbase) + (255 << abase); 750 y_table32[i ] = (yval << rbase) + (needAlpha ? 0 : (255 << abase));
670 y_table32[i+1024] = yval << gbase; 751 y_table32[i+1024] = yval << gbase;
671 y_table32[i+2048] = yval << bbase; 752 y_table32[i+2048] = yval << bbase;
672 yb += cy; 753 yb += cy;
673 } 754 }
674 fill_table(c->table_rV, 4, crv, y_table32 + yoffs); 755 fill_table(c->table_rV, 4, crv, y_table32 + yoffs);