diff mbox series

[FFmpeg-devel,v12,2/9] avutil/swscale: add YUV444_16 and UYVY_16 pixel format and input support

Message ID 20241021195721.892544-4-ms+git@mur.at
State New
Headers show
Series DNxUncompressed decoder | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished

Commit Message

martin schitter Oct. 21, 2024, 7:57 p.m. UTC
---
 libavutil/pixdesc.c              | 46 ++++++++++++++++
 libavutil/pixfmt.h               |  8 +++
 libswscale/input.c               | 90 ++++++++++++++++++++++++++++++++
 libswscale/utils.c               |  4 ++
 tests/ref/fate/imgutils          |  8 +++
 tests/ref/fate/sws-pixdesc-query | 14 +++++
 6 files changed, 170 insertions(+)
diff mbox series

Patch

diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
index c6a9b85..96b9fbe 100644
--- a/libavutil/pixdesc.c
+++ b/libavutil/pixdesc.c
@@ -492,6 +492,29 @@  static const AVPixFmtDescriptor av_pix_fmt_descriptors[AV_PIX_FMT_NB] = {
             { 0, 4, 2, 0, 8 },        /* V */
         },
     },
+    [AV_PIX_FMT_UYVY422_16LE] = {
+        .name = "uyvy422_16le",
+        .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 */
+        },
+    },
+    [AV_PIX_FMT_UYVY422_16BE] = {
+        .name = "uyvy422_16be",
+        .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_UYYVYY411] = {
         .name = "uyyvyy411",
         .nb_components = 3,
@@ -1667,6 +1690,29 @@  static const AVPixFmtDescriptor av_pix_fmt_descriptors[AV_PIX_FMT_NB] = {
         },
         .flags = AV_PIX_FMT_FLAG_BE | AV_PIX_FMT_FLAG_PLANAR,
     },
+    [AV_PIX_FMT_YUV444_16LE] = {
+        .name = "yuv444_16le",
+        .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 */
+        },
+    },
+    [AV_PIX_FMT_YUV444_16BE] = {
+        .name = "yuv444_16be",
+        .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_YUV444P10LE] = {
         .name = "yuv444p10le",
         .nb_components = 3,
diff --git a/libavutil/pixfmt.h b/libavutil/pixfmt.h
index 0c7f909..fde8dbb 100644
--- a/libavutil/pixfmt.h
+++ b/libavutil/pixfmt.h
@@ -458,6 +458,11 @@  enum AVPixelFormat {
     AV_PIX_FMT_RGB96LE,     ///< packed RGBA 32:32:32, 96bpp, RGBRGB..., little-endian
 
     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_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_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
 };
@@ -509,6 +514,7 @@  enum AVPixelFormat {
 #define AV_PIX_FMT_YUV420P16 AV_PIX_FMT_NE(YUV420P16BE, YUV420P16LE)
 #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_GBRP9     AV_PIX_FMT_NE(GBRP9BE ,    GBRP9LE)
 #define AV_PIX_FMT_GBRP10    AV_PIX_FMT_NE(GBRP10BE,    GBRP10LE)
@@ -542,6 +548,8 @@  enum AVPixelFormat {
 #define AV_PIX_FMT_YUVA422P16 AV_PIX_FMT_NE(YUVA422P16BE, YUVA422P16LE)
 #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_XYZ12      AV_PIX_FMT_NE(XYZ12BE, XYZ12LE)
 #define AV_PIX_FMT_NV20       AV_PIX_FMT_NE(NV20BE,  NV20LE)
 #define AV_PIX_FMT_AYUV64     AV_PIX_FMT_NE(AYUV64BE, AYUV64LE)
diff --git a/libswscale/input.c b/libswscale/input.c
index 79376b9..e23b59e 100644
--- a/libswscale/input.c
+++ b/libswscale/input.c
@@ -805,6 +805,39 @@  static void vyuToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, cons
     }
 }
 
+static void read_yuv444_16le_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;
+    for (i = 0; i < width; i++)
+        AV_WN16(dst + i * 2, AV_RL16(src + i * 6));
+}
+
+static void read_yuv444_16le_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)
+{
+    for (int i = 0; i < width; i++) {
+        AV_WN16(dstU + i * 2, AV_RL16(src + i * 6 + 2));
+        AV_WN16(dstV + i * 2, AV_RL16(src + i * 6 + 4));
+    }
+}
+
+static void read_yuv444_16be_Y_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused0,
+                                 const uint8_t *unused1, int width, uint32_t *unused2, void *opq)
+{
+    for (int i = 0; i < width; i++)
+        AV_WN16(dst + i * 2, AV_RB16(src + i * 6));
+}
+
+static void read_yuv444_16be_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)
+{
+    for (int i = 0; i < width; i++) {
+        AV_WN16(dstU + i * 2, AV_RB16(src + i * 6 + 2));
+        AV_WN16(dstV + i * 2, AV_RB16(src + i * 6 + 4));
+    }
+}
+
 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)
 {
@@ -903,6 +936,39 @@  static void uyvyToUV_c(uint8_t *dstU, uint8_t *dstV, const uint8_t *unused0, con
     av_assert1(src1 == src2);
 }
 
+static void uyvy16le_ToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1,
+                           const uint8_t *unused2,  int width, uint32_t *unused, void *opq)
+{
+    for (int i = 0; i < width; i++)
+        AV_WN16(dst + i * 2, AV_RL16(src + 4 * i + 2));
+}
+
+static void uyvy16le_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 *opq)
+{
+    for (int i = 0; i < width; i++) {
+        AV_WN16(dstU + i * 2, AV_RL16(src1 + 8 * i));
+        AV_WN16(dstV + i * 2, AV_RL16(src1 + 8 * i + 4));
+    }
+}
+
+static void uyvy16be_ToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1,
+                           const uint8_t *unused2,  int width, uint32_t *unused, void *opq)
+{
+    for (int i = 0; i < width; i++)
+        AV_WN16(dst + i * 2, AV_RB16(src + 4 * i + 2));
+}
+
+static void uyvy16be_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 *opq)
+{
+    for (int i = 0; i < width; i++) {
+        AV_WN16(dstU + i * 2, AV_RB16(src1 + 8 * i));
+        AV_WN16(dstV + i * 2, AV_RB16(src1 + 8 * i + 4));
+    }
+}
+
+
 static av_always_inline void nvXXtoUV_c(uint8_t *dst1, uint8_t *dst2,
                                         const uint8_t *src, int width)
 {
@@ -1575,12 +1641,24 @@  av_cold void ff_sws_init_input_funcs(SwsContext *c,
     case AV_PIX_FMT_UYVY422:
         *chrToYV12 = uyvyToUV_c;
         break;
+    case AV_PIX_FMT_UYVY422_16LE:
+        *chrToYV12 = uyvy16le_ToUV_c;
+        break;
+    case AV_PIX_FMT_UYVY422_16BE:
+        *chrToYV12 = uyvy16be_ToUV_c;
+        break;
     case AV_PIX_FMT_VYU444:
         *chrToYV12 = vyuToUV_c;
         break;
     case AV_PIX_FMT_YUV444:
         *chrToYV12 = yuv444ToUV_c;
         break;
+    case AV_PIX_FMT_YUV444_16LE:
+        *chrToYV12 = read_yuv444_16le_UV_c;
+        break;
+    case AV_PIX_FMT_YUV444_16BE:
+        *chrToYV12 = read_yuv444_16be_UV_c;
+        break;
     case AV_PIX_FMT_NV12:
     case AV_PIX_FMT_NV16:
     case AV_PIX_FMT_NV24:
@@ -2180,12 +2258,24 @@  av_cold void ff_sws_init_input_funcs(SwsContext *c,
     case AV_PIX_FMT_UYVY422:
         *lumToYV12 = uyvyToY_c;
         break;
+    case AV_PIX_FMT_UYVY422_16LE:
+        *lumToYV12 = uyvy16le_ToY_c;
+        break;
+    case AV_PIX_FMT_UYVY422_16BE:
+        *lumToYV12 = uyvy16be_ToY_c;
+        break;
     case AV_PIX_FMT_VYU444:
         *lumToYV12 = vyuToY_c;
         break;
     case AV_PIX_FMT_YUV444:
         *lumToYV12 = yuv444ToY_c;
         break;
+    case AV_PIX_FMT_YUV444_16LE:
+        *lumToYV12 = read_yuv444_16le_Y_c;
+        break;
+    case AV_PIX_FMT_YUV444_16BE:
+        *lumToYV12 = read_yuv444_16be_Y_c;
+        break;
     case AV_PIX_FMT_BGR24:
         *lumToYV12 = bgr24ToY_c;
         break;
diff --git a/libswscale/utils.c b/libswscale/utils.c
index 36d9738..623e826 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -74,6 +74,8 @@  static const FormatEntry format_entries[] = {
     [AV_PIX_FMT_YUV422P]     = { 1, 1 },
     [AV_PIX_FMT_YUV444P]     = { 1, 1 },
     [AV_PIX_FMT_YUV444]      = { 1, 0 },
+    [AV_PIX_FMT_YUV444_16BE] = { 1, 0 },
+    [AV_PIX_FMT_YUV444_16LE] = { 1, 0 },
     [AV_PIX_FMT_YUV410P]     = { 1, 1 },
     [AV_PIX_FMT_YUV411P]     = { 1, 1 },
     [AV_PIX_FMT_GRAY8]       = { 1, 1 },
@@ -86,6 +88,8 @@  static const FormatEntry format_entries[] = {
     [AV_PIX_FMT_YUVJ444P]    = { 1, 1 },
     [AV_PIX_FMT_YVYU422]     = { 1, 1 },
     [AV_PIX_FMT_UYVY422]     = { 1, 1 },
+    [AV_PIX_FMT_UYVY422_16BE]= { 1, 0 },
+    [AV_PIX_FMT_UYVY422_16LE]= { 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 62a52be..b4d98f4 100644
--- a/tests/ref/fate/imgutils
+++ b/tests/ref/fate/imgutils
@@ -281,6 +281,10 @@  rgba128le       planes: 1, linesizes: 1024   0   0   0, plane_sizes: 49152     0
 rgb96be         planes: 1, linesizes: 768   0   0   0, plane_sizes: 36864     0     0     0, plane_offsets:     0     0     0, total_size: 36864
 rgb96le         planes: 1, linesizes: 768   0   0   0, plane_sizes: 36864     0     0     0, plane_offsets:     0     0     0, total_size: 36864
 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
+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
 
 image_fill_black tests
 yuv420p         total_size:   4608,  black_unknown_crc: 0xd00f6cc6,  black_tv_crc: 0xd00f6cc6,  black_pc_crc: 0x234969af
@@ -509,3 +513,7 @@  rgba128le       total_size:  49152,  black_unknown_crc: 0x59ef499b,  black_tv_cr
 rgb96be         total_size:  36864,  black_unknown_crc: 0x00000000,  black_tv_crc: 0x00000000,  black_pc_crc: 0x00000000
 rgb96le         total_size:  36864,  black_unknown_crc: 0x00000000,  black_tv_crc: 0x00000000,  black_pc_crc: 0x00000000
 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
+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
diff --git a/tests/ref/fate/sws-pixdesc-query b/tests/ref/fate/sws-pixdesc-query
index 6e80565..5c2a4bd 100644
--- a/tests/ref/fate/sws-pixdesc-query
+++ b/tests/ref/fate/sws-pixdesc-query
@@ -25,12 +25,16 @@  is16BPS:
   rgbaf16le
   rgbf16be
   rgbf16le
+  uyvy422_16be
+  uyvy422_16le
   ya16be
   ya16le
   yuv420p16be
   yuv420p16le
   yuv422p16be
   yuv422p16le
+  yuv444_16be
+  yuv444_16le
   yuv444p16be
   yuv444p16le
   yuva420p16be
@@ -187,6 +191,7 @@  isBE:
   rgbaf32be
   rgbf16be
   rgbf32be
+  uyvy422_16be
   v30xbe
   x2bgr10be
   x2rgb10be
@@ -208,6 +213,7 @@  isBE:
   yuv422p9be
   yuv440p10be
   yuv440p12be
+  yuv444_16be
   yuv444p10be
   yuv444p12be
   yuv444p14be
@@ -256,6 +262,8 @@  isYUV:
   p416le
   uyva
   uyvy422
+  uyvy422_16be
+  uyvy422_16le
   uyyvyy411
   v30xbe
   v30xle
@@ -305,6 +313,8 @@  isYUV:
   yuv440p12be
   yuv440p12le
   yuv444
+  yuv444_16be
+  yuv444_16le
   yuv444p
   yuv444p10be
   yuv444p10le
@@ -857,6 +867,8 @@  Packed:
   rgbf32le
   uyva
   uyvy422
+  uyvy422_16be
+  uyvy422_16le
   uyyvyy411
   v30xbe
   v30xle
@@ -881,6 +893,8 @@  Packed:
   ya16le
   ya8
   yuv444
+  yuv444_16be
+  yuv444_16le
   yuyv422
   yvyu422