[vlc-commits] avcodec: extract video_format_t color setting as a function

Zhao Zhili git at videolan.org
Mon Nov 2 10:08:15 CET 2020


vlc | branch: master | Zhao Zhili <quinkblack at foxmail.com> | Thu Oct  8 14:08:00 2020 +0200| [439efd8084605755f4916df5f8f0ca740b4e7f6f] | committer: Steve Lhomme

avcodec: extract video_format_t color setting as a function

Now the APIs for color information conversion are symmetric.

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=439efd8084605755f4916df5f8f0ca740b4e7f6f
---

 modules/codec/avcodec/avcommon.h | 103 +++++++++++++++++++++++++++++++++++++++
 modules/codec/avcodec/video.c    | 100 +------------------------------------
 2 files changed, 104 insertions(+), 99 deletions(-)

diff --git a/modules/codec/avcodec/avcommon.h b/modules/codec/avcodec/avcommon.h
index 6c0c88704c..acd4790651 100644
--- a/modules/codec/avcodec/avcommon.h
+++ b/modules/codec/avcodec/avcommon.h
@@ -255,4 +255,107 @@ static inline void set_video_color_settings( const video_format_t *p_fmt, AVCode
     }
 }
 
+static inline void get_video_color_settings( const AVCodecContext *ctx,
+                                             video_format_t *fmt )
+{
+    switch ( ctx->color_range )
+    {
+    case AVCOL_RANGE_JPEG:
+        fmt->color_range = COLOR_RANGE_FULL;
+        break;
+    case AVCOL_RANGE_MPEG:
+        fmt->color_range = COLOR_RANGE_LIMITED;
+        break;
+    default: /* do nothing */
+        break;
+    }
+
+    switch( ctx->colorspace )
+    {
+        case AVCOL_SPC_BT709:
+            fmt->space = COLOR_SPACE_BT709;
+            break;
+        case AVCOL_SPC_SMPTE170M:
+        case AVCOL_SPC_BT470BG:
+            fmt->space = COLOR_SPACE_BT601;
+            break;
+        case AVCOL_SPC_BT2020_NCL:
+        case AVCOL_SPC_BT2020_CL:
+            fmt->space = COLOR_SPACE_BT2020;
+            break;
+        default:
+            break;
+    }
+
+    switch( ctx->color_trc )
+    {
+        case AVCOL_TRC_LINEAR:
+            fmt->transfer = TRANSFER_FUNC_LINEAR;
+            break;
+        case AVCOL_TRC_GAMMA22:
+            fmt->transfer = TRANSFER_FUNC_SRGB;
+            break;
+        case AVCOL_TRC_BT709:
+            fmt->transfer = TRANSFER_FUNC_BT709;
+            break;
+        case AVCOL_TRC_SMPTE170M:
+        case AVCOL_TRC_BT2020_10:
+        case AVCOL_TRC_BT2020_12:
+            fmt->transfer = TRANSFER_FUNC_BT2020;
+            break;
+#if LIBAVUTIL_VERSION_CHECK( 55, 14, 0, 31, 100)
+        case AVCOL_TRC_ARIB_STD_B67:
+            fmt->transfer = TRANSFER_FUNC_ARIB_B67;
+            break;
+#endif
+#if LIBAVUTIL_VERSION_CHECK( 55, 17, 0, 37, 100)
+        case AVCOL_TRC_SMPTE2084:
+            fmt->transfer = TRANSFER_FUNC_SMPTE_ST2084;
+            break;
+        case AVCOL_TRC_SMPTE240M:
+            fmt->transfer = TRANSFER_FUNC_SMPTE_240;
+            break;
+        case AVCOL_TRC_GAMMA28:
+            fmt->transfer = TRANSFER_FUNC_BT470_BG;
+            break;
+#endif
+        default:
+            break;
+    }
+
+    switch( ctx->color_primaries )
+    {
+        case AVCOL_PRI_BT709:
+            fmt->primaries = COLOR_PRIMARIES_BT709;
+            break;
+        case AVCOL_PRI_BT470BG:
+            fmt->primaries = COLOR_PRIMARIES_BT601_625;
+            break;
+        case AVCOL_PRI_SMPTE170M:
+        case AVCOL_PRI_SMPTE240M:
+            fmt->primaries = COLOR_PRIMARIES_BT601_525;
+            break;
+        case AVCOL_PRI_BT2020:
+            fmt->primaries = COLOR_PRIMARIES_BT2020;
+            break;
+        default:
+            break;
+    }
+
+    switch( ctx->chroma_sample_location )
+    {
+        case AVCHROMA_LOC_LEFT:
+            fmt->chroma_location = CHROMA_LOCATION_LEFT;
+            break;
+        case AVCHROMA_LOC_CENTER:
+            fmt->chroma_location = CHROMA_LOCATION_CENTER;
+            break;
+        case AVCHROMA_LOC_TOPLEFT:
+            fmt->chroma_location = CHROMA_LOCATION_TOP_LEFT;
+            break;
+        default:
+            break;
+    }
+}
+
 #endif
diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index c17954228c..6a30ef8400 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -231,105 +231,7 @@ static int lavc_GetVideoFormat(decoder_t *dec, video_format_t *restrict fmt,
                                  * __MAX(ctx->ticks_per_frame, 1);
     }
 
-    switch ( ctx->color_range )
-    {
-    case AVCOL_RANGE_JPEG:
-        fmt->color_range = COLOR_RANGE_FULL;
-        break;
-    case AVCOL_RANGE_MPEG:
-        fmt->color_range = COLOR_RANGE_LIMITED;
-        break;
-    default: /* do nothing */
-        break;
-    }
-
-    switch( ctx->colorspace )
-    {
-        case AVCOL_SPC_BT709:
-            fmt->space = COLOR_SPACE_BT709;
-            break;
-        case AVCOL_SPC_SMPTE170M:
-        case AVCOL_SPC_BT470BG:
-            fmt->space = COLOR_SPACE_BT601;
-            break;
-        case AVCOL_SPC_BT2020_NCL:
-        case AVCOL_SPC_BT2020_CL:
-            fmt->space = COLOR_SPACE_BT2020;
-            break;
-        default:
-            break;
-    }
-
-    switch( ctx->color_trc )
-    {
-        case AVCOL_TRC_LINEAR:
-            fmt->transfer = TRANSFER_FUNC_LINEAR;
-            break;
-        case AVCOL_TRC_GAMMA22:
-            fmt->transfer = TRANSFER_FUNC_SRGB;
-            break;
-        case AVCOL_TRC_BT709:
-            fmt->transfer = TRANSFER_FUNC_BT709;
-            break;
-        case AVCOL_TRC_SMPTE170M:
-        case AVCOL_TRC_BT2020_10:
-        case AVCOL_TRC_BT2020_12:
-            fmt->transfer = TRANSFER_FUNC_BT2020;
-            break;
-#if LIBAVUTIL_VERSION_CHECK( 55, 14, 0, 31, 100)
-        case AVCOL_TRC_ARIB_STD_B67:
-            fmt->transfer = TRANSFER_FUNC_ARIB_B67;
-            break;
-#endif
-#if LIBAVUTIL_VERSION_CHECK( 55, 17, 0, 37, 100)
-        case AVCOL_TRC_SMPTE2084:
-            fmt->transfer = TRANSFER_FUNC_SMPTE_ST2084;
-            break;
-        case AVCOL_TRC_SMPTE240M:
-            fmt->transfer = TRANSFER_FUNC_SMPTE_240;
-            break;
-        case AVCOL_TRC_GAMMA28:
-            fmt->transfer = TRANSFER_FUNC_BT470_BG;
-            break;
-#endif
-        default:
-            break;
-    }
-
-    switch( ctx->color_primaries )
-    {
-        case AVCOL_PRI_BT709:
-            fmt->primaries = COLOR_PRIMARIES_BT709;
-            break;
-        case AVCOL_PRI_BT470BG:
-            fmt->primaries = COLOR_PRIMARIES_BT601_625;
-            break;
-        case AVCOL_PRI_SMPTE170M:
-        case AVCOL_PRI_SMPTE240M:
-            fmt->primaries = COLOR_PRIMARIES_BT601_525;
-            break;
-        case AVCOL_PRI_BT2020:
-            fmt->primaries = COLOR_PRIMARIES_BT2020;
-            break;
-        default:
-            break;
-    }
-
-    switch( ctx->chroma_sample_location )
-    {
-        case AVCHROMA_LOC_LEFT:
-            fmt->chroma_location = CHROMA_LOCATION_LEFT;
-            break;
-        case AVCHROMA_LOC_CENTER:
-            fmt->chroma_location = CHROMA_LOCATION_CENTER;
-            break;
-        case AVCHROMA_LOC_TOPLEFT:
-            fmt->chroma_location = CHROMA_LOCATION_TOP_LEFT;
-            break;
-        default:
-            break;
-    }
-
+    get_video_color_settings(ctx, fmt);
     return 0;
 }
 



More information about the vlc-commits mailing list