[FFmpeg-devel] [PATCH v2 2/5] swscale/yuv2rgb: prepare YUV2RGBFUNC macro for multi-planar rgb

Ramiro Polla ramiro.polla at gmail.com
Tue Aug 6 13:51:03 EEST 2024


This will be used in the upcoming yuv42{0,2}p -> gbrp unscaled
colorspace converters.

There is no difference in performance.
---
 libswscale/yuv2rgb.c | 83 +++++++++++++++++++++++++-------------------
 1 file changed, 48 insertions(+), 35 deletions(-)

diff --git a/libswscale/yuv2rgb.c b/libswscale/yuv2rgb.c
index d77660b3a3..31d10235ef 100644
--- a/libswscale/yuv2rgb.c
+++ b/libswscale/yuv2rgb.c
@@ -124,7 +124,7 @@ const int *sws_getCoefficients(int colorspace)
     dst_##l[12 * i +  8] = dst_##l[12 * i +  9] = g[Y]; \
     dst_##l[12 * i + 10] = dst_##l[12 * i + 11] = r[Y];
 
-#define YUV2RGBFUNC(func_name, dst_type, alpha, yuv422)                     \
+#define YUV2RGBFUNC(func_name, dst_type, alpha, yuv422, nb_dst_planes)      \
     static int func_name(SwsContext *c, const uint8_t *src[],               \
                          int srcStride[], int srcSliceY, int srcSliceH,     \
                          uint8_t *dst[], int dstStride[])                   \
@@ -137,6 +137,7 @@ const int *sws_getCoefficients(int colorspace)
                 (dst_type *)(dst[0] + (yd)     * dstStride[0]);             \
             dst_type *dst_2 =                                               \
                 (dst_type *)(dst[0] + (yd + 1) * dstStride[0]);             \
+            dst_type av_unused *dst1_1, *dst1_2, *dst2_1, *dst2_2;          \
             dst_type av_unused *r, *g, *b;                                  \
             const uint8_t *py_1 = src[0] +  y       * srcStride[0];         \
             const uint8_t *py_2 = py_1   +            srcStride[0];         \
@@ -145,6 +146,12 @@ const int *sws_getCoefficients(int colorspace)
             const uint8_t av_unused *pu_2, *pv_2;                           \
             const uint8_t av_unused *pa_1, *pa_2;                           \
             unsigned int h_size = c->dstW >> 3;                             \
+            if (nb_dst_planes > 1) {                                        \
+                dst1_1 = (dst_type *)(dst[1] + (yd)     * dstStride[1]);    \
+                dst1_2 = (dst_type *)(dst[1] + (yd + 1) * dstStride[1]);    \
+                dst2_1 = (dst_type *)(dst[2] + (yd)     * dstStride[2]);    \
+                dst2_2 = (dst_type *)(dst[2] + (yd + 1) * dstStride[2]);    \
+            }                                                               \
             if (yuv422) {                                                   \
                 pu_2 = pu_1 + srcStride[1];                                 \
                 pv_2 = pv_1 + srcStride[2];                                 \
@@ -156,7 +163,7 @@ const int *sws_getCoefficients(int colorspace)
             while (h_size--) {                                              \
                 int av_unused U, V, Y;                                      \
 
-#define ENDYUV2RGBLINE(dst_delta, ss, alpha, yuv422) \
+#define ENDYUV2RGBLINE(dst_delta, ss, alpha, yuv422, nb_dst_planes) \
     pu_1  += 4 >> ss;                               \
     pv_1  += 4 >> ss;                               \
     if (yuv422) {                                   \
@@ -171,6 +178,12 @@ const int *sws_getCoefficients(int colorspace)
     }                                               \
     dst_1 += dst_delta >> ss;                       \
     dst_2 += dst_delta >> ss;                       \
+    if (nb_dst_planes > 1) {                        \
+        dst1_1 += dst_delta >> ss;                  \
+        dst1_2 += dst_delta >> ss;                  \
+        dst2_1 += dst_delta >> ss;                  \
+        dst2_2 += dst_delta >> ss;                  \
+    }                                               \
     }                                               \
     if (c->dstW & (4 >> ss)) {                      \
         int av_unused Y, U, V;                      \
@@ -181,8 +194,8 @@ const int *sws_getCoefficients(int colorspace)
         return srcSliceH;                           \
     }
 
-#define YUV420FUNC(func_name, dst_type, alpha, abase, PUTFUNC, dst_delta) \
-    YUV2RGBFUNC(func_name, dst_type, alpha, 0)                          \
+#define YUV420FUNC(func_name, dst_type, alpha, abase, PUTFUNC, dst_delta, nb_dst_planes) \
+    YUV2RGBFUNC(func_name, dst_type, alpha, 0, nb_dst_planes)           \
         LOADCHROMA(1, 0);                                               \
         PUTFUNC(1, 0, abase);                                           \
         PUTFUNC(2, 0, abase);                                           \
@@ -198,7 +211,7 @@ const int *sws_getCoefficients(int colorspace)
         LOADCHROMA(1, 3);                                               \
         PUTFUNC(2, 3, abase);                                           \
         PUTFUNC(1, 3, abase);                                           \
-    ENDYUV2RGBLINE(dst_delta, 0, alpha, 0)                              \
+    ENDYUV2RGBLINE(dst_delta, 0, alpha, 0, nb_dst_planes)               \
         LOADCHROMA(1, 0);                                               \
         PUTFUNC(1, 0, abase);                                           \
         PUTFUNC(2, 0, abase);                                           \
@@ -206,14 +219,14 @@ const int *sws_getCoefficients(int colorspace)
         LOADCHROMA(1, 1);                                               \
         PUTFUNC(2, 1, abase);                                           \
         PUTFUNC(1, 1, abase);                                           \
-    ENDYUV2RGBLINE(dst_delta, 1, alpha, 0)                              \
+    ENDYUV2RGBLINE(dst_delta, 1, alpha, 0, nb_dst_planes)               \
         LOADCHROMA(1, 0);                                               \
         PUTFUNC(1, 0, abase);                                           \
         PUTFUNC(2, 0, abase);                                           \
     ENDYUV2RGBFUNC()
 
-#define YUV422FUNC(func_name, dst_type, alpha, abase, PUTFUNC, dst_delta) \
-    YUV2RGBFUNC(func_name, dst_type, alpha, 1)                          \
+#define YUV422FUNC(func_name, dst_type, alpha, abase, PUTFUNC, dst_delta, nb_dst_planes) \
+    YUV2RGBFUNC(func_name, dst_type, alpha, 1, nb_dst_planes)           \
         LOADCHROMA(1, 0);                                               \
         PUTFUNC(1, 0, abase);                                           \
                                                                         \
@@ -237,7 +250,7 @@ const int *sws_getCoefficients(int colorspace)
                                                                         \
         LOADCHROMA(1, 3);                                               \
         PUTFUNC(1, 3, abase);                                           \
-    ENDYUV2RGBLINE(dst_delta, 0, alpha, 1)                              \
+    ENDYUV2RGBLINE(dst_delta, 0, alpha, 1, nb_dst_planes)               \
         LOADCHROMA(1, 0);                                               \
         PUTFUNC(1, 0, abase);                                           \
                                                                         \
@@ -249,7 +262,7 @@ const int *sws_getCoefficients(int colorspace)
                                                                         \
         LOADCHROMA(1, 1);                                               \
         PUTFUNC(1, 1, abase);                                           \
-    ENDYUV2RGBLINE(dst_delta, 1, alpha, 1)                              \
+    ENDYUV2RGBLINE(dst_delta, 1, alpha, 1, nb_dst_planes)               \
         LOADCHROMA(1, 0);                                               \
         PUTFUNC(1, 0, abase);                                           \
                                                                         \
@@ -258,7 +271,7 @@ const int *sws_getCoefficients(int colorspace)
     ENDYUV2RGBFUNC()
 
 #define YUV420FUNC_DITHER(func_name, dst_type, LOADDITHER, PUTFUNC, dst_delta) \
-    YUV2RGBFUNC(func_name, dst_type, 0, 0)                              \
+    YUV2RGBFUNC(func_name, dst_type, 0, 0, 1)                           \
         LOADDITHER                                                      \
                                                                         \
         LOADCHROMA(1, 0);                                               \
@@ -276,7 +289,7 @@ const int *sws_getCoefficients(int colorspace)
         LOADCHROMA(1, 3);                                               \
         PUTFUNC(2, 3, 6 + 8);                                           \
         PUTFUNC(1, 3, 6);                                               \
-    ENDYUV2RGBLINE(dst_delta, 0, 0, 0)                                  \
+    ENDYUV2RGBLINE(dst_delta, 0, 0, 0, 1)                               \
         LOADDITHER                                                      \
                                                                         \
         LOADCHROMA(1, 0);                                               \
@@ -286,7 +299,7 @@ const int *sws_getCoefficients(int colorspace)
         LOADCHROMA(1, 1);                                               \
         PUTFUNC(2, 1, 2 + 8);                                           \
         PUTFUNC(1, 1, 2);                                               \
-    ENDYUV2RGBLINE(dst_delta, 1, 0, 0)                                  \
+    ENDYUV2RGBLINE(dst_delta, 1, 0, 0, 1)                               \
         LOADDITHER                                                      \
                                                                         \
         LOADCHROMA(1, 0);                                               \
@@ -295,7 +308,7 @@ const int *sws_getCoefficients(int colorspace)
     ENDYUV2RGBFUNC()
 
 #define YUV422FUNC_DITHER(func_name, dst_type, LOADDITHER, PUTFUNC, dst_delta) \
-    YUV2RGBFUNC(func_name, dst_type, 0, 1)                              \
+    YUV2RGBFUNC(func_name, dst_type, 0, 1, 1)                           \
         LOADDITHER                                                      \
                                                                         \
         LOADCHROMA(1, 0);                                               \
@@ -321,7 +334,7 @@ const int *sws_getCoefficients(int colorspace)
                                                                         \
         LOADCHROMA(1, 3);                                               \
         PUTFUNC(1, 3, 6);                                               \
-    ENDYUV2RGBLINE(dst_delta, 0, 0, 1)                                  \
+    ENDYUV2RGBLINE(dst_delta, 0, 0, 1, 1)                               \
         LOADDITHER                                                      \
                                                                         \
         LOADCHROMA(1, 0);                                               \
@@ -335,7 +348,7 @@ const int *sws_getCoefficients(int colorspace)
                                                                         \
         LOADCHROMA(1, 1);                                               \
         PUTFUNC(1, 1, 2);                                               \
-    ENDYUV2RGBLINE(dst_delta, 1, 0, 1)                                  \
+    ENDYUV2RGBLINE(dst_delta, 1, 0, 1, 1)                               \
         LOADDITHER                                                      \
                                                                         \
         LOADCHROMA(1, 0);                                               \
@@ -431,7 +444,7 @@ const int *sws_getCoefficients(int colorspace)
                          g[Y +  d64[1 + o]] +       \
                          b[Y + d128[1 + o]];
 
-YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0, 0)
+YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0, 0, 1)
     const uint8_t *d128 = ff_dither_8x8_220[yd & 7];
     char out_1 = 0, out_2 = 0;
     g = c->table_gU[128 + YUVRGB_TABLE_HEADROOM] + c->table_gV[128 + YUVRGB_TABLE_HEADROOM];
@@ -494,18 +507,18 @@ YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0, 0)
 ENDYUV2RGBFUNC()
 
 // YUV420
-YUV420FUNC(yuv2rgb_c_48,     uint8_t,  0,  0, PUTRGB48, 48)
-YUV420FUNC(yuv2rgb_c_bgr48,  uint8_t,  0,  0, PUTBGR48, 48)
-YUV420FUNC(yuv2rgb_c_32,     uint32_t, 0,  0, PUTRGB,    8)
+YUV420FUNC(yuv2rgb_c_48,     uint8_t,  0,  0, PUTRGB48, 48, 1)
+YUV420FUNC(yuv2rgb_c_bgr48,  uint8_t,  0,  0, PUTBGR48, 48, 1)
+YUV420FUNC(yuv2rgb_c_32,     uint32_t, 0,  0, PUTRGB,    8, 1)
 #if HAVE_BIGENDIAN
-YUV420FUNC(yuva2argb_c,      uint32_t, 1, 24, PUTRGBA,   8)
-YUV420FUNC(yuva2rgba_c,      uint32_t, 1,  0, PUTRGBA,   8)
+YUV420FUNC(yuva2argb_c,      uint32_t, 1, 24, PUTRGBA,   8, 1)
+YUV420FUNC(yuva2rgba_c,      uint32_t, 1,  0, PUTRGBA,   8, 1)
 #else
-YUV420FUNC(yuva2rgba_c,      uint32_t, 1, 24, PUTRGBA,   8)
-YUV420FUNC(yuva2argb_c,      uint32_t, 1,  0, PUTRGBA,   8)
+YUV420FUNC(yuva2rgba_c,      uint32_t, 1, 24, PUTRGBA,   8, 1)
+YUV420FUNC(yuva2argb_c,      uint32_t, 1,  0, PUTRGBA,   8, 1)
 #endif
-YUV420FUNC(yuv2rgb_c_24_rgb, uint8_t,  0,  0, PUTRGB24, 24)
-YUV420FUNC(yuv2rgb_c_24_bgr, uint8_t,  0,  0, PUTBGR24, 24)
+YUV420FUNC(yuv2rgb_c_24_rgb, uint8_t,  0,  0, PUTRGB24, 24, 1)
+YUV420FUNC(yuv2rgb_c_24_bgr, uint8_t,  0,  0, PUTBGR24, 24, 1)
 YUV420FUNC_DITHER(yuv2rgb_c_16_ordered_dither, uint16_t, LOADDITHER16,  PUTRGB16,  8)
 YUV420FUNC_DITHER(yuv2rgb_c_15_ordered_dither, uint16_t, LOADDITHER15,  PUTRGB15,  8)
 YUV420FUNC_DITHER(yuv2rgb_c_12_ordered_dither, uint16_t, LOADDITHER12,  PUTRGB12,  8)
@@ -514,18 +527,18 @@ YUV420FUNC_DITHER(yuv2rgb_c_4_ordered_dither,  uint8_t,  LOADDITHER4D,  PUTRGB4D
 YUV420FUNC_DITHER(yuv2rgb_c_4b_ordered_dither, uint8_t,  LOADDITHER4DB, PUTRGB4DB, 8)
 
 // YUV422
-YUV422FUNC(yuv422p_rgb48_c,  uint8_t,  0,  0, PUTRGB48, 48)
-YUV422FUNC(yuv422p_bgr48_c,  uint8_t,  0,  0, PUTBGR48, 48)
-YUV422FUNC(yuv422p_rgb32_c,  uint32_t, 0,  0, PUTRGB,    8)
+YUV422FUNC(yuv422p_rgb48_c,  uint8_t,  0,  0, PUTRGB48, 48, 1)
+YUV422FUNC(yuv422p_bgr48_c,  uint8_t,  0,  0, PUTBGR48, 48, 1)
+YUV422FUNC(yuv422p_rgb32_c,  uint32_t, 0,  0, PUTRGB,    8, 1)
 #if HAVE_BIGENDIAN
-YUV422FUNC(yuva422p_argb_c,  uint32_t, 1, 24, PUTRGBA,   8)
-YUV422FUNC(yuva422p_rgba_c,  uint32_t, 1,  0, PUTRGBA,   8)
+YUV422FUNC(yuva422p_argb_c,  uint32_t, 1, 24, PUTRGBA,   8, 1)
+YUV422FUNC(yuva422p_rgba_c,  uint32_t, 1,  0, PUTRGBA,   8, 1)
 #else
-YUV422FUNC(yuva422p_rgba_c,  uint32_t, 1, 24, PUTRGBA,   8)
-YUV422FUNC(yuva422p_argb_c,  uint32_t, 1,  0, PUTRGBA,   8)
+YUV422FUNC(yuva422p_rgba_c,  uint32_t, 1, 24, PUTRGBA,   8, 1)
+YUV422FUNC(yuva422p_argb_c,  uint32_t, 1,  0, PUTRGBA,   8, 1)
 #endif
-YUV422FUNC(yuv422p_rgb24_c,  uint8_t,  0,  0, PUTRGB24, 24)
-YUV422FUNC(yuv422p_bgr24_c,  uint8_t,  0,  0, PUTBGR24, 24)
+YUV422FUNC(yuv422p_rgb24_c,  uint8_t,  0,  0, PUTRGB24, 24, 1)
+YUV422FUNC(yuv422p_bgr24_c,  uint8_t,  0,  0, PUTBGR24, 24, 1)
 YUV422FUNC_DITHER(yuv422p_bgr16,     uint16_t, LOADDITHER16,  PUTRGB16,  8)
 YUV422FUNC_DITHER(yuv422p_bgr15,     uint16_t, LOADDITHER15,  PUTRGB15,  8)
 YUV422FUNC_DITHER(yuv422p_bgr12,     uint16_t, LOADDITHER12,  PUTRGB12,  8)
-- 
2.30.2



More information about the ffmpeg-devel mailing list