mpv icon indicating copy to clipboard operation
mpv copied to clipboard

Wrong colors when rendering paletted PNG

Open quilloss opened this issue 11 years ago • 8 comments

mpv renders paletted PNG wrongly when the option vo=opengl:srgb is used.

Sample PNG: basn3p08

mpv output: screenshot

Tested on lachs0r's 2015-01-27 Windows build (git-f6e05b1)

quilloss avatar Jan 27 '15 22:01 quilloss

This is triggered by https://github.com/mpv-player/mpv/blob/master/video/out/gl_video.c#L1720

For some reason GL_SRGB does not play well with paletted PNG files, it seems. No idea what the root cause is. We can safely delete that entire if block if you want, at the expensive of a slight(?) performance loss. I'm not sure if anybody would care. Our scaler already takes care of sRGB companding just fine even without GL_SRGB.

Would also allow us to remove is_linear_rgb completely, which makes the code a bit simpler.

haasn avatar Jan 27 '15 23:01 haasn

Would anyone even notice the difference performance? Not that anyone opens PNGs in mpv in the first place.

quilloss avatar Jan 28 '15 01:01 quilloss

It makes a (meaningful?) difference for RGB video as well. I haven't tested the performance.

haasn avatar Jan 28 '15 01:01 haasn

@haasn: but why is it failing? This makes no sense to me. Unless the is_linear_rgb code path was broken in the meantime.

ghost avatar Jan 28 '15 07:01 ghost

One thing is clear: it's a regression and works with 0.7.2.

I'm not opposed to removing the extra codepath, once we know we know why it fails.

ghost avatar Jan 28 '15 08:01 ghost

OK, it's simple: srgb textures don't touch the alpha channel. But we have the red color component in the alpha channel, which we later move to the red channel. So the red component is broken. (This is done because PNG uses a component order order than RGBA - we fix this in the shader.)

So I guess I'll just remove this code.

ghost avatar Jan 28 '15 12:01 ghost

Actually, it's the blue channel, not red.

ghost avatar Jan 28 '15 12:01 ghost

Done.

Would also allow us to remove is_linear_rgb completely, which makes the code a bit simpler.

It looked like it still has to be there, but maybe I didn't look closely enough when simplifying the code.

ghost avatar Jan 28 '15 12:01 ghost