[FFmpeg-devel] [PATCH 2/3] libswscale: add support for VUYX format

Philip Langdale philipl at overt.org
Sat Aug 20 05:14:35 EEST 2022


As we already have support for VUYA, I figured I should do the small
amount of work to support VUYX as well. That means a little refactoring
to share code.

Signed-off-by: Philip Langdale <philipl at overt.org>
---
 libswscale/input.c                       | 10 ++++---
 libswscale/output.c                      | 35 +++++++++++++++++++++---
 libswscale/utils.c                       |  1 +
 tests/ref/fate/filter-pixdesc-vuyx       |  1 +
 tests/ref/fate/filter-pixfmts-copy       |  1 +
 tests/ref/fate/filter-pixfmts-crop       |  1 +
 tests/ref/fate/filter-pixfmts-field      |  1 +
 tests/ref/fate/filter-pixfmts-fieldorder |  1 +
 tests/ref/fate/filter-pixfmts-hflip      |  1 +
 tests/ref/fate/filter-pixfmts-il         |  1 +
 tests/ref/fate/filter-pixfmts-null       |  1 +
 tests/ref/fate/filter-pixfmts-pad        |  1 +
 tests/ref/fate/filter-pixfmts-scale      |  1 +
 tests/ref/fate/filter-pixfmts-transpose  |  1 +
 tests/ref/fate/filter-pixfmts-vflip      |  1 +
 15 files changed, 50 insertions(+), 8 deletions(-)
 create mode 100644 tests/ref/fate/filter-pixdesc-vuyx

diff --git a/libswscale/input.c b/libswscale/input.c
index 1077d01e91..92681c9c53 100644
--- a/libswscale/input.c
+++ b/libswscale/input.c
@@ -659,7 +659,7 @@ static void read_ayuv64le_A_c(uint8_t *dst, const uint8_t *src, const uint8_t *u
         AV_WN16(dst + i * 2, AV_RL16(src + i * 8));
 }
 
-static void read_vuya_UV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, const uint8_t *src,
+static void read_vuyx_UV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, const uint8_t *src,
                            const uint8_t *unused1, int width, uint32_t *unused2, void *opq)
 {
     int i;
@@ -669,7 +669,7 @@ static void read_vuya_UV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0,
     }
 }
 
-static void read_vuya_Y_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused0, const uint8_t *unused1, int width,
+static void read_vuyx_Y_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused0, const uint8_t *unused1, int width,
                           uint32_t *unused2, void *opq)
 {
     int i;
@@ -1375,7 +1375,8 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c)
         break;
 #endif
     case AV_PIX_FMT_VUYA:
-        c->chrToYV12 = read_vuya_UV_c;
+    case AV_PIX_FMT_VUYX:
+        c->chrToYV12 = read_vuyx_UV_c;
         break;
     case AV_PIX_FMT_AYUV64LE:
         c->chrToYV12 = read_ayuv64le_UV_c;
@@ -1752,7 +1753,8 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c)
         c->lumToYV12 = read_ya16be_gray_c;
         break;
     case AV_PIX_FMT_VUYA:
-        c->lumToYV12 = read_vuya_Y_c;
+    case AV_PIX_FMT_VUYX:
+        c->lumToYV12 = read_vuyx_Y_c;
         break;
     case AV_PIX_FMT_AYUV64LE:
         c->lumToYV12 = read_ayuv64le_Y_c;
diff --git a/libswscale/output.c b/libswscale/output.c
index 74f992ae80..40a4476c6d 100644
--- a/libswscale/output.c
+++ b/libswscale/output.c
@@ -2585,13 +2585,14 @@ yuv2ayuv64le_X_c(SwsContext *c, const int16_t *lumFilter,
 }
 
 static void
-yuv2vuya_X_c(SwsContext *c, const int16_t *lumFilter,
+yuv2vuyX_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)
+             const int16_t **alpSrc, uint8_t *dest, int dstW, int y,
+             int destHasAlpha)
 {
-    int hasAlpha = !!alpSrc;
+    int hasAlpha = destHasAlpha && (!!alpSrc);
     int i;
 
     for (i = 0; i < dstW; i++) {
@@ -2634,10 +2635,33 @@ yuv2vuya_X_c(SwsContext *c, const int16_t *lumFilter,
         dest[4 * i    ] = V;
         dest[4 * i + 1] = U;
         dest[4 * i + 2] = Y;
-        dest[4 * i + 3] = A;
+        if (destHasAlpha)
+            dest[4 * i + 3] = A;
     }
 }
 
+static void
+yuv2vuya_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)
+{
+    yuv2vuyX_X_c(c, lumFilter, lumSrc, lumFilterSize, chrFilter,
+                 chrUSrc, chrVSrc, chrFilterSize, alpSrc, dest, dstW, y, 1);
+}
+
+static void
+yuv2vuyx_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)
+{
+    yuv2vuyX_X_c(c, lumFilter, lumSrc, lumFilterSize, chrFilter,
+                 chrUSrc, chrVSrc, chrFilterSize, alpSrc, dest, dstW, y, 0);
+}
+
 av_cold void ff_sws_init_output_funcs(SwsContext *c,
                                       yuv2planar1_fn *yuv2plane1,
                                       yuv2planarX_fn *yuv2planeX,
@@ -3143,5 +3167,8 @@ av_cold void ff_sws_init_output_funcs(SwsContext *c,
     case AV_PIX_FMT_VUYA:
         *yuv2packedX = yuv2vuya_X_c;
         break;
+    case AV_PIX_FMT_VUYX:
+        *yuv2packedX = yuv2vuyx_X_c;
+        break;
     }
 }
diff --git a/libswscale/utils.c b/libswscale/utils.c
index 9ef157c006..a621a35862 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -259,6 +259,7 @@ static const FormatEntry format_entries[] = {
     [AV_PIX_FMT_P416LE]      = { 1, 1 },
     [AV_PIX_FMT_NV16]        = { 1, 1 },
     [AV_PIX_FMT_VUYA]        = { 1, 1 },
+    [AV_PIX_FMT_VUYX]        = { 1, 1 },
     [AV_PIX_FMT_RGBAF16BE]   = { 1, 0 },
     [AV_PIX_FMT_RGBAF16LE]   = { 1, 0 },
 };
diff --git a/tests/ref/fate/filter-pixdesc-vuyx b/tests/ref/fate/filter-pixdesc-vuyx
new file mode 100644
index 0000000000..99871e05d0
--- /dev/null
+++ b/tests/ref/fate/filter-pixdesc-vuyx
@@ -0,0 +1 @@
+pixdesc-vuyx        ebc83f9793eb4eddbb0a37fdcb67a33d
diff --git a/tests/ref/fate/filter-pixfmts-copy b/tests/ref/fate/filter-pixfmts-copy
index 93dd611f97..371b94c62e 100644
--- a/tests/ref/fate/filter-pixfmts-copy
+++ b/tests/ref/fate/filter-pixfmts-copy
@@ -90,6 +90,7 @@ rgba64be            ae2ae04b5efedca3505f47c4dd6ea6ea
 rgba64le            b91e1d77f799eb92241a2d2d28437b15
 uyvy422             3bcf3c80047592f2211fae3260b1b65d
 vuya                3d5e934651cae1ce334001cb1829ad22
+vuyx                3f68ea6ec492b30d867cb5401562264e
 x2bgr10le           550c0d190cf695afa4eaacb644db6b75
 x2rgb10le           c1e3ac21be04a16bb157b22784524520
 xyz12be             a1ef56bf746d71f59669c28e48fc8450
diff --git a/tests/ref/fate/filter-pixfmts-crop b/tests/ref/fate/filter-pixfmts-crop
index 739b99713a..364e881aef 100644
--- a/tests/ref/fate/filter-pixfmts-crop
+++ b/tests/ref/fate/filter-pixfmts-crop
@@ -87,6 +87,7 @@ rgba                9488ac85abceaf99a9309eac5a87697e
 rgba64be            89910046972ab3c68e2a348302cc8ca9
 rgba64le            fea8ebfc869b52adf353778f29eac7a7
 vuya                76578a705ff3a37559653c1289bd03dd
+vuyx                5d2bae51a2f4892bd5f177f190cc323b
 x2bgr10le           84de725b85662c362862820dc4a309aa
 x2rgb10le           f4265aca7a67dbfa9354370098ca6f33
 xyz12be             cb4571f9aaa7b59f999ef327276104b7
diff --git a/tests/ref/fate/filter-pixfmts-field b/tests/ref/fate/filter-pixfmts-field
index e08161bc0d..768b3f474a 100644
--- a/tests/ref/fate/filter-pixfmts-field
+++ b/tests/ref/fate/filter-pixfmts-field
@@ -90,6 +90,7 @@ rgba64be            23c8c0edaabe3eaec89ce69633fb0048
 rgba64le            dfdba4de4a7cac9abf08852666c341d3
 uyvy422             1c49e44ab3f060e85fc4a3a9464f045e
 vuya                f72bcf29d75cd143d0c565f7cc49119a
+vuyx                6257cd1ce11330660e9fa9c675acbdcc
 x2bgr10le           dbe21538d7cb1744914f6bd46ec09b55
 x2rgb10le           a18bc4ae5274e0a8cca9137ecd50c677
 xyz12be             d2fa69ec91d3ed862f2dac3f8e7a3437
diff --git a/tests/ref/fate/filter-pixfmts-fieldorder b/tests/ref/fate/filter-pixfmts-fieldorder
index de5c4fe59b..258c8563f0 100644
--- a/tests/ref/fate/filter-pixfmts-fieldorder
+++ b/tests/ref/fate/filter-pixfmts-fieldorder
@@ -81,6 +81,7 @@ rgba64be            5598f44514d122b9a57c5c92c20bbc61
 rgba64le            b34e6e30621ae579519a2d91a96a0acf
 uyvy422             75de70e31c435dde878002d3f22b238a
 vuya                a3891d4168ff208948fd0b3ba0910495
+vuyx                d7a900e970c9a69ed41f8b220114b9fa
 x2bgr10le           86474d84f26c5c51d6f75bf7e1de8da8
 x2rgb10le           cdf6a9e8a8d081aa768c6ae2e6221676
 xyz12be             15f5cda71de5fef9cec5e75e3833b6bc
diff --git a/tests/ref/fate/filter-pixfmts-hflip b/tests/ref/fate/filter-pixfmts-hflip
index b0f6754bbf..6fbc472a4e 100644
--- a/tests/ref/fate/filter-pixfmts-hflip
+++ b/tests/ref/fate/filter-pixfmts-hflip
@@ -87,6 +87,7 @@ rgba                51961c723ea6707e0a410cd3f21f15d3
 rgba64be            c910444019f4cfbf4d995227af55da8d
 rgba64le            0c810d8b3a6bca10321788e1cb145340
 vuya                7e530261e7ac4eae4fd616fd7572d0b8
+vuyx                3ce9890363cad3984521293be1eb679c
 x2bgr10le           827cc659f29378e00c5a7d2c0ada8f9a
 x2rgb10le           d4a8189b65395a88d0a38a7053f3359f
 xyz12be             25f90259ff8a226befdaec3dfe82996e
diff --git a/tests/ref/fate/filter-pixfmts-il b/tests/ref/fate/filter-pixfmts-il
index 04efcb8a56..09748c2d08 100644
--- a/tests/ref/fate/filter-pixfmts-il
+++ b/tests/ref/fate/filter-pixfmts-il
@@ -89,6 +89,7 @@ rgba64be            db70d33aa6c06f3e0a1c77bd11284261
 rgba64le            a8a2daae04374a27219bc1c890204007
 uyvy422             d6ee3ca43356d08c392382b24b22cda5
 vuya                b9deab5ba249dd608b709c09255a4932
+vuyx                49cc92fcc002ec0f312017014dd68c0c
 x2bgr10le           135acaff8318cf9861bb0f7849a9e5e9
 x2rgb10le           517fb186f523dc7cdc5c5c6967cfbe94
 xyz12be             7c7d54c55f136cbbc50b18029f3be0b3
diff --git a/tests/ref/fate/filter-pixfmts-null b/tests/ref/fate/filter-pixfmts-null
index 93dd611f97..371b94c62e 100644
--- a/tests/ref/fate/filter-pixfmts-null
+++ b/tests/ref/fate/filter-pixfmts-null
@@ -90,6 +90,7 @@ rgba64be            ae2ae04b5efedca3505f47c4dd6ea6ea
 rgba64le            b91e1d77f799eb92241a2d2d28437b15
 uyvy422             3bcf3c80047592f2211fae3260b1b65d
 vuya                3d5e934651cae1ce334001cb1829ad22
+vuyx                3f68ea6ec492b30d867cb5401562264e
 x2bgr10le           550c0d190cf695afa4eaacb644db6b75
 x2rgb10le           c1e3ac21be04a16bb157b22784524520
 xyz12be             a1ef56bf746d71f59669c28e48fc8450
diff --git a/tests/ref/fate/filter-pixfmts-pad b/tests/ref/fate/filter-pixfmts-pad
index 0f00affdce..07aaea6b06 100644
--- a/tests/ref/fate/filter-pixfmts-pad
+++ b/tests/ref/fate/filter-pixfmts-pad
@@ -36,6 +36,7 @@ rgb0                0984eb985dabbe757ed6beb53db84eff
 rgb24               17f9e2e0c609009acaf2175c42d4a2a5
 rgba                b157c90191463d34fb3ce77b36c96386
 vuya                44368c0a758ee68e24ce976e3b1b8535
+vuyx                bc7c4f693a22cd1ac95e33d473086474
 xyz12le             23dadbbba70b2925ce75fb8ba8080ba3
 ya16le              8dbfcb586abf626da7d1aca887a581b9
 ya8                 495daaca2dcb4f7aeba7652768b41ced
diff --git a/tests/ref/fate/filter-pixfmts-scale b/tests/ref/fate/filter-pixfmts-scale
index f4822f5bae..e1bbe961e1 100644
--- a/tests/ref/fate/filter-pixfmts-scale
+++ b/tests/ref/fate/filter-pixfmts-scale
@@ -90,6 +90,7 @@ rgba64be            ee73e57923af984b31cc7795d13929da
 rgba64le            783d2779adfafe3548bdb671ec0de69e
 uyvy422             aeb4ba4f9f003ae21f6d18089198244f
 vuya                ffa817e283bf6a0b6fba21b07523ccaa
+vuyx                ba182200e20e0c82765eba15217848d3
 x2bgr10le           d57b9a99033cc7b65ddd111578f2d385
 x2rgb10le           d56bdb23fa6a8e12a0b4394987f89935
 xyz12be             c7ba8345998c0141ddc079cdd29b1a40
diff --git a/tests/ref/fate/filter-pixfmts-transpose b/tests/ref/fate/filter-pixfmts-transpose
index b3f2d5c5a0..0c2993d5b0 100644
--- a/tests/ref/fate/filter-pixfmts-transpose
+++ b/tests/ref/fate/filter-pixfmts-transpose
@@ -81,6 +81,7 @@ rgba                4d76a9542143752a4ac30f82f88f68f1
 rgba64be            a60041217f4c0cd796d19d3940a12a41
 rgba64le            ad47197774858858ae7b0c177dffa459
 vuya                9ece18a345beb17cd19e09e443eca4bf
+vuyx                4c2929cd1c6e5512f62e802f482f0ef2
 x2bgr10le           4aa774b6d8f6d446a64f1f288e5c97eb
 x2rgb10le           09cb1d98fe17ad8a6d9d3bec97ddc845
 xyz12be             68e5cba640f6e4ef72dff950e88b5342
diff --git a/tests/ref/fate/filter-pixfmts-vflip b/tests/ref/fate/filter-pixfmts-vflip
index 9081ce4f18..5cac61a9d2 100644
--- a/tests/ref/fate/filter-pixfmts-vflip
+++ b/tests/ref/fate/filter-pixfmts-vflip
@@ -90,6 +90,7 @@ rgba64be            17e6273323b5779b5f3f775f150c1011
 rgba64le            48f45b10503b7dd140329c3dd0d54c98
 uyvy422             3a237e8376264e0cfa78f8a3fdadec8a
 vuya                fb849f76e56181e005c31fce75d7038c
+vuyx                7a8079a97610e2c1c97aa8832b58a102
 x2bgr10le           795b66a5fc83cd2cf300aae51c230f80
 x2rgb10le           262c502230cf3724f8e2cf4737f18a42
 xyz12be             810644e008deb231850d779aaa27cc7e
-- 
2.34.1



More information about the ffmpeg-devel mailing list