summaryrefslogtreecommitdiffstats
path: root/video/out/gl_video_shaders.glsl
diff options
context:
space:
mode:
authorNiklas Haas <git@nand.wakku.to>2014-11-26 21:35:08 +0100
committerwm4 <wm4@nowhere>2014-11-26 21:44:36 +0100
commitb5848028138ef6bc2687576b9636b5a2a9c72a6b (patch)
tree8ad132b3b98e45dea4c2a39ed4000356e1fcd51b /video/out/gl_video_shaders.glsl
parentcc5437746312127aed4e4c8e62091707ec61153c (diff)
downloadmpv-b5848028138ef6bc2687576b9636b5a2a9c72a6b.tar.bz2
mpv-b5848028138ef6bc2687576b9636b5a2a9c72a6b.tar.xz
vo_opengl: Linearize non-RGB sRGB files correctly (eg. JPEG)
Signed-off-by: wm4 <wm4@nowhere>
Diffstat (limited to 'video/out/gl_video_shaders.glsl')
-rw-r--r--video/out/gl_video_shaders.glsl16
1 files changed, 16 insertions, 0 deletions
diff --git a/video/out/gl_video_shaders.glsl b/video/out/gl_video_shaders.glsl
index bb6530295f..ff2a019b30 100644
--- a/video/out/gl_video_shaders.glsl
+++ b/video/out/gl_video_shaders.glsl
@@ -43,6 +43,12 @@
// Earlier GLSL doesn't support mix() with bvec
#if __VERSION__ >= 130
+vec3 srgb_expand(vec3 v)
+{
+ return mix(v / 12.92, pow((v + vec3(0.055))/1.055, vec3(2.4)),
+ lessThanEqual(vec3(0.04045), v));
+}
+
vec3 srgb_compand(vec3 v)
{
return mix(v * 12.92, 1.055 * pow(v, vec3(1.0/2.4)) - 0.055,
@@ -98,6 +104,9 @@ void main() {
#ifdef USE_OSD_LINEAR_CONV_BT2020
color.rgb = bt2020_expand(color.rgb);
#endif
+#ifdef USE_OSD_LINEAR_CONV_SRGB
+ color.rgb = srgb_expand(color.rgb);
+#endif
#ifdef USE_OSD_CMS_MATRIX
// Convert to the right target gamut first (to BT.709 for sRGB,
// and to BT.2020 for 3DLUT). Normal clamping here as perceptually
@@ -439,6 +448,13 @@ void main() {
// ... and actual BT.2020 (two-part function)
color = bt2020_expand(color);
#endif
+#ifdef USE_LINEAR_LIGHT_SRGB
+ // This is not needed for most sRGB content since we can use GL_SRGB to
+ // directly sample RGB texture in linear light, but for things which are
+ // also sRGB but in a different format (such as JPEG's YUV), we need
+ // to convert to linear light manually.
+ color = srgb_expand(color);
+#endif
#ifdef USE_CONST_LUMA
// Calculate the green channel from the expanded RYcB
// The BT.2020 specification says Yc = 0.2627*R + 0.6780*G + 0.0593*B