[FFmpeg-devel] [PATCH v12 3/9] avutil/swscale: add YUV444F16 and UYVYF16 pixel format and input support

Martin Schitter ms+git at mur.at
Mon Oct 21 22:57:16 EEST 2024


---
 libavutil/pixdesc.c              | 48 ++++++++++++++++
 libavutil/pixfmt.h               |  6 ++
 libswscale/input.c               | 99 ++++++++++++++++++++++++++++++++
 libswscale/utils.c               |  4 ++
 tests/ref/fate/imgutils          |  8 +++
 tests/ref/fate/sws-pixdesc-query | 14 +++++
 6 files changed, 179 insertions(+)

diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
index 96b9fbe..609f07a 100644
--- a/libavutil/pixdesc.c
+++ b/libavutil/pixdesc.c
@@ -515,6 +515,30 @@ static const AVPixFmtDescriptor av_pix_fmt_descriptors[AV_PIX_FMT_NB] = {
         },
         .flags = AV_PIX_FMT_FLAG_BE,
     },
+    [AV_PIX_FMT_UYVY422F16LE] = {
+        .name = "uyvy422f16le",
+        .nb_components = 3,
+        .log2_chroma_w = 1,
+        .log2_chroma_h = 0,
+        .comp = {
+            { 0, 4, 2, 0, 16 },        /* Y */
+            { 0, 8, 0, 0, 16 },        /* U */
+            { 0, 8, 4, 0, 16 },        /* V */
+        },
+        .flags = AV_PIX_FMT_FLAG_FLOAT,
+    },
+    [AV_PIX_FMT_UYVY422F16BE] = {
+        .name = "uyvy422f16be",
+        .nb_components = 3,
+        .log2_chroma_w = 1,
+        .log2_chroma_h = 0,
+        .comp = {
+            { 0, 4, 2, 0, 16 },        /* Y */
+            { 0, 8, 0, 0, 16 },        /* U */
+            { 0, 8, 4, 0, 16 },        /* V */
+        },
+        .flags = AV_PIX_FMT_FLAG_BE | AV_PIX_FMT_FLAG_FLOAT,
+    },
     [AV_PIX_FMT_UYYVYY411] = {
         .name = "uyyvyy411",
         .nb_components = 3,
@@ -1713,6 +1737,30 @@ static const AVPixFmtDescriptor av_pix_fmt_descriptors[AV_PIX_FMT_NB] = {
         },
         .flags = AV_PIX_FMT_FLAG_BE,
     },
+    [AV_PIX_FMT_YUV444F16LE] = {
+        .name = "yuv444f16le",
+        .nb_components = 3,
+        .log2_chroma_w = 0,
+        .log2_chroma_h = 0,
+        .comp = {
+            { 0, 6, 0, 0, 16 },        /* Y */
+            { 0, 6, 2, 0, 16 },        /* U */
+            { 0, 6, 4, 0, 16 },        /* V */
+        },
+        .flags = AV_PIX_FMT_FLAG_FLOAT,
+    },
+    [AV_PIX_FMT_YUV444F16BE] = {
+        .name = "yuv444f16be",
+        .nb_components = 3,
+        .log2_chroma_w = 0,
+        .log2_chroma_h = 0,
+        .comp = {
+            { 0, 6, 0, 0, 16 },        /* Y */
+            { 0, 6, 2, 0, 16 },        /* U */
+            { 0, 6, 4, 0, 16 },        /* V */
+        },
+        .flags = AV_PIX_FMT_FLAG_BE | AV_PIX_FMT_FLAG_FLOAT,
+    },
     [AV_PIX_FMT_YUV444P10LE] = {
         .name = "yuv444p10le",
         .nb_components = 3,
diff --git a/libavutil/pixfmt.h b/libavutil/pixfmt.h
index fde8dbb..67f568f 100644
--- a/libavutil/pixfmt.h
+++ b/libavutil/pixfmt.h
@@ -460,9 +460,13 @@ enum AVPixelFormat {
     AV_PIX_FMT_YUV444,      ///< packed YUV 4:4:4, 24bpp (1 Cr & Cb sample per 1x1 Y), YUVYUV...
     AV_PIX_FMT_YUV444_16BE,  ///< packed YUV 4:4:4, 48bpp (1 Cr & Cb sample per 1x1 Y), YUVYUV..., big-endian
     AV_PIX_FMT_YUV444_16LE,  ///< packed YUV 4:4:4, 48bpp (1 Cr & Cb sample per 1x1 Y), YUVYUV..., little-endian
+    AV_PIX_FMT_YUV444F16BE,  ///< IEEE-754 half precision packed YUV 4:4:4, 48bpp (1 Cr & Cb sample per 1x1 Y), YUVYUV..., big-endian
+    AV_PIX_FMT_YUV444F16LE,  ///< IEEE-754 half precision packed YUV 4:4:4, 48bpp (1 Cr & Cb sample per 1x1 Y), YUVYUV..., little-endian
 
     AV_PIX_FMT_UYVY422_16BE, ///< packed UYVU 4:2:2, 32bpp, Cb Y0 Cr Y1, big-endian
     AV_PIX_FMT_UYVY422_16LE, ///< packed UYVU 4:2:2, 32bpp, Cb Y0 Cr Y1, little-endian
+    AV_PIX_FMT_UYVY422F16BE, ///< IEEE-754 half precision packed UYVU 4:2:2, 32bpp, Cb Y0 Cr Y1, big-endian
+    AV_PIX_FMT_UYVY422F16LE, ///< IEEE-754 half precision packed UYVU 4:2:2, 32bpp, Cb Y0 Cr Y1, little-endian
 
     AV_PIX_FMT_NB         ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions
 };
@@ -515,6 +519,7 @@ enum AVPixelFormat {
 #define AV_PIX_FMT_YUV422P16 AV_PIX_FMT_NE(YUV422P16BE, YUV422P16LE)
 #define AV_PIX_FMT_YUV444P16 AV_PIX_FMT_NE(YUV444P16BE, YUV444P16LE)
 #define AV_PIX_FMT_YUV444_16 AV_PIX_FMT_NE(YUV444_16BE, YUV444_16LE)
+#define AV_PIX_FMT_YUV444F16 AV_PIX_FMT_NE(YUV444F16BE, YUV444F16LE)
 
 #define AV_PIX_FMT_GBRP9     AV_PIX_FMT_NE(GBRP9BE ,    GBRP9LE)
 #define AV_PIX_FMT_GBRP10    AV_PIX_FMT_NE(GBRP10BE,    GBRP10LE)
@@ -549,6 +554,7 @@ enum AVPixelFormat {
 #define AV_PIX_FMT_YUVA444P16 AV_PIX_FMT_NE(YUVA444P16BE, YUVA444P16LE)
 
 #define AV_PIX_FMT_UYVY422_16 AV_PIX_FMT_NE(UYVY422_16BE, UYVY422_16LE)
+#define AV_PIX_FMT_UYVY422F16 AV_PIX_FMT_NE(UYVY422F16BE, UYVY422F16LE)
 
 #define AV_PIX_FMT_XYZ12      AV_PIX_FMT_NE(XYZ12BE, XYZ12LE)
 #define AV_PIX_FMT_NV20       AV_PIX_FMT_NE(NV20BE,  NV20LE)
diff --git a/libswscale/input.c b/libswscale/input.c
index e23b59e..685b2ea 100644
--- a/libswscale/input.c
+++ b/libswscale/input.c
@@ -838,6 +838,44 @@ static void read_yuv444_16be_UV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *u
     }
 }
 
+static void read_yuv444f16le_Y_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused0,
+                                 const uint8_t *unused1, int width, uint32_t *unused2, void *h2f_tbl)
+{
+    for (int i = 0; i < width; i++)
+        AV_WN16(dst + i * 2, lrintf(av_clipf(65535.0f * av_int2float(
+            half2float(AV_RL16(src + i * 6), h2f_tbl)), 0.0f, 65535.0f)));
+}
+
+static void read_yuv444f16le_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 *h2f_tbl)
+{
+    for (int i = 0; i < width; i++) {
+        AV_WN16(dstU + i * 2, lrintf(av_clipf(65535.0f * (av_int2float(
+            half2float(AV_RL16(src + i * 6 + 2), h2f_tbl)) + 0.5f), 0.0f, 65535.0f)));
+        AV_WN16(dstV + i * 2, lrintf(av_clipf(65535.0f * (av_int2float(
+            half2float(AV_RL16(src + i * 6 + 4), h2f_tbl)) + 0.5f), 0.0f, 65535.0f)));
+    }
+}
+
+static void read_yuv444f16be_Y_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused0,
+                                 const uint8_t *unused1, int width, uint32_t *unused2, void *h2f_tbl)
+{
+    for (int i = 0; i < width; i++)
+        AV_WN16(dst + i * 2, lrintf(av_clipf(65535.0f * av_int2float(
+            half2float(AV_RB16(src + i * 6), h2f_tbl)), 0.0f, 65535.0f)));
+}
+
+static void read_yuv444f16be_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 *h2f_tbl)
+{
+    for (int i = 0; i < width; i++) {
+        AV_WN16(dstU + i * 2, lrintf(av_clipf(65535.0f * (av_int2float(
+            half2float(AV_RB16(src + i * 6 + 2), h2f_tbl)) + 0.5f), 0.0f, 65535.0f)));
+        AV_WN16(dstV + i * 2, lrintf(av_clipf(65535.0f * (av_int2float(
+            half2float(AV_RB16(src + i * 6 + 4), h2f_tbl)) + 0.5f), 0.0f, 65535.0f)));
+    }
+}
+
 static void read_v30xle_Y_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused0, const uint8_t *unused1, int width,
                                uint32_t *unused2, void *opq)
 {
@@ -968,6 +1006,43 @@ static void uyvy16be_ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0
     }
 }
 
+static void uyvyf16le_ToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2,  int width,
+                      uint32_t *unused, void *h2f_tbl)
+{
+    for (int i = 0; i < width; i++)
+        AV_WN16(dst + i * 2, lrintf(av_clipf(65535.0f * av_int2float(
+            half2float(AV_RL16(src + i * 4 + 2), h2f_tbl)), 0.0f, 65535.0f)));
+}
+
+static void uyvyf16le_ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, const uint8_t *src1,
+                       const uint8_t *src2, int width, uint32_t *unused, void *h2f_tbl)
+{
+    for (int i = 0; i < width; i++) {
+        AV_WN16(dstU + i * 2, lrintf(av_clipf(65535.0f * (av_int2float(
+            half2float(AV_RL16(src1 + i * 8), h2f_tbl)) + 0.5f), 0.0f, 65535.0f)));
+        AV_WN16(dstV + i * 2, lrintf(av_clipf(65535.0f * (av_int2float(
+            half2float(AV_RL16(src1 + i * 8 + 4), h2f_tbl)) + 0.5f), 0.0f, 65535.0f)));
+    }
+}
+
+static void uyvyf16be_ToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2,  int width,
+                      uint32_t *unused, void *h2f_tbl)
+{
+    for (int i = 0; i < width; i++)
+        AV_WN16(dst + i * 2, lrintf(av_clipf(65535.0f * av_int2float(
+            half2float(AV_RB16(src + i * 4 + 2), h2f_tbl)), 0.0f, 65535.0f)));
+}
+
+static void uyvyf16be_ToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, const uint8_t *src1,
+                       const uint8_t *src2, int width, uint32_t *unused, void *h2f_tbl)
+{
+    for (int i = 0; i < width; i++) {
+        AV_WN16(dstU + i * 2, lrintf(av_clipf(65535.0f * (av_int2float(
+            half2float(AV_RB16(src1 + i * 8), h2f_tbl)) + 0.5f), 0.0f, 65535.0f)));
+        AV_WN16(dstV + i * 2, lrintf(av_clipf(65535.0f * (av_int2float(
+            half2float(AV_RB16(src1 + i * 8 + 4), h2f_tbl)) + 0.5f), 0.0f, 65535.0f)));
+    }
+}
 
 static av_always_inline void nvXXtoUV_c(uint8_t *dst1, uint8_t *dst2,
                                         const uint8_t *src, int width)
@@ -1647,6 +1722,12 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c,
     case AV_PIX_FMT_UYVY422_16BE:
         *chrToYV12 = uyvy16be_ToUV_c;
         break;
+    case AV_PIX_FMT_UYVY422F16LE:
+        *chrToYV12 = uyvyf16le_ToUV_c;
+        break;
+    case AV_PIX_FMT_UYVY422F16BE:
+        *chrToYV12 = uyvyf16be_ToUV_c;
+        break;
     case AV_PIX_FMT_VYU444:
         *chrToYV12 = vyuToUV_c;
         break;
@@ -1659,6 +1740,12 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c,
     case AV_PIX_FMT_YUV444_16BE:
         *chrToYV12 = read_yuv444_16be_UV_c;
         break;
+    case AV_PIX_FMT_YUV444F16LE:
+        *chrToYV12 = read_yuv444f16le_UV_c;
+        break;
+    case AV_PIX_FMT_YUV444F16BE:
+        *chrToYV12 = read_yuv444f16be_UV_c;
+        break;
     case AV_PIX_FMT_NV12:
     case AV_PIX_FMT_NV16:
     case AV_PIX_FMT_NV24:
@@ -2264,6 +2351,12 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c,
     case AV_PIX_FMT_UYVY422_16BE:
         *lumToYV12 = uyvy16be_ToY_c;
         break;
+    case AV_PIX_FMT_UYVY422F16LE:
+        *lumToYV12 = uyvyf16le_ToY_c;
+        break;
+    case AV_PIX_FMT_UYVY422F16BE:
+        *lumToYV12 = uyvyf16be_ToY_c;
+        break;
     case AV_PIX_FMT_VYU444:
         *lumToYV12 = vyuToY_c;
         break;
@@ -2276,6 +2369,12 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c,
     case AV_PIX_FMT_YUV444_16BE:
         *lumToYV12 = read_yuv444_16be_Y_c;
         break;
+    case AV_PIX_FMT_YUV444F16LE:
+        *lumToYV12 = read_yuv444f16le_Y_c;
+        break;
+    case AV_PIX_FMT_YUV444F16BE:
+        *lumToYV12 = read_yuv444f16be_Y_c;
+        break;
     case AV_PIX_FMT_BGR24:
         *lumToYV12 = bgr24ToY_c;
         break;
diff --git a/libswscale/utils.c b/libswscale/utils.c
index 623e826..4573355 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -76,6 +76,8 @@ static const FormatEntry format_entries[] = {
     [AV_PIX_FMT_YUV444]      = { 1, 0 },
     [AV_PIX_FMT_YUV444_16BE] = { 1, 0 },
     [AV_PIX_FMT_YUV444_16LE] = { 1, 0 },
+    [AV_PIX_FMT_YUV444F16BE] = { 1, 0 },
+    [AV_PIX_FMT_YUV444F16LE] = { 1, 0 },
     [AV_PIX_FMT_YUV410P]     = { 1, 1 },
     [AV_PIX_FMT_YUV411P]     = { 1, 1 },
     [AV_PIX_FMT_GRAY8]       = { 1, 1 },
@@ -90,6 +92,8 @@ static const FormatEntry format_entries[] = {
     [AV_PIX_FMT_UYVY422]     = { 1, 1 },
     [AV_PIX_FMT_UYVY422_16BE]= { 1, 0 },
     [AV_PIX_FMT_UYVY422_16LE]= { 1, 0 },
+    [AV_PIX_FMT_UYVY422F16BE]= { 1, 0 },
+    [AV_PIX_FMT_UYVY422F16LE]= { 1, 0 },
     [AV_PIX_FMT_UYYVYY411]   = { 0, 0 },
     [AV_PIX_FMT_BGR8]        = { 1, 1 },
     [AV_PIX_FMT_BGR4]        = { 0, 1 },
diff --git a/tests/ref/fate/imgutils b/tests/ref/fate/imgutils
index b4d98f4..bebd540 100644
--- a/tests/ref/fate/imgutils
+++ b/tests/ref/fate/imgutils
@@ -283,8 +283,12 @@ rgb96le         planes: 1, linesizes: 768   0   0   0, plane_sizes: 36864     0
 yuv444          planes: 1, linesizes: 192   0   0   0, plane_sizes:  9216     0     0     0, plane_offsets:     0     0     0, total_size: 9216
 yuv444_16be     planes: 1, linesizes: 384   0   0   0, plane_sizes: 18432     0     0     0, plane_offsets:     0     0     0, total_size: 18432
 yuv444_16le     planes: 1, linesizes: 384   0   0   0, plane_sizes: 18432     0     0     0, plane_offsets:     0     0     0, total_size: 18432
+yuv444f16be     planes: 1, linesizes: 384   0   0   0, plane_sizes: 18432     0     0     0, plane_offsets:     0     0     0, total_size: 18432
+yuv444f16le     planes: 1, linesizes: 384   0   0   0, plane_sizes: 18432     0     0     0, plane_offsets:     0     0     0, total_size: 18432
 uyvy422_16be    planes: 1, linesizes: 256   0   0   0, plane_sizes: 12288     0     0     0, plane_offsets:     0     0     0, total_size: 12288
 uyvy422_16le    planes: 1, linesizes: 256   0   0   0, plane_sizes: 12288     0     0     0, plane_offsets:     0     0     0, total_size: 12288
+uyvy422f16be    planes: 1, linesizes: 256   0   0   0, plane_sizes: 12288     0     0     0, plane_offsets:     0     0     0, total_size: 12288
+uyvy422f16le    planes: 1, linesizes: 256   0   0   0, plane_sizes: 12288     0     0     0, plane_offsets:     0     0     0, total_size: 12288
 
 image_fill_black tests
 yuv420p         total_size:   4608,  black_unknown_crc: 0xd00f6cc6,  black_tv_crc: 0xd00f6cc6,  black_pc_crc: 0x234969af
@@ -515,5 +519,9 @@ rgb96le         total_size:  36864,  black_unknown_crc: 0x00000000,  black_tv_cr
 yuv444          total_size:   9216,  black_unknown_crc: 0x32a4be0b,  black_tv_crc: 0x32a4be0b,  black_pc_crc: 0x07501edb
 yuv444_16be     total_size:  18432,  black_unknown_crc: 0xac983d03,  black_tv_crc: 0xac983d03,  black_pc_crc: 0x949a61fc
 yuv444_16le     total_size:  18432,  black_unknown_crc: 0x24c4432b,  black_tv_crc: 0x24c4432b,  black_pc_crc: 0xfe5a7889
+yuv444f16be     total_size:  18432,  black_unknown_crc: 0x5cf972e1,  black_tv_crc: 0x5cf972e1,  black_pc_crc: 0x482033cf
+yuv444f16le     total_size:  18432,  black_unknown_crc: 0x4a18e5bb,  black_tv_crc: 0x4a18e5bb,  black_pc_crc: 0x920584a7
 uyvy422_16be    total_size:  12288,  black_unknown_crc: 0xb53352d5,  black_tv_crc: 0xb53352d5,  black_pc_crc: 0xf8461cf3
 uyvy422_16le    total_size:  12288,  black_unknown_crc: 0xe39de4bd,  black_tv_crc: 0xe39de4bd,  black_pc_crc: 0x24b29add
+uyvy422f16be    total_size:  12288,  black_unknown_crc: 0x9c275ddf,  black_tv_crc: 0x9c275ddf,  black_pc_crc: 0xde92b629
+uyvy422f16le    total_size:  12288,  black_unknown_crc: 0x2e5b76c4,  black_tv_crc: 0x2e5b76c4,  black_pc_crc: 0x2928eced
diff --git a/tests/ref/fate/sws-pixdesc-query b/tests/ref/fate/sws-pixdesc-query
index 5c2a4bd..0d564c8 100644
--- a/tests/ref/fate/sws-pixdesc-query
+++ b/tests/ref/fate/sws-pixdesc-query
@@ -27,6 +27,8 @@ is16BPS:
   rgbf16le
   uyvy422_16be
   uyvy422_16le
+  uyvy422f16be
+  uyvy422f16le
   ya16be
   ya16le
   yuv420p16be
@@ -35,6 +37,8 @@ is16BPS:
   yuv422p16le
   yuv444_16be
   yuv444_16le
+  yuv444f16be
+  yuv444f16le
   yuv444p16be
   yuv444p16le
   yuva420p16be
@@ -192,6 +196,7 @@ isBE:
   rgbf16be
   rgbf32be
   uyvy422_16be
+  uyvy422f16be
   v30xbe
   x2bgr10be
   x2rgb10be
@@ -214,6 +219,7 @@ isBE:
   yuv440p10be
   yuv440p12be
   yuv444_16be
+  yuv444f16be
   yuv444p10be
   yuv444p12be
   yuv444p14be
@@ -264,6 +270,8 @@ isYUV:
   uyvy422
   uyvy422_16be
   uyvy422_16le
+  uyvy422f16be
+  uyvy422f16le
   uyyvyy411
   v30xbe
   v30xle
@@ -315,6 +323,8 @@ isYUV:
   yuv444
   yuv444_16be
   yuv444_16le
+  yuv444f16be
+  yuv444f16le
   yuv444p
   yuv444p10be
   yuv444p10le
@@ -869,6 +879,8 @@ Packed:
   uyvy422
   uyvy422_16be
   uyvy422_16le
+  uyvy422f16be
+  uyvy422f16le
   uyyvyy411
   v30xbe
   v30xle
@@ -895,6 +907,8 @@ Packed:
   yuv444
   yuv444_16be
   yuv444_16le
+  yuv444f16be
+  yuv444f16le
   yuyv422
   yvyu422
 
-- 
2.45.2



More information about the ffmpeg-devel mailing list