[FFmpeg-cvslog] swscale/input: add support for P012

Philip Langdale git at videolan.org
Tue Sep 6 22:50:40 EEST 2022


ffmpeg | branch: master | Philip Langdale <philipl at overt.org> | Sun Sep  4 15:43:23 2022 -0700| [5bdd7261150db5d254d588f6cf8f038c149e63b5] | committer: Philip Langdale

swscale/input: add support for P012

As we now have three of these formats, I added macros to generate the
conversion functions.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5bdd7261150db5d254d588f6cf8f038c149e63b5
---

 libswscale/input.c   | 123 +++++++++++++++++++++++++++------------------------
 libswscale/utils.c   |   2 +
 libswscale/version.h |   2 +-
 3 files changed, 67 insertions(+), 60 deletions(-)

diff --git a/libswscale/input.c b/libswscale/input.c
index 8032360907..babedfd541 100644
--- a/libswscale/input.c
+++ b/libswscale/input.c
@@ -749,67 +749,60 @@ static void nv21ToUV_c(uint8_t *dstU, uint8_t *dstV,
     nvXXtoUV_c(dstV, dstU, src1, width);
 }
 
-static void p010LEToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1,
-                        const uint8_t *unused2, int width, uint32_t *unused, void *opq)
-{
-    int i;
-    for (i = 0; i < width; i++) {
-        AV_WN16(dst + i * 2, AV_RL16(src + i * 2) >> 6);
-    }
-}
-
-static void p010BEToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1,
-                        const uint8_t *unused2, int width, uint32_t *unused, void *opq)
-{
-    int i;
-    for (i = 0; i < width; i++) {
-        AV_WN16(dst + i * 2, AV_RB16(src + i * 2) >> 6);
+#define p01x_uv_wrapper(bits, shift) \
+    static void p0 ## bits ## LEToUV_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)      \
+    {                                                                    \
+        int i;                                                           \
+        for (i = 0; i < width; i++) {                                    \
+            AV_WN16(dstU + i * 2, AV_RL16(src1 + i * 4 + 0) >> shift);   \
+            AV_WN16(dstV + i * 2, AV_RL16(src1 + i * 4 + 2) >> shift);   \
+        }                                                                \
+    }                                                                    \
+                                                                         \
+    static void p0 ## bits ## BEToUV_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)      \
+    {                                                                    \
+        int i;                                                           \
+        for (i = 0; i < width; i++) {                                    \
+            AV_WN16(dstU + i * 2, AV_RB16(src1 + i * 4 + 0) >> shift);   \
+            AV_WN16(dstV + i * 2, AV_RB16(src1 + i * 4 + 2) >> shift);   \
+        }                                                                \
     }
-}
 
-static void p010LEToUV_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)
-{
-    int i;
-    for (i = 0; i < width; i++) {
-        AV_WN16(dstU + i * 2, AV_RL16(src1 + i * 4 + 0) >> 6);
-        AV_WN16(dstV + i * 2, AV_RL16(src1 + i * 4 + 2) >> 6);
-    }
-}
-
-static void p010BEToUV_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)
-{
-    int i;
-    for (i = 0; i < width; i++) {
-        AV_WN16(dstU + i * 2, AV_RB16(src1 + i * 4 + 0) >> 6);
-        AV_WN16(dstV + i * 2, AV_RB16(src1 + i * 4 + 2) >> 6);
-    }
-}
-
-static void p016LEToUV_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)
-{
-    int i;
-    for (i = 0; i < width; i++) {
-        AV_WN16(dstU + i * 2, AV_RL16(src1 + i * 4 + 0));
-        AV_WN16(dstV + i * 2, AV_RL16(src1 + i * 4 + 2));
-    }
-}
-
-static void p016BEToUV_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)
-{
-    int i;
-    for (i = 0; i < width; i++) {
-        AV_WN16(dstU + i * 2, AV_RB16(src1 + i * 4 + 0));
-        AV_WN16(dstV + i * 2, AV_RB16(src1 + i * 4 + 2));
-    }
-}
+#define p01x_wrapper(bits, shift) \
+    static void p0 ## bits ## LEToY_c(uint8_t *dst, const uint8_t *src,  \
+                                      const uint8_t *unused1,            \
+                                      const uint8_t *unused2, int width, \
+                                      uint32_t *unused, void *opq)       \
+    {                                                                    \
+        int i;                                                           \
+        for (i = 0; i < width; i++) {                                    \
+            AV_WN16(dst + i * 2, AV_RL16(src + i * 2) >> shift);         \
+        }                                                                \
+    }                                                                    \
+                                                                         \
+    static void p0 ## bits ## BEToY_c(uint8_t *dst, const uint8_t *src,  \
+                                      const uint8_t *unused1,            \
+                                      const uint8_t *unused2, int width, \
+                                      uint32_t *unused, void *opq)       \
+    {                                                                    \
+        int i;                                                           \
+        for (i = 0; i < width; i++) {                                    \
+            AV_WN16(dst + i * 2, AV_RB16(src + i * 2) >> shift);         \
+        }                                                                \
+    }                                                                    \
+    p01x_uv_wrapper(bits, shift)
+
+p01x_wrapper(10, 6);
+p01x_wrapper(12, 4);
+p01x_uv_wrapper(16, 0);
 
 #define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
 
@@ -1413,6 +1406,12 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c)
     case AV_PIX_FMT_P410BE:
         c->chrToYV12 = p010BEToUV_c;
         break;
+    case AV_PIX_FMT_P012LE:
+        c->chrToYV12 = p012LEToUV_c;
+        break;
+    case AV_PIX_FMT_P012BE:
+        c->chrToYV12 = p012BEToUV_c;
+        break;
     case AV_PIX_FMT_P016LE:
     case AV_PIX_FMT_P216LE:
     case AV_PIX_FMT_P416LE:
@@ -1893,6 +1892,12 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c)
     case AV_PIX_FMT_P410BE:
         c->lumToYV12 = p010BEToY_c;
         break;
+    case AV_PIX_FMT_P012LE:
+        c->lumToYV12 = p012LEToY_c;
+        break;
+    case AV_PIX_FMT_P012BE:
+        c->lumToYV12 = p012BEToY_c;
+        break;
     case AV_PIX_FMT_GRAYF32LE:
         c->lumToYV12 = grayf32leToY16_c;
         break;
diff --git a/libswscale/utils.c b/libswscale/utils.c
index a67e07b612..a7f77cd39d 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -236,6 +236,8 @@ static const FormatEntry format_entries[] = {
     [AV_PIX_FMT_AYUV64LE]    = { 1, 1},
     [AV_PIX_FMT_P010LE]      = { 1, 1 },
     [AV_PIX_FMT_P010BE]      = { 1, 1 },
+    [AV_PIX_FMT_P012LE]      = { 1, 0 },
+    [AV_PIX_FMT_P012BE]      = { 1, 0 },
     [AV_PIX_FMT_P016LE]      = { 1, 1 },
     [AV_PIX_FMT_P016BE]      = { 1, 1 },
     [AV_PIX_FMT_GRAYF32LE]   = { 1, 1 },
diff --git a/libswscale/version.h b/libswscale/version.h
index 403fc8f9e7..dd517a1fc6 100644
--- a/libswscale/version.h
+++ b/libswscale/version.h
@@ -29,7 +29,7 @@
 #include "version_major.h"
 
 #define LIBSWSCALE_VERSION_MINOR   8
-#define LIBSWSCALE_VERSION_MICRO 105
+#define LIBSWSCALE_VERSION_MICRO 106
 
 #define LIBSWSCALE_VERSION_INT  AV_VERSION_INT(LIBSWSCALE_VERSION_MAJOR, \
                                                LIBSWSCALE_VERSION_MINOR, \



More information about the ffmpeg-cvslog mailing list