Using force SRGB with TGA and when targeting compressed formats

Jan 15, 2014 at 5:45 PM
Edited Jan 15, 2014 at 5:46 PM
Hello. I've noticed a couple issues with texconv.

I'm trying to use texconv in an asset conversion pipeline which uses TGA as a source format. They weren't saved with any kind of metadata indicating which textures are sRGB and which are not, but we can make educated guesses. However, texconv does not appear to handle the -srgbi flag when reading a TGA. It works (kind of; more on that later) when reading via a WIC or DDS format, but not with TGA. I've stepped through the code and it looks like the TGA reader simply doesn't handle forceSRGB.

In the meantime I can do this:
> texconv diffuse_map.tga
reading diffuse_map.tga (512x512 R8G8B8A8_UNORM 2D) as (512x512,11 R8G8B8A8_UNORM 2D)
writing diffuse_map.DDS
> texconv -srgbi -f R8G8B8A8_UNORM_SRGB diffuse_map.DDS
reading diffuse_map.DDS (512x512,11 R8G8B8A8_UNORM 2D) as (512x512,11 R8G8B8A8_UNORM_SRGB 2D)
writing diffuse_map.DDS
But it's a bit of a go-around and it seems the behaviour is not obeying the command line parameter.

On this note I've noticed an issue when converting to compressed format. My actual intent is to encode as BC7_UNORM_SRGB but I instead use R8G8B8A8_UNORM_SRGB instead because if I specify a compressed texture, it again fails to recognize the -srgbi parameter. The goal is to avoid scanline conversion from linear -> srgb since I am trying to tell texconv that the data is already in sRGB space.

If I do this instead:
> texconv diffuse_map.tga
reading diffuse_map.tga (512x512 R8G8B8A8_UNORM 2D) as (512x512,11 R8G8B8A8_UNORM 2D)
writing diffuse_map.DDS
> texconv -srgbi -f BC7_UNORM_SRGB diffuse_map.DDS
reading diffuse_map.DDS (512x512,11 R8G8B8A8_UNORM 2D) as
[Using DirectCompute on "Intel(R) HD Graphics 4000"]
 (512x512,11 BC7_UNORM_SRGB 2D)
writing diffuse_map.DDS
It still performs scanline conversion, so I must do it in 3 steps: first from TGA to R8G8B8A8_UNORM DDS (texconv sees linear->linear; no conversion). Then from R8G8B8A8_UNORM DDS with -srgbi to R8G8B8A8_UNORM_SRGB DDS (texconv sees forceSRGB on input and an sRGB output; no conversion). Then finally from R8G8B8A8_UNORM_SRGB DDS to BC7_UNORM_SRGB DDS (texconv sees sRGB input and output; no conversion). Only in this way can I get an image which I know is in sRGB space but otherwise lacks the metadata to prove it, to a BC7_UNORM_SRGB without having the data manipulated.
Jan 15, 2014 at 6:50 PM
The following is a no-op under the current logic because there's no format conversion taking place (which is where the sRGB conversion is applied). This just writes out a DDS with the same format as the .tga which isn't _SRGB. This is true of .TGA, WIC formats, and .DDS.
texconv -srgbi diffuse_map.tga
To actually do this operation, you need to use -f to force a conversion which works correctly for TGA, WIC formats, and .DDS
texconv -srgbi -f R8G8B8A8_UNORM_SRGB diffuse_map.tga
The problem you are running into is that Compress is not given the -srgbi/srgbo flags as input. It isn't specific to TGA as it appears to do the same RGB -> sRGB conversion for your DDS -srgbi case as well as the .tga case.
Jan 15, 2014 at 6:52 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Jan 15, 2014 at 9:12 PM
Ah, I see. If I use -srgbi -f R8G8B8A8_UNORM_SRGB on the TGA then the result is as expected. Thanks you for clearing that up.
Jan 24, 2014 at 9:16 PM
This has been fixed in the January 2014 release
Marked as answer by walbourn on 1/24/2014 at 2:16 PM