From 2778fdbe5424485d135a37d384d6449113a6c2b5 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Wed, 1 Jul 2015 19:40:26 +0000 Subject: swscale: implement YA8 output Signed-off-by: Paul B Mahol --- libswscale/output.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) (limited to 'libswscale/output.c') diff --git a/libswscale/output.c b/libswscale/output.c index f63af3b..09e3369 100644 --- a/libswscale/output.c +++ b/libswscale/output.c @@ -1917,6 +1917,97 @@ yuv2gbrp_full_X_c(SwsContext *c, const int16_t *lumFilter, } } +static void +yuv2ya8_1_c(SwsContext *c, const int16_t *buf0, + const int16_t *ubuf[2], const int16_t *vbuf[2], + const int16_t *abuf0, uint8_t *dest, int dstW, + int uvalpha, int y) +{ + int hasAlpha = !!abuf0; + int i; + + for (i = 0; i < dstW; i++) { + int Y = (buf0[i] + 64) >> 7; + int A; + + Y = av_clip_uint8(Y); + + if (hasAlpha) { + A = (abuf0[i] + 64) >> 7; + if (A & 0x100) + A = av_clip_uint8(A); + } + + dest[i * 2 ] = Y; + dest[i * 2 + 1] = hasAlpha ? A : 255; + } +} + +static void +yuv2ya8_2_c(SwsContext *c, const int16_t *buf[2], + const int16_t *ubuf[2], const int16_t *vbuf[2], + const int16_t *abuf[2], uint8_t *dest, int dstW, + int yalpha, int uvalpha, int y) +{ + int hasAlpha = abuf[0] && abuf[1]; + const int16_t *buf0 = buf[0], *buf1 = buf[1], + *abuf0 = hasAlpha ? abuf[0] : NULL, + *abuf1 = hasAlpha ? abuf[1] : NULL; + int yalpha1 = 4096 - yalpha; + int i; + + for (i = 0; i < dstW; i++) { + int Y = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19; + int A; + + Y = av_clip_uint8(Y); + + if (hasAlpha) { + A = (abuf0[i * 2] * yalpha1 + abuf1[i * 2] * yalpha) >> 19; + A = av_clip_uint8(A); + } + + dest[i * 2 ] = Y; + dest[i * 2 + 1] = hasAlpha ? A : 255; + } +} + +static void +yuv2ya8_X_c(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) +{ + int hasAlpha = !!alpSrc; + int i; + + for (i = 0; i < dstW; i++) { + int j; + int Y = 1 << 18, A = 1 << 18; + + for (j = 0; j < lumFilterSize; j++) + Y += lumSrc[j][i] * lumFilter[j]; + + Y >>= 19; + if (Y & 0x100) + Y = av_clip_uint8(Y); + + if (hasAlpha) { + for (j = 0; j < lumFilterSize; j++) + A += alpSrc[j][i] * lumFilter[j]; + + A >>= 19; + + if (A & 0x100) + A = av_clip_uint8(A); + } + + dest[2 * i ] = Y; + dest[2 * i + 1] = hasAlpha ? A : 255; + } +} + av_cold void ff_sws_init_output_funcs(SwsContext *c, yuv2planar1_fn *yuv2plane1, yuv2planarX_fn *yuv2planeX, @@ -2361,5 +2452,10 @@ av_cold void ff_sws_init_output_funcs(SwsContext *c, *yuv2packed2 = yuv2uyvy422_2_c; *yuv2packedX = yuv2uyvy422_X_c; break; + case AV_PIX_FMT_YA8: + *yuv2packed1 = yuv2ya8_1_c; + *yuv2packed2 = yuv2ya8_2_c; + *yuv2packedX = yuv2ya8_X_c; + break; } } -- cgit v1.1