1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-26 09:02:38 +00:00

vo_opengl: add manual sRGB companding to not artifact when dithering

Patch by nand. Modified not to use macros in the GLSL, and also remove
the checks for framebuffer presence. (Disabling ICC if no sRGB
framebuffer is available was probably a bug.)
This commit is contained in:
nand 2012-11-10 19:08:21 +01:00 committed by wm4
parent c78243c03e
commit ed8fad729d
2 changed files with 11 additions and 14 deletions

View File

@ -698,6 +698,7 @@ static void compile_shaders(struct gl_priv *p)
shader_def_opt(&header_final, "USE_LINEAR_CONV_INV", p->use_lut_3d);
shader_def_opt(&header_final, "USE_GAMMA_POW", p->use_gamma);
shader_def_opt(&header_final, "USE_3DLUT", p->use_lut_3d);
shader_def_opt(&header_final, "USE_SRGB", p->use_srgb);
shader_def_opt(&header_final, "USE_DITHER", p->dither_texture != 0);
if (p->use_scale_sep && p->scalers[0].kernel) {
@ -1122,11 +1123,6 @@ static void do_render(struct gl_priv *p)
float final_texw = p->image_width * source->tex_w / (float)source->vp_w;
float final_texh = p->image_height * source->tex_h / (float)source->vp_h;
bool use_srgb_fb = p->use_srgb && !p->use_lut_3d;
if (use_srgb_fb)
gl->Enable(GL_FRAMEBUFFER_SRGB);
if (p->stereo_mode) {
int w = p->src_rect.x1 - p->src_rect.x0;
int imgw = p->image_width;
@ -1165,9 +1161,6 @@ static void do_render(struct gl_priv *p)
draw_triangles(p, vb, VERTICES_PER_QUAD);
}
if (use_srgb_fb)
gl->Disable(GL_FRAMEBUFFER_SRGB);
gl->UseProgram(0);
debug_check_gl(p, "after video rendering");
@ -1457,8 +1450,7 @@ static void check_gl_features(struct gl_priv *p)
GL *gl = p->gl;
bool have_float_tex = gl->mpgl_caps & MPGL_CAP_FLOAT_TEX;
bool have_fbo = gl->mpgl_caps & MPGL_CAP_FB;
bool have_srgb = (gl->mpgl_caps & MPGL_CAP_SRGB_TEX) &&
(gl->mpgl_caps & MPGL_CAP_SRGB_FB);
bool have_srgb = gl->mpgl_caps & MPGL_CAP_SRGB_TEX;
char *disabled[10];
int n_disabled = 0;
@ -1493,10 +1485,6 @@ static void check_gl_features(struct gl_priv *p)
p->use_lut_3d = false;
disabled[n_disabled++] = "color management (FBO)";
}
if (!have_srgb && p->use_lut_3d) {
p->use_lut_3d = false;
disabled[n_disabled++] = "color management (sRGB)";
}
if (!have_fbo) {
p->use_scale_sep = false;

View File

@ -292,6 +292,12 @@ vec4 sample_sharpen5(sampler2D tex, vec2 texsize, vec2 texcoord) {
return p + t * filter_param1;
}
vec3 srgb_compand(vec3 v)
{
return mix(1.055 * pow(v, vec3(1.0/2.4)) - vec3(0.055), v * 12.92,
lessThanEqual(v, vec3(0.0031308)));
}
void main() {
#ifdef USE_PLANAR
vec3 color = vec3(SAMPLE_L(textures[0], textures_size[0], texcoord).r,
@ -325,6 +331,9 @@ void main() {
#ifdef USE_3DLUT
color = texture3D(lut_3d, color).rgb;
#endif
#ifdef USE_SRGB
color.rgb = srgb_compand(color.rgb);
#endif
#ifdef USE_DITHER
float dither_value = texture(dither, gl_FragCoord.xy / dither_size).r;
color = floor(color * dither_multiply + dither_value ) / dither_quantization;