[vlc-commits] [Git][videolan/vlc][master] 2 commits: codec: videotoolbox: add utility function to map and attach video format color...
Steve Lhomme (@robUx4)
gitlab at videolan.org
Fri Sep 1 16:07:21 UTC 2023
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
2838f0c4 by Maxime Chapelet at 2023-09-01T15:49:35+00:00
codec: videotoolbox: add utility function to map and attach video format color properties to a CoreVideo buffer
- - - - -
43e8db57 by Maxime Chapelet at 2023-09-01T15:49:35+00:00
chroma: cvpx: convert video format color properties and attach them to converted CoreVideo buffer
This converts color properties from the source video format and attach them to the converted CoreVideo buffer in order to present them properly with a native Darwin renderer.
- - - - -
3 changed files:
- modules/codec/vt_utils.c
- modules/codec/vt_utils.h
- modules/video_chroma/cvpx.c
Changes:
=====================================
modules/codec/vt_utils.c
=====================================
@@ -402,6 +402,83 @@ cvpx_map_TransferFunction_from_vtf(video_transfer_func_t transfer_func)
return NULL;
}
+bool cvpx_has_attachment(CVPixelBufferRef pixelBuffer, CFStringRef key) {
+ if (__builtin_available(macOS 10.12, iOS 15, *)) {
+ return CVBufferHasAttachment(pixelBuffer, key);
+ }
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ return CVBufferGetAttachment(pixelBuffer, key, NULL) != NULL;
+#pragma clang diagnostic pop
+}
+
+
+
+void cvpx_attach_mapped_color_properties(CVPixelBufferRef cvpx,
+ const video_format_t *fmt)
+{
+ if (!cvpx_has_attachment(cvpx, kCVImageBufferYCbCrMatrixKey))
+ {
+ CFStringRef color_matrix =
+ cvpx_map_YCbCrMatrix_from_vcs(fmt->space);
+ if (color_matrix) {
+ CVBufferSetAttachment(
+ cvpx,
+ kCVImageBufferYCbCrMatrixKey,
+ color_matrix,
+ kCVAttachmentMode_ShouldPropagate
+ );
+ }
+ }
+
+ if (!cvpx_has_attachment(cvpx, kCVImageBufferColorPrimariesKey))
+ {
+ CFStringRef color_primaries =
+ cvpx_map_ColorPrimaries_from_vcp(fmt->primaries);
+ if (color_primaries) {
+ CVBufferSetAttachment(
+ cvpx,
+ kCVImageBufferColorPrimariesKey,
+ color_primaries,
+ kCVAttachmentMode_ShouldPropagate
+ );
+ }
+ }
+
+ if (!cvpx_has_attachment(cvpx, kCVImageBufferTransferFunctionKey))
+ {
+ CFStringRef color_transfer_func =
+ cvpx_map_TransferFunction_from_vtf(fmt->transfer);
+ if (color_transfer_func) {
+ CVBufferSetAttachment(
+ cvpx,
+ kCVImageBufferTransferFunctionKey,
+ color_transfer_func,
+ kCVAttachmentMode_ShouldPropagate
+ );
+ }
+ }
+
+ if (!cvpx_has_attachment(cvpx, kCVImageBufferGammaLevelKey))
+ {
+ Float32 gamma = 0;
+ if (fmt->transfer == TRANSFER_FUNC_SRGB)
+ gamma = 2.2;
+
+ if (gamma != 0) {
+ CFNumberRef value =
+ CFNumberCreate(NULL, kCFNumberFloat32Type, &gamma);
+ CVBufferSetAttachment(
+ cvpx,
+ kCVImageBufferGammaLevelKey,
+ value,
+ kCVAttachmentMode_ShouldPropagate
+ );
+ CFRelease(value);
+ }
+ }
+}
+
struct cvpx_video_context
{
const struct vlc_video_context_operations *ops;
=====================================
modules/codec/vt_utils.h
=====================================
@@ -107,6 +107,29 @@ cvpx_map_ColorPrimaries_from_vcp(video_color_primaries_t color_primaries);
CFStringRef
cvpx_map_TransferFunction_from_vtf(video_transfer_func_t transfer_func);
+/**
+ * @brief Check if an image buffer has an attachment corresponding to the key
+ * parameter
+ *
+ * @param pixelBuffer the image buffer where attachment is searched
+ * @param key the attachment's key to search
+ * @return true if attachment is present
+ * @return false if key didn't match any attachment
+ */
+bool cvpx_has_attachment(CVPixelBufferRef pixelBuffer, CFStringRef key);
+
+/**
+ * @brief Try to map and attach kCVImageBufferYCbCrMatrixKey,
+ * kCVImageBufferColorPrimariesKey, kCVImageBufferTransferFunctionKey and
+ * kCVImageBufferGammaLevelKey if correspondance is found from a video_format_t.
+ * Attachments can be optionally kept if already present or overwritten
+ *
+ * @param cvpx The image buffer where properties will be attached
+ * @param fmt The video format that contains the source color properties
+ */
+void cvpx_attach_mapped_color_properties(CVPixelBufferRef cvpx,
+ const video_format_t *fmt);
+
enum cvpx_video_context_type
{
CVPX_VIDEO_CONTEXT_DEFAULT,
=====================================
modules/video_chroma/cvpx.c
=====================================
@@ -198,6 +198,8 @@ static picture_t *SW_TO_CVPX_Filter(filter_t *p_filter, picture_t *src)
return NULL;
}
+ cvpx_attach_mapped_color_properties(cvpx, &p_sys->sw.fmt);
+
/* Allocate a CPVX backed picture mapped for read/write */
picture_t *mapped_dst =
cvpxpic_create_mapped(&p_sys->sw.fmt, cvpx, p_filter->vctx_out, false);
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/044464ee0d3b098c09db9ab97cebc58fe3aadd35...43e8db57f8b23acf0d32b22fec580048e6776ed6
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/044464ee0d3b098c09db9ab97cebc58fe3aadd35...43e8db57f8b23acf0d32b22fec580048e6776ed6
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