From af2faf2076b96ab85cc51d5e970574079373c396 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Thu, 9 Jun 2011 18:13:53 -0400 Subject: swscale: split YUYV output out of yuv2packed[12X]_c(). This is part of the Great Evil Plan to simplify swscale. --- libswscale/swscale.c | 181 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 137 insertions(+), 44 deletions(-) (limited to 'libswscale') diff --git a/libswscale/swscale.c b/libswscale/swscale.c index 39aac0c67b..bc076dd3f2 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -626,7 +626,117 @@ yuv2mono_1_c_template(SwsContext *c, const uint16_t *buf0, YUV2PACKEDWRAPPER(yuv2mono, white, PIX_FMT_MONOWHITE); YUV2PACKEDWRAPPER(yuv2mono, black, PIX_FMT_MONOBLACK); -#define YSCALE_YUV_2_PACKEDX_C(type,alpha) \ +static av_always_inline void +yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter, + const int16_t **lumSrc, int lumFilterSize, + const int16_t *chrFilter, const int16_t **chrUSrc, + const int16_t **chrVSrc, int chrFilterSize, + const int16_t **alpSrc, uint8_t *dest, int dstW, + int y, enum PixelFormat target) +{ + int i; + +#define output_pixels(pos, Y1, U, Y2, V) \ + if (target == PIX_FMT_YUYV422) { \ + dest[pos + 0] = Y1; \ + dest[pos + 1] = U; \ + dest[pos + 2] = Y2; \ + dest[pos + 3] = V; \ + } else { \ + dest[pos + 0] = U; \ + dest[pos + 1] = Y1; \ + dest[pos + 2] = V; \ + dest[pos + 3] = Y2; \ + } + + for (i = 0; i < (dstW >> 1); i++) { + int j; + int Y1 = 1 << 18; + int Y2 = 1 << 18; + int U = 1 << 18; + int V = 1 << 18; + + for (j = 0; j < lumFilterSize; j++) { + Y1 += lumSrc[j][i * 2] * lumFilter[j]; + Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j]; + } + for (j = 0; j < chrFilterSize; j++) { + U += chrUSrc[j][i] * chrFilter[j]; + V += chrVSrc[j][i] * chrFilter[j]; + } + Y1 >>= 19; + Y2 >>= 19; + U >>= 19; + V >>= 19; + if ((Y1 | Y2 | U | V) & 0x100) { + Y1 = av_clip_uint8(Y1); + Y2 = av_clip_uint8(Y2); + U = av_clip_uint8(U); + V = av_clip_uint8(V); + } + output_pixels(4*i, Y1, U, Y2, V); + } +} + +static av_always_inline void +yuv2422_2_c_template(SwsContext *c, const uint16_t *buf0, + const uint16_t *buf1, const uint16_t *ubuf0, + const uint16_t *ubuf1, const uint16_t *vbuf0, + const uint16_t *vbuf1, const uint16_t *abuf0, + const uint16_t *abuf1, uint8_t *dest, int dstW, + int yalpha, int uvalpha, int y, + enum PixelFormat target) +{ + int yalpha1 = 4095 - yalpha; + int uvalpha1 = 4095 - uvalpha; + int i; + + for (i = 0; i < (dstW >> 1); i++) { + int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19; + int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19; + int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19; + int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19; + + output_pixels(i * 4, Y1, U, Y2, V); + } +} + +static av_always_inline void +yuv2422_1_c_template(SwsContext *c, const uint16_t *buf0, + const uint16_t *ubuf0, const uint16_t *ubuf1, + const uint16_t *vbuf0, const uint16_t *vbuf1, + const uint16_t *abuf0, uint8_t *dest, int dstW, + int uvalpha, enum PixelFormat dstFormat, + int flags, int y, enum PixelFormat target) +{ + int i; + + if (uvalpha < 2048) { + for (i = 0; i < (dstW >> 1); i++) { + int Y1 = buf0[i * 2] >> 7; + int Y2 = buf0[i * 2 + 1] >> 7; + int U = ubuf1[i] >> 7; + int V = vbuf1[i] >> 7; + + output_pixels(i * 4, Y1, U, Y2, V); + } + } else { + for (i = 0; i < (dstW >> 1); i++) { + int Y1 = buf0[i * 2] >> 7; + int Y2 = buf0[i * 2 + 1] >> 7; + int U = (ubuf0[i] + ubuf1[i]) >> 8; + int V = (vbuf0[i] + vbuf1[i]) >> 8; + + output_pixels(i * 4, Y1, U, Y2, V); + } + } +#undef output_pixels +} + +YUV2PACKEDWRAPPER(yuv2422, yuyv, PIX_FMT_YUYV422); +YUV2PACKEDWRAPPER(yuv2422, uyvy, PIX_FMT_UYVY422); + +#define YSCALE_YUV_2_RGBX_C(type,alpha) \ for (i=0; i<(dstW>>1); i++) {\ int j;\ int Y1 = 1<<18;\ @@ -668,7 +778,11 @@ YUV2PACKEDWRAPPER(yuv2mono, black, PIX_FMT_MONOBLACK); A1 = av_clip_uint8(A1); \ A2 = av_clip_uint8(A2); \ }\ - } + }\ + /* FIXME fix tables so that clipping is not needed and then use _NOCLIP*/\ + r = (type *)c->table_rV[V]; \ + g = (type *)(c->table_gU[U] + c->table_gV[V]); \ + b = (type *)c->table_bU[U]; #define YSCALE_YUV_2_RGBX_FULL_C(rnd,alpha) \ for (i=0; itable_rV[V]; \ - g = (type *)(c->table_gU[U] + c->table_gV[V]); \ - b = (type *)c->table_bU[U]; - -#define YSCALE_YUV_2_PACKED2_C(type,alpha) \ +#define YSCALE_YUV_2_RGB2_C(type,alpha) \ for (i=0; i<(dstW>>1); i++) { \ const int i2= 2*i; \ int Y1= (buf0[i2 ]*yalpha1+buf1[i2 ]*yalpha)>>19; \ @@ -727,15 +835,12 @@ YUV2PACKEDWRAPPER(yuv2mono, black, PIX_FMT_MONOBLACK); if (alpha) {\ A1= (abuf0[i2 ]*yalpha1+abuf1[i2 ]*yalpha)>>19; \ A2= (abuf0[i2+1]*yalpha1+abuf1[i2+1]*yalpha)>>19; \ - } - -#define YSCALE_YUV_2_RGB2_C(type,alpha) \ - YSCALE_YUV_2_PACKED2_C(type,alpha)\ + }\ r = (type *)c->table_rV[V];\ g = (type *)(c->table_gU[U] + c->table_gV[V]);\ b = (type *)c->table_bU[U]; -#define YSCALE_YUV_2_PACKED1_C(type,alpha) \ +#define YSCALE_YUV_2_RGB1_C(type,alpha) \ for (i=0; i<(dstW>>1); i++) {\ const int i2= 2*i;\ int Y1= buf0[i2 ]>>7;\ @@ -747,15 +852,12 @@ YUV2PACKEDWRAPPER(yuv2mono, black, PIX_FMT_MONOBLACK); if (alpha) {\ A1= abuf0[i2 ]>>7;\ A2= abuf0[i2+1]>>7;\ - } - -#define YSCALE_YUV_2_RGB1_C(type,alpha) \ - YSCALE_YUV_2_PACKED1_C(type,alpha)\ + }\ r = (type *)c->table_rV[V];\ g = (type *)(c->table_gU[U] + c->table_gV[V]);\ b = (type *)c->table_bU[U]; -#define YSCALE_YUV_2_PACKED1B_C(type,alpha) \ +#define YSCALE_YUV_2_RGB1B_C(type,alpha) \ for (i=0; i<(dstW>>1); i++) {\ const int i2= 2*i;\ int Y1= buf0[i2 ]>>7;\ @@ -767,15 +869,12 @@ YUV2PACKEDWRAPPER(yuv2mono, black, PIX_FMT_MONOBLACK); if (alpha) {\ A1= abuf0[i2 ]>>7;\ A2= abuf0[i2+1]>>7;\ - } - -#define YSCALE_YUV_2_RGB1B_C(type,alpha) \ - YSCALE_YUV_2_PACKED1B_C(type,alpha)\ + }\ r = (type *)c->table_rV[V];\ g = (type *)(c->table_gU[U] + c->table_gV[V]);\ b = (type *)c->table_bU[U]; -#define YSCALE_YUV_2_ANYRGB_C(func, func2)\ +#define YSCALE_YUV_2_ANYRGB_C(func)\ switch(c->dstFormat) {\ case PIX_FMT_RGB48BE:\ case PIX_FMT_RGB48LE:\ @@ -951,22 +1050,6 @@ YUV2PACKEDWRAPPER(yuv2mono, black, PIX_FMT_MONOBLACK); }\ }\ break;\ - case PIX_FMT_YUYV422:\ - func2\ - ((uint8_t*)dest)[2*i2+0]= Y1;\ - ((uint8_t*)dest)[2*i2+1]= U;\ - ((uint8_t*)dest)[2*i2+2]= Y2;\ - ((uint8_t*)dest)[2*i2+3]= V;\ - } \ - break;\ - case PIX_FMT_UYVY422:\ - func2\ - ((uint8_t*)dest)[2*i2+0]= U;\ - ((uint8_t*)dest)[2*i2+1]= Y1;\ - ((uint8_t*)dest)[2*i2+2]= V;\ - ((uint8_t*)dest)[2*i2+3]= Y2;\ - } \ - break;\ } static void yuv2packedX_c(SwsContext *c, const int16_t *lumFilter, @@ -976,7 +1059,7 @@ static void yuv2packedX_c(SwsContext *c, const int16_t *lumFilter, const int16_t **alpSrc, uint8_t *dest, int dstW, int y) { int i; - YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGBX_C, YSCALE_YUV_2_PACKEDX_C(void,0)) + YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGBX_C) } static void yuv2rgbX_c_full(SwsContext *c, const int16_t *lumFilter, @@ -1079,7 +1162,7 @@ static void yuv2packed2_c(SwsContext *c, const uint16_t *buf0, int uvalpha1=4095-uvalpha; int i; - YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB2_C, YSCALE_YUV_2_PACKED2_C(void,0)) + YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB2_C) } /** @@ -1095,9 +1178,9 @@ static void yuv2packed1_c(SwsContext *c, const uint16_t *buf0, int i; if (uvalpha < 2048) { - YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB1_C, YSCALE_YUV_2_PACKED1_C(void,0)) + YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB1_C) } else { - YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB1B_C, YSCALE_YUV_2_PACKED1B_C(void,0)) + YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB1B_C) } } @@ -1771,6 +1854,16 @@ find_c_packed_planar_out_funcs(SwsContext *c, *yuv2packed2 = yuv2monoblack_2_c; *yuv2packedX = yuv2monoblack_X_c; break; + case PIX_FMT_YUYV422: + *yuv2packed1 = yuv2422yuyv_1_c; + *yuv2packed2 = yuv2422yuyv_2_c; + *yuv2packedX = yuv2422yuyv_X_c; + break; + case PIX_FMT_UYVY422: + *yuv2packed1 = yuv2422uyvy_1_c; + *yuv2packed2 = yuv2422uyvy_2_c; + *yuv2packedX = yuv2422uyvy_X_c; + break; default: *yuv2packed1 = yuv2packed1_c; *yuv2packed2 = yuv2packed2_c; -- cgit v1.2.3 From 103278f7b0b037a4a6184865ca9b8d021ec9be85 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Wed, 8 Jun 2011 19:16:39 -0700 Subject: libavutil/swscale: YUV444P10/YUV444P9 support. Also add missing glue code for recently added YUV422P10 formats to swscale. Signed-off-by: Ronald S. Bultje --- libswscale/swscale.c | 14 +++++++++++++- libswscale/swscale_internal.h | 12 ++++++++++++ libswscale/utils.c | 6 ++++++ 3 files changed, 31 insertions(+), 1 deletion(-) (limited to 'libswscale') diff --git a/libswscale/swscale.c b/libswscale/swscale.c index bc076dd3f2..ba89a0f4be 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -1821,7 +1821,7 @@ find_c_packed_planar_out_funcs(SwsContext *c, } else if (is16BPS(dstFormat)) { *yuv2yuvX = isBE(dstFormat) ? yuv2yuvX16BE_c : yuv2yuvX16LE_c; } else if (is9_OR_10BPS(dstFormat)) { - if (dstFormat == PIX_FMT_YUV420P9BE || dstFormat == PIX_FMT_YUV420P9LE) { + if (av_pix_fmt_descriptors[dstFormat].comp[0].depth_minus1 == 8) { *yuv2yuvX = isBE(dstFormat) ? yuv2yuvX9BE_c : yuv2yuvX9LE_c; } else { *yuv2yuvX = isBE(dstFormat) ? yuv2yuvX10BE_c : yuv2yuvX10LE_c; @@ -2161,9 +2161,15 @@ static av_cold void sws_init_swScale_c(SwsContext *c) case PIX_FMT_PAL8 : case PIX_FMT_BGR4_BYTE: case PIX_FMT_RGB4_BYTE: c->chrToYV12 = palToUV_c; break; + case PIX_FMT_YUV444P9BE: case PIX_FMT_YUV420P9BE: c->chrToYV12 = BE9ToUV_c; break; + case PIX_FMT_YUV444P9LE: case PIX_FMT_YUV420P9LE: c->chrToYV12 = LE9ToUV_c; break; + case PIX_FMT_YUV444P10BE: + case PIX_FMT_YUV422P10BE: case PIX_FMT_YUV420P10BE: c->chrToYV12 = BE10ToUV_c; break; + case PIX_FMT_YUV422P10LE: + case PIX_FMT_YUV444P10LE: case PIX_FMT_YUV420P10LE: c->chrToYV12 = LE10ToUV_c; break; case PIX_FMT_YUV420P16BE: case PIX_FMT_YUV422P16BE: @@ -2219,9 +2225,15 @@ static av_cold void sws_init_swScale_c(SwsContext *c) c->lumToYV12 = NULL; c->alpToYV12 = NULL; switch (srcFormat) { + case PIX_FMT_YUV444P9BE: case PIX_FMT_YUV420P9BE: c->lumToYV12 = BE9ToY_c; break; + case PIX_FMT_YUV444P9LE: case PIX_FMT_YUV420P9LE: c->lumToYV12 = LE9ToY_c; break; + case PIX_FMT_YUV444P10BE: + case PIX_FMT_YUV422P10BE: case PIX_FMT_YUV420P10BE: c->lumToYV12 = BE10ToY_c; break; + case PIX_FMT_YUV444P10LE: + case PIX_FMT_YUV422P10LE: case PIX_FMT_YUV420P10LE: c->lumToYV12 = LE10ToY_c; break; case PIX_FMT_YUYV422 : case PIX_FMT_YUV420P16BE: diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index 013eef9e31..483842e866 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -355,6 +355,12 @@ const char *sws_format_name(enum PixelFormat format); #define is9_OR_10BPS(x) ( \ (x)==PIX_FMT_YUV420P9LE \ || (x)==PIX_FMT_YUV420P9BE \ + || (x)==PIX_FMT_YUV444P9BE \ + || (x)==PIX_FMT_YUV444P9LE \ + || (x)==PIX_FMT_YUV422P10BE \ + || (x)==PIX_FMT_YUV422P10LE \ + || (x)==PIX_FMT_YUV444P10BE \ + || (x)==PIX_FMT_YUV444P10LE \ || (x)==PIX_FMT_YUV420P10LE \ || (x)==PIX_FMT_YUV420P10BE \ ) @@ -373,12 +379,18 @@ const char *sws_format_name(enum PixelFormat format); #define isPlanarYUV(x) ( \ isPlanar8YUV(x) \ || (x)==PIX_FMT_YUV420P9LE \ + || (x)==PIX_FMT_YUV444P9LE \ || (x)==PIX_FMT_YUV420P10LE \ + || (x)==PIX_FMT_YUV422P10LE \ + || (x)==PIX_FMT_YUV444P10LE \ || (x)==PIX_FMT_YUV420P16LE \ || (x)==PIX_FMT_YUV422P16LE \ || (x)==PIX_FMT_YUV444P16LE \ || (x)==PIX_FMT_YUV420P9BE \ + || (x)==PIX_FMT_YUV444P9BE \ || (x)==PIX_FMT_YUV420P10BE \ + || (x)==PIX_FMT_YUV422P10BE \ + || (x)==PIX_FMT_YUV444P10BE \ || (x)==PIX_FMT_YUV420P16BE \ || (x)==PIX_FMT_YUV422P16BE \ || (x)==PIX_FMT_YUV444P16BE \ diff --git a/libswscale/utils.c b/libswscale/utils.c index d552330ec5..213bf3a043 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -110,12 +110,18 @@ const char *swscale_license(void) || (x)==PIX_FMT_MONOWHITE \ || (x)==PIX_FMT_MONOBLACK \ || (x)==PIX_FMT_YUV420P9LE \ + || (x)==PIX_FMT_YUV444P9LE \ || (x)==PIX_FMT_YUV420P10LE \ + || (x)==PIX_FMT_YUV422P10LE \ + || (x)==PIX_FMT_YUV444P10LE \ || (x)==PIX_FMT_YUV420P16LE \ || (x)==PIX_FMT_YUV422P16LE \ || (x)==PIX_FMT_YUV444P16LE \ || (x)==PIX_FMT_YUV420P9BE \ + || (x)==PIX_FMT_YUV444P9BE \ || (x)==PIX_FMT_YUV420P10BE \ + || (x)==PIX_FMT_YUV444P10BE \ + || (x)==PIX_FMT_YUV422P10BE \ || (x)==PIX_FMT_YUV420P16BE \ || (x)==PIX_FMT_YUV422P16BE \ || (x)==PIX_FMT_YUV444P16BE \ -- cgit v1.2.3