[vlc-commits] [Git][videolan/vlc][master] codec: videotoolbox: move functions to map color properties in vt_utils

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Aug 31 05:52:11 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
214f8fc4 by Maxime Chapelet at 2023-08-29T18:34:23+02:00
codec: videotoolbox: move functions to map color properties in vt_utils

Those functions can be useful in other places.
One useful case will be to attach color properties properly in the cvpx converter's output image buffers in a future fix without duplicating this mapping code.

- - - - -


3 changed files:

- modules/codec/videotoolbox/decoder.c
- modules/codec/vt_utils.c
- modules/codec/vt_utils.h


Changes:

=====================================
modules/codec/videotoolbox/decoder.c
=====================================
@@ -37,7 +37,6 @@
 #import "../../packetizer/h264_slice.h"
 #import "../../packetizer/hxxx_nal.h"
 #import "../../packetizer/hxxx_sei.h"
-#import "../../packetizer/iso_color_tables.h"
 
 #import <VideoToolbox/VideoToolbox.h>
 #import <VideoToolbox/VTErrors.h>
@@ -1177,92 +1176,6 @@ static CMVideoCodecType CodecPrecheck(decoder_t *p_dec)
     vlc_assert_unreachable();
 }
 
-static CFStringRef 
-MapYCbCrMatrixFromFormat(video_color_space_t color_space)
-{
-    switch (color_space) {
-    case COLOR_SPACE_BT601:
-        return kCVImageBufferYCbCrMatrix_ITU_R_601_4;
-    case COLOR_SPACE_BT2020:
-        if (__builtin_available(macOS 10.11, iOS 9, *))
-            return kCVImageBufferYCbCrMatrix_ITU_R_2020;
-        break;
-    case COLOR_SPACE_BT709:
-        return kCVImageBufferYCbCrMatrix_ITU_R_709_2;
-    case COLOR_SPACE_UNDEF:
-        break;
-    default:
-        if (__builtin_available(macOS 10.13, iOS 11, tvOS 11, watchOS 4, *)) {
-            enum iso_23001_8_mc mc_cicp = 
-                vlc_coeffs_to_iso_23001_8_mc(color_space);
-            return CVYCbCrMatrixGetStringForIntegerCodePoint(mc_cicp);
-        }
-    }
-    return NULL;
-}
-
-static CFStringRef 
-MapColorPrimariesFromFormat(video_color_primaries_t color_primaries)
-{
-    switch (color_primaries) {
-    case COLOR_PRIMARIES_BT2020:
-        return kCVImageBufferColorPrimaries_ITU_R_2020;
-    case COLOR_PRIMARIES_BT709:
-        return kCVImageBufferColorPrimaries_ITU_R_709_2;
-    case COLOR_PRIMARIES_SMTPE_170:
-        return kCVImageBufferColorPrimaries_SMPTE_C;
-    case COLOR_PRIMARIES_EBU_3213:
-        return kCVImageBufferColorPrimaries_EBU_3213;
-    case COLOR_PRIMARIES_UNDEF:
-        break;
-    default:
-        if (__builtin_available(macOS 10.13, iOS 11, tvOS 11, watchOS 4, *)) {
-            enum iso_23001_8_cp cp_cicp = 
-                vlc_primaries_to_iso_23001_8_cp(color_primaries);
-            return CVColorPrimariesGetStringForIntegerCodePoint(cp_cicp);
-        }
-    }
-    return NULL;
-}
-
-static CFStringRef 
-MapTransferFuncFromFormat(video_transfer_func_t transfer_func)
-{
-    switch (transfer_func) {
-    case TRANSFER_FUNC_SMPTE_ST2084:
-        if (__builtin_available(macOS 10.13, iOS 11, *))
-            return kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ;
-        break;
-    case TRANSFER_FUNC_BT709:
-    /* note: as stated by CVImageBuffer.h, 
-       kCVImageBufferTransferFunction_ITU_R_709_2 is equivalent to
-       kCVImageBufferTransferFunction_ITU_R_2020 and preferred
-    */
-        return kCVImageBufferTransferFunction_ITU_R_709_2;
-    case TRANSFER_FUNC_SMPTE_240:
-        return kCVImageBufferTransferFunction_SMPTE_240M_1995;
-    case TRANSFER_FUNC_HLG:
-        if (__builtin_available(macOS 10.13, iOS 11, *))
-            return kCVImageBufferTransferFunction_ITU_R_2100_HLG;
-        break;
-    case TRANSFER_FUNC_LINEAR:
-        if (__builtin_available(macOS 10.14, iOS 12, *))
-            return kCVImageBufferTransferFunction_Linear;
-        break;
-    case TRANSFER_FUNC_SRGB:
-        return kCVImageBufferTransferFunction_UseGamma;
-    case TRANSFER_FUNC_UNDEF:
-        break;
-    default:
-        if (__builtin_available(macOS 10.13, iOS 11, tvOS 11, watchOS 4, *)) {
-            enum iso_23001_8_tc tc_cicp =
-                vlc_xfer_to_iso_23001_8_tc(transfer_func);
-            return CVTransferFunctionGetStringForIntegerCodePoint(tc_cicp);
-        }
-    }
-    return NULL;
-}
-
 static void 
 SetDecoderColorProperties(CFMutableDictionaryRef decoderConfiguration, 
                           const video_format_t *video_fmt)
@@ -1277,7 +1190,7 @@ SetDecoderColorProperties(CFMutableDictionaryRef decoderConfiguration,
     */
     
     CFStringRef color_matrix = 
-        MapYCbCrMatrixFromFormat(video_fmt->space);
+        cvpx_map_YCbCrMatrix_from_vcs(video_fmt->space);
     if (color_matrix) {
         CFDictionarySetValue(
             decoderConfiguration,
@@ -1286,7 +1199,7 @@ SetDecoderColorProperties(CFMutableDictionaryRef decoderConfiguration,
     }
 
     CFStringRef color_primaries = 
-        MapColorPrimariesFromFormat(video_fmt->primaries);
+        cvpx_map_ColorPrimaries_from_vcp(video_fmt->primaries);
     if (color_primaries) {
         CFDictionarySetValue(
             decoderConfiguration, 
@@ -1296,7 +1209,7 @@ SetDecoderColorProperties(CFMutableDictionaryRef decoderConfiguration,
     }
 
     CFStringRef color_transfer_func = 
-        MapTransferFuncFromFormat(video_fmt->transfer);
+        cvpx_map_TransferFunction_from_vtf(video_fmt->transfer);
     if (color_transfer_func) {
         CFDictionarySetValue(
             decoderConfiguration, 


=====================================
modules/codec/vt_utils.c
=====================================
@@ -25,6 +25,7 @@
 #include <vlc_atomic.h>
 
 #include "vt_utils.h"
+#include "../packetizer/iso_color_tables.h"
 
 CFMutableDictionaryRef
 cfdict_create(CFIndex capacity)
@@ -315,6 +316,92 @@ cvpxpool_new_cvpx(CVPixelBufferPoolRef pool)
     return cvpx;
 }
 
+CFStringRef 
+cvpx_map_YCbCrMatrix_from_vcs(video_color_space_t color_space)
+{
+    switch (color_space) {
+    case COLOR_SPACE_BT601:
+        return kCVImageBufferYCbCrMatrix_ITU_R_601_4;
+    case COLOR_SPACE_BT2020:
+        if (__builtin_available(macOS 10.11, iOS 9, *))
+            return kCVImageBufferYCbCrMatrix_ITU_R_2020;
+        break;
+    case COLOR_SPACE_BT709:
+        return kCVImageBufferYCbCrMatrix_ITU_R_709_2;
+    case COLOR_SPACE_UNDEF:
+        break;
+    default:
+        if (__builtin_available(macOS 10.13, iOS 11, tvOS 11, watchOS 4, *)) {
+            enum iso_23001_8_mc mc_cicp = 
+                vlc_coeffs_to_iso_23001_8_mc(color_space);
+            return CVYCbCrMatrixGetStringForIntegerCodePoint(mc_cicp);
+        }
+    }
+    return NULL;
+}
+
+CFStringRef 
+cvpx_map_ColorPrimaries_from_vcp(video_color_primaries_t color_primaries)
+{
+    switch (color_primaries) {
+    case COLOR_PRIMARIES_BT2020:
+        return kCVImageBufferColorPrimaries_ITU_R_2020;
+    case COLOR_PRIMARIES_BT709:
+        return kCVImageBufferColorPrimaries_ITU_R_709_2;
+    case COLOR_PRIMARIES_SMTPE_170:
+        return kCVImageBufferColorPrimaries_SMPTE_C;
+    case COLOR_PRIMARIES_EBU_3213:
+        return kCVImageBufferColorPrimaries_EBU_3213;
+    case COLOR_PRIMARIES_UNDEF:
+        break;
+    default:
+        if (__builtin_available(macOS 10.13, iOS 11, tvOS 11, watchOS 4, *)) {
+            enum iso_23001_8_cp cp_cicp = 
+                vlc_primaries_to_iso_23001_8_cp(color_primaries);
+            return CVColorPrimariesGetStringForIntegerCodePoint(cp_cicp);
+        }
+    }
+    return NULL;
+}
+
+CFStringRef 
+cvpx_map_TransferFunction_from_vtf(video_transfer_func_t transfer_func)
+{
+    switch (transfer_func) {
+    case TRANSFER_FUNC_SMPTE_ST2084:
+        if (__builtin_available(macOS 10.13, iOS 11, *))
+            return kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ;
+        break;
+    case TRANSFER_FUNC_BT709:
+    /* note: as stated by CVImageBuffer.h, 
+       kCVImageBufferTransferFunction_ITU_R_709_2 is equivalent to
+       kCVImageBufferTransferFunction_ITU_R_2020 and preferred
+    */
+        return kCVImageBufferTransferFunction_ITU_R_709_2;
+    case TRANSFER_FUNC_SMPTE_240:
+        return kCVImageBufferTransferFunction_SMPTE_240M_1995;
+    case TRANSFER_FUNC_HLG:
+        if (__builtin_available(macOS 10.13, iOS 11, *))
+            return kCVImageBufferTransferFunction_ITU_R_2100_HLG;
+        break;
+    case TRANSFER_FUNC_LINEAR:
+        if (__builtin_available(macOS 10.14, iOS 12, *))
+            return kCVImageBufferTransferFunction_Linear;
+        break;
+    case TRANSFER_FUNC_SRGB:
+        return kCVImageBufferTransferFunction_UseGamma;
+    case TRANSFER_FUNC_UNDEF:
+        break;
+    default:
+        if (__builtin_available(macOS 10.13, iOS 11, tvOS 11, watchOS 4, *)) {
+            enum iso_23001_8_tc tc_cicp =
+                vlc_xfer_to_iso_23001_8_tc(transfer_func);
+            return CVTransferFunctionGetStringForIntegerCodePoint(tc_cicp);
+        }
+    }
+    return NULL;
+}
+
 struct cvpx_video_context
 {
     const struct vlc_video_context_operations *ops;


=====================================
modules/codec/vt_utils.h
=====================================
@@ -77,6 +77,36 @@ CVPixelBufferPoolRef cvpxpool_create(const video_format_t *fmt, unsigned count);
  */
 CVPixelBufferRef cvpxpool_new_cvpx(CVPixelBufferPoolRef pool);
 
+/**
+ * @brief Get a kCVImageBufferYCbCrMatrix_X value corresponding 
+ * to a video_color_space_t
+ * 
+ * @param color_space a video format color space value
+ * @return a CFStringRef or NULL if there's no value match
+ */
+CFStringRef 
+cvpx_map_YCbCrMatrix_from_vcs(video_color_space_t color_space);
+
+/**
+ * @brief Get a kCVImageBufferColorPrimaries_X value corresponding 
+ * to a video_color_primaries_t
+ * 
+ * @param color_primaries a video format color primaries value
+ * @return a CFStringRef or NULL if there's no value match
+ */
+CFStringRef 
+cvpx_map_ColorPrimaries_from_vcp(video_color_primaries_t color_primaries);
+
+/**
+ * @brief Get a kCVImageBufferTransferFunction_X value corresponding 
+ * to a video_transfer_func_t
+ * 
+ * @param transfer_func a video format transfer func value
+ * @return a CFStringRef or NULL if there's no value match
+ */
+CFStringRef 
+cvpx_map_TransferFunction_from_vtf(video_transfer_func_t transfer_func);
+
 enum cvpx_video_context_type
 {
     CVPX_VIDEO_CONTEXT_DEFAULT,



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/214f8fc46ea126f84bc1d0697a916000f4f7a6de

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/214f8fc46ea126f84bc1d0697a916000f4f7a6de
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list