Skip to content

Commit a686d34

Browse files
committed
swscale/swscale_unscaled: add unscaled conversion for AYUV/VUYA/UYVA
Signed-off-by: James Almer <[email protected]>
1 parent d6b2d08 commit a686d34

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

libswscale/rgb2rgb.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ void (*shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, int src_size);
5656
void (*shuffle_bytes_1230)(const uint8_t *src, uint8_t *dst, int src_size);
5757
void (*shuffle_bytes_3012)(const uint8_t *src, uint8_t *dst, int src_size);
5858
void (*shuffle_bytes_3210)(const uint8_t *src, uint8_t *dst, int src_size);
59+
void (*shuffle_bytes_3102)(const uint8_t *src, uint8_t *dst, int src_size);
60+
void (*shuffle_bytes_2013)(const uint8_t *src, uint8_t *dst, int src_size);
61+
void (*shuffle_bytes_2130)(const uint8_t *src, uint8_t *dst, int src_size);
62+
void (*shuffle_bytes_1203)(const uint8_t *src, uint8_t *dst, int src_size);
5963

6064

6165
void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc,

libswscale/rgb2rgb.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ extern void (*shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, int src_size
5252
extern void (*shuffle_bytes_1230)(const uint8_t *src, uint8_t *dst, int src_size);
5353
extern void (*shuffle_bytes_3012)(const uint8_t *src, uint8_t *dst, int src_size);
5454
extern void (*shuffle_bytes_3210)(const uint8_t *src, uint8_t *dst, int src_size);
55+
extern void (*shuffle_bytes_3102)(const uint8_t *src, uint8_t *dst, int src_size);
56+
extern void (*shuffle_bytes_2013)(const uint8_t *src, uint8_t *dst, int src_size);
57+
extern void (*shuffle_bytes_2130)(const uint8_t *src, uint8_t *dst, int src_size);
58+
extern void (*shuffle_bytes_1203)(const uint8_t *src, uint8_t *dst, int src_size);
5559

5660
void rgb64tobgr48_nobswap(const uint8_t *src, uint8_t *dst, int src_size);
5761
void rgb64tobgr48_bswap(const uint8_t *src, uint8_t *dst, int src_size);

libswscale/rgb2rgb_template.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ static void shuffle_bytes_##name (const uint8_t *src, \
359359
DEFINE_SHUFFLE_BYTES(1230_c, 1, 2, 3, 0)
360360
DEFINE_SHUFFLE_BYTES(3012_c, 3, 0, 1, 2)
361361
DEFINE_SHUFFLE_BYTES(3210_c, 3, 2, 1, 0)
362+
DEFINE_SHUFFLE_BYTES(3102_c, 3, 1, 0, 2)
363+
DEFINE_SHUFFLE_BYTES(2013_c, 2, 0, 1, 3)
364+
DEFINE_SHUFFLE_BYTES(2130_c, 2, 1, 3, 0)
365+
DEFINE_SHUFFLE_BYTES(1203_c, 1, 2, 0, 3)
362366

363367
static inline void rgb24tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size)
364368
{
@@ -970,6 +974,10 @@ static av_cold void rgb2rgb_init_c(void)
970974
shuffle_bytes_1230 = shuffle_bytes_1230_c;
971975
shuffle_bytes_3012 = shuffle_bytes_3012_c;
972976
shuffle_bytes_3210 = shuffle_bytes_3210_c;
977+
shuffle_bytes_3102 = shuffle_bytes_3102_c;
978+
shuffle_bytes_2013 = shuffle_bytes_2013_c;
979+
shuffle_bytes_2130 = shuffle_bytes_2130_c;
980+
shuffle_bytes_1203 = shuffle_bytes_1203_c;
973981
rgb32tobgr16 = rgb32tobgr16_c;
974982
rgb32tobgr15 = rgb32tobgr15_c;
975983
yv12toyuy2 = yv12toyuy2_c;

libswscale/swscale_unscaled.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,13 @@ static int bayer_to_yv12_wrapper(SwsInternal *c, const uint8_t *const src[],
14971497
|| (x) == AV_PIX_FMT_BGR48BE \
14981498
)
14991499

1500+
#define isAYUV(x) ( \
1501+
(x) == AV_PIX_FMT_AYUV \
1502+
|| (x) == AV_PIX_FMT_VUYA \
1503+
|| (x) == AV_PIX_FMT_VUYX \
1504+
|| (x) == AV_PIX_FMT_UYVA \
1505+
)
1506+
15001507
/* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */
15011508
typedef void (* rgbConvFn) (const uint8_t *, uint8_t *, int);
15021509
static rgbConvFn findRgbConvFn(SwsInternal *c)
@@ -1569,6 +1576,16 @@ static rgbConvFn findRgbConvFn(SwsInternal *c)
15691576
|| CONV_IS(BGRA64LE, BGR48BE)
15701577
|| CONV_IS(RGBA64BE, RGB48LE)
15711578
|| CONV_IS(BGRA64BE, BGR48LE)) conv = rgb64to48_bswap;
1579+
} else if (isAYUV(srcFormat) && isAYUV(dstFormat)) {
1580+
/* VUYX only for dst, to avoid copying undefined bytes */
1581+
if ( CONV_IS(AYUV, VUYA)
1582+
|| CONV_IS(AYUV, VUYX)
1583+
|| CONV_IS(VUYA, AYUV)) conv = shuffle_bytes_3210;
1584+
else if (CONV_IS(AYUV, UYVA)) conv = shuffle_bytes_2130;
1585+
else if (CONV_IS(VUYA, UYVA)) conv = shuffle_bytes_1203;
1586+
else if (CONV_IS(UYVA, AYUV)) conv = shuffle_bytes_3102;
1587+
else if (CONV_IS(UYVA, VUYA)
1588+
|| CONV_IS(UYVA, VUYX)) conv = shuffle_bytes_2013;
15721589
} else
15731590
/* BGR -> BGR */
15741591
if ((isBGRinInt(srcFormat) && isBGRinInt(dstFormat)) ||
@@ -2086,6 +2103,10 @@ void ff_get_unscaled_swscale(SwsInternal *c)
20862103
!(flags & SWS_ACCURATE_RND) && !(dstW&1))
20872104
c->convert_unscaled = bgr24ToYv12Wrapper;
20882105

2106+
/* AYUV/VUYA/UYVA -> AYUV/VUYA/UYVA */
2107+
if (isAYUV(srcFormat) && isAYUV(dstFormat) && findRgbConvFn(c))
2108+
c->convert_unscaled = rgbToRgbWrapper;
2109+
20892110
/* RGB/BGR -> RGB/BGR (no dither needed forms) */
20902111
if (isAnyRGB(srcFormat) && isAnyRGB(dstFormat) && findRgbConvFn(c)
20912112
&& (!needsDither || (c->flags&(SWS_FAST_BILINEAR|SWS_POINT))))

0 commit comments

Comments
 (0)