[vlc-devel] [PATCH] direct3d11: add a pixel shader to render BT.2020 colors for biplanar chroma

Steve Lhomme robux4 at videolabs.io
Fri Jul 29 14:52:59 CEST 2016


---
 modules/video_output/win32/direct3d11.c | 41 ++++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)

diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 160b58d..d359650 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -269,6 +269,39 @@ static const char *globPixelShaderBiplanarYUV_BT709_2RGB = "\
   }\
 ";
 
+/* RGB-709 to RGB-2020 based on https://www.researchgate.net/publication/258434326_Beyond_BT709 */
+static const char *globPixelShaderBiplanarYUV_BT2020_2RGB = "\
+  Texture2D shaderTextureY;\
+  Texture2D shaderTextureUV;\
+  SamplerState SampleType;\
+  \
+  struct PS_INPUT\
+  {\
+    float4 Position   : SV_POSITION;\
+    float2 Texture    : TEXCOORD0;\
+    float  Opacity    : OPACITY;\
+  };\
+  \
+  float4 PS( PS_INPUT In ) : SV_TARGET\
+  {\
+    float3 yuv;\
+    float4 rgba;\
+    yuv.x  = shaderTextureY.Sample(SampleType, In.Texture).x;\
+    yuv.yz = shaderTextureUV.Sample(SampleType, In.Texture).xy;\
+    yuv.x  = 1.164383561643836 * (yuv.x-0.0625);\
+    yuv.y  = yuv.y - 0.5;\
+    yuv.z  = yuv.z - 0.5;\
+    rgba.x = saturate(yuv.x + 1.792741071428571 * yuv.z);\
+    rgba.y = saturate(yuv.x - 0.532909328559444 * yuv.z - 0.21324861427373 * yuv.y);\
+    rgba.z = saturate(yuv.x + 2.112401785714286 * yuv.y);\
+    rgba.x = saturate( 1.661 * rgba.x - 0.588 * rgba.y - 0.073 * rgba.z);\
+    rgba.y = saturate(-0.125 * rgba.x + 1.133 * rgba.y - 0.008 * rgba.z);\
+    rgba.z = saturate(-0.018 * rgba.x - 0.101 * rgba.y + 1.119 * rgba.z);\
+    rgba.a = In.Opacity;\
+    return rgba;\
+  }\
+";
+
 static const char *globPixelShaderBiplanarYUYV_BT709_2RGB = "\
   Texture2D shaderTextureYUYV;\
   SamplerState SampleType;\
@@ -1228,7 +1261,13 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
     if (sys->picQuadConfig.resourceFormatYRGB == DXGI_FORMAT_R8_UNORM ||
         sys->picQuadConfig.resourceFormatYRGB == DXGI_FORMAT_R16_UNORM)
     {
-        if( fmt->i_height > 576 )
+        if (vd->fmt.space == COLOR_SPACE_BT2020)
+            sys->d3dPxShader = globPixelShaderBiplanarYUV_BT2020_2RGB;
+        else if (vd->fmt.space == COLOR_SPACE_BT709)
+            sys->d3dPxShader = globPixelShaderBiplanarYUV_BT709_2RGB;
+        else if (vd->fmt.space == COLOR_SPACE_BT601)
+            sys->d3dPxShader = globPixelShaderBiplanarYUV_BT601_2RGB;
+        else if( fmt->i_height > 576 )
             sys->d3dPxShader = globPixelShaderBiplanarYUV_BT709_2RGB;
         else
             sys->d3dPxShader = globPixelShaderBiplanarYUV_BT601_2RGB;
-- 
2.8.2



More information about the vlc-devel mailing list