I used the DirectXTex
library to capture a screenshot of a DX11 game and save it to a file. The problem is that it works great when I save it as jpeg but if I save it as png the image would become super bright and washed out. I checked the image using TweakPNG
and found out the gamma was set to 1.0 and that's what's causing the problem.
I checked images taken by some other software including the snipping tool and they seem to use 0.45455 as gamma or they leave out the gamma value altogether.
I don't know if DirectXTex
will let me specify a gamma value or not. I'm not even sure if WIC
has this functionality as I can't seem to find useful information either on MSDN or other sites.
By default DirectXTex will add the sRGB
chunk to the PNG
file it writes if the format is DXGI_FORMAT_*_SRGB
. Furthermore, if the format is not DXGI_FORMAT_*_SRGB
I explicitly remove the sRGB
chunk and set the gAMA
chunk to 1.0 because otherwise WIC always adds the sRGB
chunk.
You can see this behavior in the code in both DirectXTexWIC.cpp and in the DirectX Tool Kit's ScreenGrab.cpp module.
If you are not doing 'gamma-correct' rendering where your render target is an DXGI_FORMAT_*_SRGB
format but have sRGB content in a DXGI_FORMAT_*
format, then my recommendation is that you pass an sRGB version of the format to the function.
In DirectXTex, that's easily done with the MakeSRGB
function.
Gamma correction in the PNG format is a bit of a mess. See this blog post