From 59d92ea62c9802b1109e74a470647e881f57b423 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Fri, 8 Jul 2022 04:37:33 +0900 Subject: [PATCH] d3d11: Add an utility method for DXGI colorspace conversion Add a method for DXGI_COLOR_SPACE_TYPE -> GstVideoColorimetry conversion Part-of: --- .../sys/d3d11/gstd3d11pluginutils.cpp | 151 ++++++++++++++++++ .../sys/d3d11/gstd3d11pluginutils.h | 3 + 2 files changed, 154 insertions(+) diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.cpp index 299f4d4715..96948e9285 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.cpp @@ -524,6 +524,157 @@ gst_d3d11_video_info_to_dxgi_color_space (const GstVideoInfo * info, return gst_d3d11_video_info_to_dxgi_color_space_yuv (info, color_space); } +gboolean +gst_d3d11_colorimetry_from_dxgi_color_space (DXGI_COLOR_SPACE_TYPE colorspace, + GstVideoColorimetry * colorimetry) +{ + /* XXX: because of ancient MinGW header */ + GST_DXGI_COLOR_SPACE_TYPE type = (GST_DXGI_COLOR_SPACE_TYPE) colorspace; + GstVideoColorimetry color; + + switch (type) { + case GST_DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709: + color.range = GST_VIDEO_COLOR_RANGE_0_255; + color.matrix = GST_VIDEO_COLOR_MATRIX_RGB; + color.transfer = GST_VIDEO_TRANSFER_SRGB; + color.primaries = GST_VIDEO_COLOR_PRIMARIES_BT709; + break; + case GST_DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709: + color.range = GST_VIDEO_COLOR_RANGE_0_255; + color.matrix = GST_VIDEO_COLOR_MATRIX_RGB; + color.transfer = GST_VIDEO_TRANSFER_GAMMA10; + color.primaries = GST_VIDEO_COLOR_PRIMARIES_BT709; + break; + case GST_DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P709: + color.range = GST_VIDEO_COLOR_RANGE_16_235; + color.matrix = GST_VIDEO_COLOR_MATRIX_RGB; + color.transfer = GST_VIDEO_TRANSFER_BT709; + color.primaries = GST_VIDEO_COLOR_PRIMARIES_BT709; + break; + case GST_DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P2020: + color.range = GST_VIDEO_COLOR_RANGE_16_235; + color.matrix = GST_VIDEO_COLOR_MATRIX_RGB; + color.transfer = GST_VIDEO_TRANSFER_BT2020_10; + color.primaries = GST_VIDEO_COLOR_PRIMARIES_BT2020; + break; + case GST_DXGI_COLOR_SPACE_YCBCR_FULL_G22_NONE_P709_X601: + color.range = GST_VIDEO_COLOR_RANGE_0_255; + color.matrix = GST_VIDEO_COLOR_MATRIX_BT601; + color.transfer = GST_VIDEO_TRANSFER_BT601; + color.primaries = GST_VIDEO_COLOR_PRIMARIES_BT709; + break; + case GST_DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601: + color.range = GST_VIDEO_COLOR_RANGE_16_235; + color.matrix = GST_VIDEO_COLOR_MATRIX_BT601; + color.transfer = GST_VIDEO_TRANSFER_BT601; + color.primaries = GST_VIDEO_COLOR_PRIMARIES_SMPTE170M; + break; + case GST_DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P601: + color.range = GST_VIDEO_COLOR_RANGE_0_255; + color.matrix = GST_VIDEO_COLOR_MATRIX_BT601; + color.transfer = GST_VIDEO_TRANSFER_BT601; + color.primaries = GST_VIDEO_COLOR_PRIMARIES_SMPTE170M; + break; + case GST_DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709: + color.range = GST_VIDEO_COLOR_RANGE_16_235; + color.matrix = GST_VIDEO_COLOR_MATRIX_BT709; + color.transfer = GST_VIDEO_TRANSFER_BT709; + color.primaries = GST_VIDEO_COLOR_PRIMARIES_BT709; + break; + case GST_DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P709: + color.range = GST_VIDEO_COLOR_RANGE_0_255; + color.matrix = GST_VIDEO_COLOR_MATRIX_BT709; + color.transfer = GST_VIDEO_TRANSFER_BT709; + color.primaries = GST_VIDEO_COLOR_PRIMARIES_BT709; + break; + case GST_DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P2020: + color.range = GST_VIDEO_COLOR_RANGE_16_235; + color.matrix = GST_VIDEO_COLOR_MATRIX_BT2020; + color.transfer = GST_VIDEO_TRANSFER_BT2020_10; + color.primaries = GST_VIDEO_COLOR_PRIMARIES_BT2020; + break; + case GST_DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020: + color.range = GST_VIDEO_COLOR_RANGE_0_255; + color.matrix = GST_VIDEO_COLOR_MATRIX_BT2020; + color.transfer = GST_VIDEO_TRANSFER_BT2020_10; + color.primaries = GST_VIDEO_COLOR_PRIMARIES_BT2020; + break; + case GST_DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020: + color.range = GST_VIDEO_COLOR_RANGE_0_255; + color.matrix = GST_VIDEO_COLOR_MATRIX_RGB; + color.transfer = GST_VIDEO_TRANSFER_SMPTE2084; + color.primaries = GST_VIDEO_COLOR_PRIMARIES_BT2020; + break; + case GST_DXGI_COLOR_SPACE_RGB_STUDIO_G2084_NONE_P2020: + color.range = GST_VIDEO_COLOR_RANGE_16_235; + color.matrix = GST_VIDEO_COLOR_MATRIX_RGB; + color.transfer = GST_VIDEO_TRANSFER_SMPTE2084; + color.primaries = GST_VIDEO_COLOR_PRIMARIES_BT2020; + break; + case GST_DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_TOPLEFT_P2020: + color.range = GST_VIDEO_COLOR_RANGE_16_235; + color.matrix = GST_VIDEO_COLOR_MATRIX_BT2020; + color.transfer = GST_VIDEO_TRANSFER_BT2020_10; + color.primaries = GST_VIDEO_COLOR_PRIMARIES_BT2020; + break; + case GST_DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_TOPLEFT_P2020: + color.range = GST_VIDEO_COLOR_RANGE_16_235; + color.matrix = GST_VIDEO_COLOR_MATRIX_BT2020; + color.transfer = GST_VIDEO_TRANSFER_SMPTE2084; + color.primaries = GST_VIDEO_COLOR_PRIMARIES_BT2020; + break; + case GST_DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P2020: + color.range = GST_VIDEO_COLOR_RANGE_0_255; + color.matrix = GST_VIDEO_COLOR_MATRIX_RGB; + color.transfer = GST_VIDEO_TRANSFER_SMPTE2084; + color.primaries = GST_VIDEO_COLOR_PRIMARIES_BT2020; + break; + case GST_DXGI_COLOR_SPACE_YCBCR_STUDIO_GHLG_TOPLEFT_P2020: + color.range = GST_VIDEO_COLOR_RANGE_16_235; + color.matrix = GST_VIDEO_COLOR_MATRIX_BT2020; + color.transfer = GST_VIDEO_TRANSFER_ARIB_STD_B67; + color.primaries = GST_VIDEO_COLOR_PRIMARIES_BT2020; + break; + case GST_DXGI_COLOR_SPACE_YCBCR_FULL_GHLG_TOPLEFT_P2020: + color.range = GST_VIDEO_COLOR_RANGE_0_255; + color.matrix = GST_VIDEO_COLOR_MATRIX_BT2020; + color.transfer = GST_VIDEO_TRANSFER_ARIB_STD_B67; + color.primaries = GST_VIDEO_COLOR_PRIMARIES_BT2020; + break; + case GST_DXGI_COLOR_SPACE_RGB_STUDIO_G24_NONE_P709: + color.range = GST_VIDEO_COLOR_RANGE_16_235; + color.matrix = GST_VIDEO_COLOR_MATRIX_RGB; + color.transfer = GST_VIDEO_TRANSFER_SRGB; + color.primaries = GST_VIDEO_COLOR_PRIMARIES_BT709; + break; + case GST_DXGI_COLOR_SPACE_RGB_STUDIO_G24_NONE_P2020: + color.range = GST_VIDEO_COLOR_RANGE_16_235; + color.matrix = GST_VIDEO_COLOR_MATRIX_RGB; + color.transfer = GST_VIDEO_TRANSFER_SRGB; + color.primaries = GST_VIDEO_COLOR_PRIMARIES_BT2020; + break; + case GST_DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_LEFT_P709: + color.range = GST_VIDEO_COLOR_RANGE_16_235; + color.matrix = GST_VIDEO_COLOR_MATRIX_RGB; + color.transfer = GST_VIDEO_TRANSFER_SRGB; + color.primaries = GST_VIDEO_COLOR_PRIMARIES_BT709; + break; + case GST_DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_LEFT_P2020: + case GST_DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_TOPLEFT_P2020: + color.range = GST_VIDEO_COLOR_RANGE_16_235; + color.matrix = GST_VIDEO_COLOR_MATRIX_RGB; + color.transfer = GST_VIDEO_TRANSFER_SRGB; + color.primaries = GST_VIDEO_COLOR_PRIMARIES_BT2020; + break; + default: + return FALSE; + } + + *colorimetry = color; + + return TRUE; +} + gboolean gst_d3d11_find_swap_chain_color_space (const GstVideoInfo * info, IDXGISwapChain3 * swapchain, GstDxgiColorSpace * color_space) diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.h b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.h index 7ffdafb966..f4af36c3ec 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.h +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.h @@ -70,6 +70,9 @@ gboolean gst_d3d11_hdr_meta_data_to_dxgi (GstVideoMasteringDisplayInf gboolean gst_d3d11_video_info_to_dxgi_color_space (const GstVideoInfo * info, GstDxgiColorSpace * color_space); +gboolean gst_d3d11_colorimetry_from_dxgi_color_space (DXGI_COLOR_SPACE_TYPE colorspace, + GstVideoColorimetry * colorimetry); + gboolean gst_d3d11_find_swap_chain_color_space (const GstVideoInfo * info, IDXGISwapChain3 * swapchain, GstDxgiColorSpace * color_space);