diff mbox series

[FFmpeg-devel,08/21] swscale/output: add VYU444 output support

Message ID 20241008225027.12209-8-jamrial@gmail.com
State New
Headers show
Series None | expand

Commit Message

James Almer Oct. 8, 2024, 10:50 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libswscale/output.c                      | 124 +++++++++++++++++++++++
 libswscale/utils.c                       |   2 +-
 tests/ref/fate/filter-pixdesc-vyu444     |   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 +
 14 files changed, 137 insertions(+), 1 deletion(-)
 create mode 100644 tests/ref/fate/filter-pixdesc-vyu444

Comments

Michael Niedermayer Oct. 11, 2024, 10:47 p.m. UTC | #1
On Tue, Oct 08, 2024 at 07:50:13PM -0300, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libswscale/output.c                      | 124 +++++++++++++++++++++++
>  libswscale/utils.c                       |   2 +-
>  tests/ref/fate/filter-pixdesc-vyu444     |   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 +
>  14 files changed, 137 insertions(+), 1 deletion(-)
>  create mode 100644 tests/ref/fate/filter-pixdesc-vyu444

if it cannot be cleanly factored with anything then LGTM

thx

[...]
diff mbox series

Patch

diff --git a/libswscale/output.c b/libswscale/output.c
index 829180e854..f94c0bcfee 100644
--- a/libswscale/output.c
+++ b/libswscale/output.c
@@ -2882,6 +2882,125 @@  AYUV_X_WRAPPER(uyva, U, Y, V, A)
 yuv2y2xx_wrapper(10)
 yuv2y2xx_wrapper(12)
 
+static void
+yuv2vyu444_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 i;
+
+    if (uvalpha < 2048) {
+        for (i = 0; i < dstW; i++) {
+            int Y = (buf0[i] + 64) >> 7;
+            int U = (ubuf[0][i] + 64) >> 7;
+            int V = (vbuf[0][i] + 64) >> 7;
+
+            if (Y & 0x100)
+                Y = av_clip_uint8(Y);
+            if (U & 0x100)
+                U = av_clip_uint8(U);
+            if (V & 0x100)
+                V = av_clip_uint8(V);
+
+            dest[3 * i    ] = V;
+            dest[3 * i + 1] = Y;
+            dest[3 * i + 2] = U;
+        }
+    } else {
+        for (i = 0; i < dstW; i++) {
+            int Y = (buf0[i] + 64) >> 7;
+            int U = (ubuf[0][i] + ubuf[1][i] + 128) >> 8;
+            int V = (vbuf[0][i] + vbuf[1][i] + 128) >> 8;
+
+            if (Y & 0x100)
+                Y = av_clip_uint8(Y);
+            if (U & 0x100)
+                U = av_clip_uint8(U);
+            if (V & 0x100)
+                V = av_clip_uint8(V);
+
+            dest[3 * i    ] = V;
+            dest[3 * i + 1] = Y;
+            dest[3 * i + 2] = U;
+        }
+    }
+}
+
+static void
+yuv2vyu444_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)
+{
+    const int16_t *buf0  = buf[0],  *buf1  = buf[1],
+                  *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],
+                  *vbuf0 = vbuf[0], *vbuf1 = vbuf[1];
+    int yalpha1  = 4096 - yalpha;
+    int uvalpha1 = 4096 - uvalpha;
+    int i;
+
+    av_assert2(yalpha  <= 4096U);
+    av_assert2(uvalpha <= 4096U);
+
+    for (i = 0; i < dstW; i++) {
+        int Y = (buf0[i]  * yalpha1  + buf1[i]  * yalpha)  >> 19;
+        int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
+        int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;
+
+        if (Y & 0x100)
+            Y = av_clip_uint8(Y);
+        if (U & 0x100)
+            U = av_clip_uint8(U);
+        if (V & 0x100)
+            V = av_clip_uint8(V);
+
+        dest[3 * i    ] = V;
+        dest[3 * i + 1] = Y;
+        dest[3 * i + 2] = U;
+    }
+}
+
+static void
+yuv2vyu444_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 i;
+
+    for (i = 0; i < dstW; i++) {
+        int j;
+        int Y = 1 << 18, U = 1 << 18;
+        int V = 1 << 18;
+
+        for (j = 0; j < lumFilterSize; j++)
+            Y += lumSrc[j][i] * lumFilter[j];
+
+        for (j = 0; j < chrFilterSize; j++)
+            U += chrUSrc[j][i] * chrFilter[j];
+
+        for (j = 0; j < chrFilterSize; j++)
+            V += chrVSrc[j][i] * chrFilter[j];
+
+        Y >>= 19;
+        U >>= 19;
+        V >>= 19;
+
+        if (Y  & 0x100)
+            Y = av_clip_uint8(Y);
+        if (U  & 0x100)
+            U = av_clip_uint8(U);
+        if (V  & 0x100)
+            V = av_clip_uint8(V);
+
+        dest[3 * i    ] = V;
+        dest[3 * i + 1] = Y;
+        dest[3 * i + 2] = U;
+    }
+}
+
 #undef output_pixel
 
 av_cold void ff_sws_init_output_funcs(SwsContext *c,
@@ -3376,6 +3495,11 @@  av_cold void ff_sws_init_output_funcs(SwsContext *c,
         *yuv2packed2 = yuv2uyvy422_2_c;
         *yuv2packedX = yuv2uyvy422_X_c;
         break;
+    case AV_PIX_FMT_VYU444:
+        *yuv2packed1 = yuv2vyu444_1_c;
+        *yuv2packed2 = yuv2vyu444_2_c;
+        *yuv2packedX = yuv2vyu444_X_c;
+        break;
     case AV_PIX_FMT_YA8:
         *yuv2packed1 = yuv2ya8_1_c;
         *yuv2packed2 = yuv2ya8_2_c;
diff --git a/libswscale/utils.c b/libswscale/utils.c
index c80cc18eb2..719619858f 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -270,7 +270,7 @@  static const FormatEntry format_entries[] = {
     [AV_PIX_FMT_XV36LE]      = { 1, 1 },
     [AV_PIX_FMT_AYUV]        = { 1, 1 },
     [AV_PIX_FMT_UYVA]        = { 1, 1 },
-    [AV_PIX_FMT_VYU444]      = { 1, 0 },
+    [AV_PIX_FMT_VYU444]      = { 1, 1 },
     [AV_PIX_FMT_V30XLE]      = { 1, 0 },
 };
 
diff --git a/tests/ref/fate/filter-pixdesc-vyu444 b/tests/ref/fate/filter-pixdesc-vyu444
new file mode 100644
index 0000000000..7572621e76
--- /dev/null
+++ b/tests/ref/fate/filter-pixdesc-vyu444
@@ -0,0 +1 @@ 
+pixdesc-vyu444      ae888f94235dd6d122c4fa3aa40f11d0
diff --git a/tests/ref/fate/filter-pixfmts-copy b/tests/ref/fate/filter-pixfmts-copy
index de9b35e35a..e538466636 100644
--- a/tests/ref/fate/filter-pixfmts-copy
+++ b/tests/ref/fate/filter-pixfmts-copy
@@ -101,6 +101,7 @@  uyva                affad7282152bcce415bdf228df00ae4
 uyvy422             3bcf3c80047592f2211fae3260b1b65d
 vuya                3d5e934651cae1ce334001cb1829ad22
 vuyx                0af13a42f9d0932c5a9bb6a8a5d1c5ee
+vyu444              2b2e6df31f5895340f25d6f67572b113
 x2bgr10le           550c0d190cf695afa4eaacb644db6b75
 x2rgb10le           c1e3ac21be04a16bb157b22784524520
 xv30le              c14b5a953bf3be56346f66ca174a5b1b
diff --git a/tests/ref/fate/filter-pixfmts-crop b/tests/ref/fate/filter-pixfmts-crop
index 666d99f932..37b78ce5ae 100644
--- a/tests/ref/fate/filter-pixfmts-crop
+++ b/tests/ref/fate/filter-pixfmts-crop
@@ -98,6 +98,7 @@  rgba64le            fea8ebfc869b52adf353778f29eac7a7
 uyva                caa03b07812dbb6c48b5fb34edf73962
 vuya                76578a705ff3a37559653c1289bd03dd
 vuyx                615241c5406eb556fca0ad8606c23a02
+vyu444              a6067a24e63385242948dbc4c5a4ab5d
 x2bgr10le           84de725b85662c362862820dc4a309aa
 x2rgb10le           f4265aca7a67dbfa9354370098ca6f33
 xv30le              a9edb820819b900a4a897fee4562a4fb
diff --git a/tests/ref/fate/filter-pixfmts-field b/tests/ref/fate/filter-pixfmts-field
index 672ee5d2ec..0cf92f3c21 100644
--- a/tests/ref/fate/filter-pixfmts-field
+++ b/tests/ref/fate/filter-pixfmts-field
@@ -101,6 +101,7 @@  uyva                c1c2953840061e3778842051b078a41e
 uyvy422             1c49e44ab3f060e85fc4a3a9464f045e
 vuya                f72bcf29d75cd143d0c565f7cc49119a
 vuyx                3d02eeab336d0a8106f6fdd91be61073
+vyu444              09fcf24f46ed72d51983d87ad3bed864
 x2bgr10le           dbe21538d7cb1744914f6bd46ec09b55
 x2rgb10le           a18bc4ae5274e0a8cca9137ecd50c677
 xv30le              e940366c78efc9e292e9de28cf04dba9
diff --git a/tests/ref/fate/filter-pixfmts-fieldorder b/tests/ref/fate/filter-pixfmts-fieldorder
index 4b9ba2a88d..d902c9087d 100644
--- a/tests/ref/fate/filter-pixfmts-fieldorder
+++ b/tests/ref/fate/filter-pixfmts-fieldorder
@@ -90,6 +90,7 @@  uyva                fa5df2c0474b2a41dbe2210372b15fcc
 uyvy422             75de70e31c435dde878002d3f22b238a
 vuya                a3891d4168ff208948fd0b3ba0910495
 vuyx                9e4480c5fcb7c091ec3e517420764ef3
+vyu444              e2e54e73f81389559a972f4049ab8606
 x2bgr10le           86474d84f26c5c51d6f75bf7e1de8da8
 x2rgb10le           cdf6a9e8a8d081aa768c6ae2e6221676
 xv30le              25aac48128d94010a3660839500caee5
diff --git a/tests/ref/fate/filter-pixfmts-hflip b/tests/ref/fate/filter-pixfmts-hflip
index 4742e3957e..49e2b60d34 100644
--- a/tests/ref/fate/filter-pixfmts-hflip
+++ b/tests/ref/fate/filter-pixfmts-hflip
@@ -98,6 +98,7 @@  rgba64le            0c810d8b3a6bca10321788e1cb145340
 uyva                9266fd7374abf86f7035e356574586f0
 vuya                7e530261e7ac4eae4fd616fd7572d0b8
 vuyx                f1d087284fb1556d76e6def5f94bf273
+vyu444              a9377d852b8263e50987593be7b03c7a
 x2bgr10le           827cc659f29378e00c5a7d2c0ada8f9a
 x2rgb10le           d4a8189b65395a88d0a38a7053f3359f
 xv30le              072aa2b61ce1e764f9d1957e8abee9a9
diff --git a/tests/ref/fate/filter-pixfmts-il b/tests/ref/fate/filter-pixfmts-il
index f43377e3dc..852c6e126a 100644
--- a/tests/ref/fate/filter-pixfmts-il
+++ b/tests/ref/fate/filter-pixfmts-il
@@ -100,6 +100,7 @@  uyva                f16f848f8283bcd59da6a4d85bc5b0a0
 uyvy422             d6ee3ca43356d08c392382b24b22cda5
 vuya                b9deab5ba249dd608b709c09255a4932
 vuyx                4251d94ee49e6a3cc1c10c09cd331308
+vyu444              cd6598487e9f9e2c7165b656c486eade
 x2bgr10le           135acaff8318cf9861bb0f7849a9e5e9
 x2rgb10le           517fb186f523dc7cdc5c5c6967cfbe94
 xv30le              7f6414a3fc700380025c29812e8376a9
diff --git a/tests/ref/fate/filter-pixfmts-null b/tests/ref/fate/filter-pixfmts-null
index de9b35e35a..e538466636 100644
--- a/tests/ref/fate/filter-pixfmts-null
+++ b/tests/ref/fate/filter-pixfmts-null
@@ -101,6 +101,7 @@  uyva                affad7282152bcce415bdf228df00ae4
 uyvy422             3bcf3c80047592f2211fae3260b1b65d
 vuya                3d5e934651cae1ce334001cb1829ad22
 vuyx                0af13a42f9d0932c5a9bb6a8a5d1c5ee
+vyu444              2b2e6df31f5895340f25d6f67572b113
 x2bgr10le           550c0d190cf695afa4eaacb644db6b75
 x2rgb10le           c1e3ac21be04a16bb157b22784524520
 xv30le              c14b5a953bf3be56346f66ca174a5b1b
diff --git a/tests/ref/fate/filter-pixfmts-pad b/tests/ref/fate/filter-pixfmts-pad
index bab4344e01..086d89e51c 100644
--- a/tests/ref/fate/filter-pixfmts-pad
+++ b/tests/ref/fate/filter-pixfmts-pad
@@ -45,6 +45,7 @@  rgba                b157c90191463d34fb3ce77b36c96386
 uyva                be076f4efae6b51032c5fc676a31f2cc
 vuya                44368c0a758ee68e24ce976e3b1b8535
 vuyx                ff637b205b78ee581e393124d0f44f5d
+vyu444              88fde4581eb7369d7ff28bb27268b169
 ya16le              dfc900a8130a7c5e64201557cbaef50a
 ya8                 5d25e9a7975805d3f0dac516a6132b6e
 yuv410p             cb871dcc1e84a7ef1d21f9237b88cf6e
diff --git a/tests/ref/fate/filter-pixfmts-scale b/tests/ref/fate/filter-pixfmts-scale
index 66307bc1d3..67b1e4b075 100644
--- a/tests/ref/fate/filter-pixfmts-scale
+++ b/tests/ref/fate/filter-pixfmts-scale
@@ -101,6 +101,7 @@  uyva                ee83c7ba25cfc997de70a4e5b3eb398f
 uyvy422             aeb4ba4f9f003ae21f6d18089198244f
 vuya                ffa817e283bf6a0b6fba21b07523ccaa
 vuyx                a6ff68f46c6b4b7595ec91b2a497df8e
+vyu444              0e5edaa26029501f05c0693321d60ded
 x2bgr10le           d57b9a99033cc7b65ddd111578f2d385
 x2rgb10le           d56bdb23fa6a8e12a0b4394987f89935
 xv30le              afe68d8a47e8460e0164970b1da0c5be
diff --git a/tests/ref/fate/filter-pixfmts-transpose b/tests/ref/fate/filter-pixfmts-transpose
index e5e8a3b7bc..de7ef24ec8 100644
--- a/tests/ref/fate/filter-pixfmts-transpose
+++ b/tests/ref/fate/filter-pixfmts-transpose
@@ -90,6 +90,7 @@  rgba64le            ad47197774858858ae7b0c177dffa459
 uyva                1500c3f52e32b2080be180d2e8196a7b
 vuya                9ece18a345beb17cd19e09e443eca4bf
 vuyx                46b5b821d7ee6ddedb3ddafd1e5b007c
+vyu444              508978bb072eba1bc4636a4abd68dbe2
 x2bgr10le           4aa774b6d8f6d446a64f1f288e5c97eb
 x2rgb10le           09cb1d98fe17ad8a6d9d3bec97ddc845
 xv30le              b1ac5a12f46d32c70acb63f89838ab76
diff --git a/tests/ref/fate/filter-pixfmts-vflip b/tests/ref/fate/filter-pixfmts-vflip
index 53ef4732cc..b55b6a94b6 100644
--- a/tests/ref/fate/filter-pixfmts-vflip
+++ b/tests/ref/fate/filter-pixfmts-vflip
@@ -101,6 +101,7 @@  uyva                0d2d0d286d841ea5b35cc06626dcafe4
 uyvy422             3a237e8376264e0cfa78f8a3fdadec8a
 vuya                fb849f76e56181e005c31fce75d7038c
 vuyx                ed7de87da324b39090a8961dfd56ca5a
+vyu444              5a98e2118b75a3804bb80003cf6fa731
 x2bgr10le           795b66a5fc83cd2cf300aae51c230f80
 x2rgb10le           262c502230cf3724f8e2cf4737f18a42
 xv30le              7e29ee107a1fabf3c7251f337d4b9fe5