From cb1a3eecac2d3395bf1e26289643082b4305f86a Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos Date: Wed, 23 Aug 2017 14:19:14 +0200 Subject: [PATCH] lsws/rgb2rgb: Add unscaled 48bit to 64bit rgb conversion. Based on b4befca2 and 6b7849e6 by Paul B Mahol. Fixes ticket #6608. --- libswscale/rgb2rgb.c | 38 +++++++++++++++++++++++++++++++++++ libswscale/rgb2rgb.h | 4 ++++ libswscale/swscale_unscaled.c | 17 ++++++++++++++++ libswscale/version.h | 2 +- 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/libswscale/rgb2rgb.c b/libswscale/rgb2rgb.c index f7f8188af1..04b7908b5e 100644 --- a/libswscale/rgb2rgb.c +++ b/libswscale/rgb2rgb.c @@ -391,3 +391,41 @@ void rgb64to48_ ## need_bswap(const uint8_t *src, \ DEFINE_RGB64TO48(nobswap, 0) DEFINE_RGB64TO48(bswap, 1) + +#define DEFINE_RGB48TOBGR64(need_bswap, swap) \ +void rgb48tobgr64_ ## need_bswap(const uint8_t *src, \ + uint8_t *dst, int src_size) \ +{ \ + uint16_t *d = (uint16_t *)dst; \ + uint16_t *s = (uint16_t *)src; \ + int i, num_pixels = src_size / 6; \ + \ + for (i = 0; i < num_pixels; i++) { \ + d[4 * i ] = swap ? av_bswap16(s[3 * i + 2]) : s[3 * i + 2]; \ + d[4 * i + 1] = swap ? av_bswap16(s[3 * i + 1]) : s[3 * i + 1]; \ + d[4 * i + 2] = swap ? av_bswap16(s[3 * i ]) : s[3 * i ]; \ + d[4 * i + 3] = 0xFFFF; \ + } \ +} + +DEFINE_RGB48TOBGR64(nobswap, 0) +DEFINE_RGB48TOBGR64(bswap, 1) + +#define DEFINE_RGB48TO64(need_bswap, swap) \ +void rgb48to64_ ## need_bswap(const uint8_t *src, \ + uint8_t *dst, int src_size) \ +{ \ + uint16_t *d = (uint16_t *)dst; \ + uint16_t *s = (uint16_t *)src; \ + int i, num_pixels = src_size / 6; \ + \ + for (i = 0; i < num_pixels; i++) { \ + d[4 * i ] = swap ? av_bswap16(s[3 * i ]) : s[3 * i ]; \ + d[4 * i + 1] = swap ? av_bswap16(s[3 * i + 1]) : s[3 * i + 1]; \ + d[4 * i + 2] = swap ? av_bswap16(s[3 * i + 2]) : s[3 * i + 2]; \ + d[4 * i + 3] = 0xFFFF; \ + } \ +} + +DEFINE_RGB48TO64(nobswap, 0) +DEFINE_RGB48TO64(bswap, 1) diff --git a/libswscale/rgb2rgb.h b/libswscale/rgb2rgb.h index 0645404eee..6994839299 100644 --- a/libswscale/rgb2rgb.h +++ b/libswscale/rgb2rgb.h @@ -59,6 +59,10 @@ void rgb48tobgr48_nobswap(const uint8_t *src, uint8_t *dst, int src_size); void rgb48tobgr48_bswap(const uint8_t *src, uint8_t *dst, int src_size); void rgb64to48_nobswap(const uint8_t *src, uint8_t *dst, int src_size); void rgb64to48_bswap(const uint8_t *src, uint8_t *dst, int src_size); +void rgb48tobgr64_nobswap(const uint8_t *src, uint8_t *dst, int src_size); +void rgb48tobgr64_bswap(const uint8_t *src, uint8_t *dst, int src_size); +void rgb48to64_nobswap(const uint8_t *src, uint8_t *dst, int src_size); +void rgb48to64_bswap(const uint8_t *src, uint8_t *dst, int src_size); void rgb24to32(const uint8_t *src, uint8_t *dst, int src_size); void rgb32to24(const uint8_t *src, uint8_t *dst, int src_size); void rgb16tobgr32(const uint8_t *src, uint8_t *dst, int src_size); diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c index 3b1b3667ce..ef36aec500 100644 --- a/libswscale/swscale_unscaled.c +++ b/libswscale/swscale_unscaled.c @@ -1292,6 +1292,23 @@ static rgbConvFn findRgbConvFn(SwsContext *c) || CONV_IS(BGR48LE, RGB48BE) || CONV_IS(RGB48BE, BGR48LE) || CONV_IS(BGR48BE, RGB48LE)) conv = rgb48tobgr48_bswap; + } else if (isRGB48(srcFormat) && isRGBA64(dstFormat)) { + if (CONV_IS(RGB48LE, BGRA64LE) + || CONV_IS(BGR48LE, RGBA64LE) + || CONV_IS(RGB48BE, BGRA64BE) + || CONV_IS(BGR48BE, RGBA64BE)) conv = rgb48tobgr64_nobswap; + else if (CONV_IS(RGB48LE, BGRA64BE) + || CONV_IS(BGR48LE, RGBA64BE) + || CONV_IS(RGB48BE, BGRA64LE) + || CONV_IS(BGR48BE, RGBA64LE)) conv = rgb48tobgr64_bswap; + if (CONV_IS(RGB48LE, RGBA64LE) + || CONV_IS(BGR48LE, BGRA64LE) + || CONV_IS(RGB48BE, RGBA64BE) + || CONV_IS(BGR48BE, BGRA64BE)) conv = rgb48to64_nobswap; + else if (CONV_IS(RGB48LE, RGBA64BE) + || CONV_IS(BGR48LE, BGRA64BE) + || CONV_IS(RGB48BE, RGBA64LE) + || CONV_IS(BGR48BE, BGRA64LE)) conv = rgb48to64_bswap; } else if (isRGBA64(srcFormat) && isRGB48(dstFormat)) { if (CONV_IS(RGBA64LE, BGR48LE) || CONV_IS(BGRA64LE, RGB48LE) diff --git a/libswscale/version.h b/libswscale/version.h index 8dff77e48a..dcf7959b23 100644 --- a/libswscale/version.h +++ b/libswscale/version.h @@ -28,7 +28,7 @@ #define LIBSWSCALE_VERSION_MAJOR 4 #define LIBSWSCALE_VERSION_MINOR 7 -#define LIBSWSCALE_VERSION_MICRO 102 +#define LIBSWSCALE_VERSION_MICRO 103 #define LIBSWSCALE_VERSION_INT AV_VERSION_INT(LIBSWSCALE_VERSION_MAJOR, \ LIBSWSCALE_VERSION_MINOR, \