[FFmpeg-devel] [PATCH v12 9/9] swscale/input: color subsampling input support for RGBF32

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


---
 libswscale/input.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/libswscale/input.c b/libswscale/input.c
index f9d7c39..ba7e3c4 100644
--- a/libswscale/input.c
+++ b/libswscale/input.c
@@ -1447,6 +1447,30 @@ static av_always_inline void planar_rgbf32_to_y(uint8_t *_dst, const uint8_t *_s
     }
 }
 
+static av_always_inline void rgbf32_to_uv_half_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused1,
+                                                 const uint8_t *_src, const uint8_t *unused2,
+                                                 int width, int is_be, int32_t *rgb2yuv)
+{
+    int i;
+    const float *src = (const float *)_src;
+    uint16_t *dstU = (uint16_t *)_dstU;
+    uint16_t *dstV = (uint16_t *)_dstV;
+    int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
+    int32_t rv = rgb2yuv[RV_IDX], gv = rgb2yuv[GV_IDX], bv = rgb2yuv[BV_IDX];
+
+    for (i = 0; i < width; i++) {
+        int r = (lrintf(av_clipf(65535.0f * rdpx(&src[6*i]), 0.0f, 65535.0f)) +
+                 lrintf(av_clipf(65535.0f * rdpx(&src[6*i+3]), 0.0f, 65535.0f))) >> 1;
+        int g = (lrintf(av_clipf(65535.0f * rdpx(&src[6*i+1]), 0.0f, 65535.0f)) +
+                 lrintf(av_clipf(65535.0f * rdpx(&src[6*i+4]), 0.0f, 65535.0f))) >> 1;
+        int b = (lrintf(av_clipf(65535.0f * rdpx(&src[6*i+2]), 0.0f, 65535.0f)) +
+                 lrintf(av_clipf(65535.0f * rdpx(&src[6*i+5]), 0.0f, 65535.0f))) >> 1;
+
+        dstU[i] = (ru*r + gu*g + bu*b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
+        dstV[i] = (rv*r + gv*g + bv*b + (0x10001 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT;
+    }
+}
+
 static av_always_inline void rgbf32_to_uv_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused1,
                                             const uint8_t *_src, const uint8_t *unused2,
                                             int width, int is_be, int32_t *rgb2yuv)
@@ -1574,6 +1598,13 @@ static void rgbf32##endian_name##_to_uv_c(uint8_t *dstU, uint8_t *dstV,
 {                                                                                                   \
     rgbf32_to_uv_c(dstU, dstV, unused1, src, unused2, w, endian, rgb2yuv);                          \
 }                                                                                                   \
+static void rgbf32##endian_name##_to_uv_half_c(uint8_t *dstU, uint8_t *dstV,                        \
+                                               const uint8_t *unused1,                              \
+                                               const uint8_t *src, const uint8_t *unused2,          \
+                                               int w, uint32_t *rgb2yuv, void *opq)                 \
+{                                                                                                   \
+    rgbf32_to_uv_half_c(dstU, dstV, unused1, src, unused2, w, endian, rgb2yuv);                     \
+}                                                                                                   \
 static void grayf32##endian_name##ToY16_c(uint8_t *dst, const uint8_t *src,                         \
                                           const uint8_t *unused1, const uint8_t *unused2,           \
                                           int width, uint32_t *unused, void *opq)                   \
@@ -2138,6 +2169,12 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c,
         case AV_PIX_FMT_RGBF16LE:
             *chrToYV12 = rgbf16leToUV_half_c;
             break;
+        case AV_PIX_FMT_RGBF32BE:
+            *chrToYV12 = rgbf32be_to_uv_half_c;
+            break;
+        case AV_PIX_FMT_RGBF32LE:
+            *chrToYV12 = rgbf32le_to_uv_half_c;
+            break;
         }
     } else {
         switch (srcFormat) {
-- 
2.45.2



More information about the ffmpeg-devel mailing list