Browse Source

libobs: Add support for reading I420 HLG

Sony cameras can create 8-bit HLG videos for some reason.
jpark37 3 years ago
parent
commit
1a7e5babc2
2 changed files with 30 additions and 2 deletions
  1. 22 0
      libobs/data/format_conversion.effect
  2. 8 2
      libobs/obs-source.c

+ 22 - 0
libobs/data/format_conversion.effect

@@ -485,6 +485,19 @@ float4 PSPlanar420_PQ_Reverse(VertTexPos frag_in) : TARGET
 	return float4(rgb, 1.);
 	return float4(rgb, 1.);
 }
 }
 
 
+float4 PSPlanar420_HLG_Reverse(VertTexPos frag_in) : TARGET
+{
+	float y = image.Load(int3(frag_in.pos.xy, 0)).x;
+	int3 xy0_chroma = int3(frag_in.uv, 0);
+	float cb = image1.Load(xy0_chroma).x;
+	float cr = image2.Load(xy0_chroma).x;
+	float3 yuv = float3(y, cb, cr);
+	float3 hlg = YUV_to_RGB(yuv);
+	float3 hdr2020 = hlg_to_linear(hlg, hlg_exponent) * maximum_over_sdr_white_nits;
+	float3 rgb = rec2020_to_rec709(hdr2020);
+	return float4(rgb, 1.);
+}
+
 float4 PSPlanar420A_Reverse(VertTexPos frag_in) : TARGET
 float4 PSPlanar420A_Reverse(VertTexPos frag_in) : TARGET
 {
 {
 	int3 xy0_luma = int3(frag_in.pos.xy, 0);
 	int3 xy0_luma = int3(frag_in.pos.xy, 0);
@@ -966,6 +979,15 @@ technique I420_PQ_Reverse
 	}
 	}
 }
 }
 
 
+technique I420_HLG_Reverse
+{
+	pass
+	{
+		vertex_shader = VSTexPosHalfHalf_Reverse(id);
+		pixel_shader  = PSPlanar420_HLG_Reverse(frag_in);
+	}
+}
+
 technique I40A_Reverse
 technique I40A_Reverse
 {
 {
 	pass
 	pass

+ 8 - 2
libobs/obs-source.c

@@ -2084,8 +2084,14 @@ static const char *select_conversion_technique(enum video_format format,
 		return "YVYU_Reverse";
 		return "YVYU_Reverse";
 
 
 	case VIDEO_FORMAT_I420:
 	case VIDEO_FORMAT_I420:
-		return (trc == VIDEO_TRC_PQ) ? "I420_PQ_Reverse"
-					     : "I420_Reverse";
+		switch (trc) {
+		case VIDEO_TRC_PQ:
+			return "I420_PQ_Reverse";
+		case VIDEO_TRC_HLG:
+			return "I420_HLG_Reverse";
+		default:
+			return "I420_Reverse";
+		}
 
 
 	case VIDEO_FORMAT_NV12:
 	case VIDEO_FORMAT_NV12:
 		return "NV12_Reverse";
 		return "NV12_Reverse";