Skip to content

Commit

Permalink
Improve sRGB displaying, fix auto compression for sRGB textures
Browse files Browse the repository at this point in the history
  • Loading branch information
iMrShadow committed Oct 11, 2024
1 parent 9e9f7f8 commit e9d5acd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
2 changes: 1 addition & 1 deletion TelltaleTextureTool/TelltaleTextureTool/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public static void ConvertTextureFromOthersToD3Dtx(string sourceFilePath, string
options.IsSRGB = true;
}

texture.TransformTexture(options, true, false);
texture.TransformTexture(options, true, true);

// Get the image
texture.GetDDSInformation(out D3DTXMetadata metadata, out ImageSection[] sections, flags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void ApplyEffects(ImageAdvancedOptions options)
{
try
{
DDSImage.TransformTexture(options, false, true);
DDSImage.TransformTexture(options, true, false);

DDSImage.GetBounds(out uint maxMip, out uint maxFace);
MaxMip = maxMip;
Expand Down
62 changes: 39 additions & 23 deletions TelltaleTextureTool/TelltaleTextureTool/Graphics/TextureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ public byte[] GetSectionPixelData(uint mip, uint face)
{
ScratchImage newDestImage = DirectXTex.CreateScratchImage();

DirectXTex.Decompress(destImage.GetImage(0, 0, 0), (int)DXGIFormat.R8G8B8A8_UNORM, ref newDestImage).ThrowIf();
DirectXTex.Decompress(destImage.GetImage(0, 0, 0), (int)DXGIFormat.UNKNOWN, ref newDestImage).ThrowIf();

destImage.Release();
destImage = newDestImage;
Expand All @@ -509,7 +509,10 @@ public byte[] GetSectionPixelData(uint mip, uint face)
{
ScratchImage newDestImage = DirectXTex.CreateScratchImage();

DirectXTex.Convert(destImage.GetImage(0, 0, 0), (int)DXGIFormat.R8G8B8A8_UNORM, TexFilterFlags.Default, 0.5f, ref newDestImage).ThrowIf();
if (DirectXTex.IsSRGB(destImage.GetMetadata().Format))
DirectXTex.Convert(destImage.GetImage(0, 0, 0), (int)DXGIFormat.R8G8B8A8_UNORM, TexFilterFlags.SrgbOut, 0.5f, ref newDestImage).ThrowIf();
else
DirectXTex.Convert(destImage.GetImage(0, 0, 0), (int)DXGIFormat.R8G8B8A8_UNORM, TexFilterFlags.Default, 0.5f, ref newDestImage).ThrowIf();

destImage.Release();
destImage = newDestImage;
Expand Down Expand Up @@ -577,7 +580,18 @@ public void Compress(DXGIFormat format = DXGIFormat.UNKNOWN)
{
TexMetadata originalMetadata = Image.GetMetadata();

DirectXTex.Compress2(Image.GetImages(), Image.GetImageCount(), ref originalMetadata, (int)format, TexCompressFlags.Default, 0.5f, ref transformedImage).ThrowIf();
TexCompressFlags flags = TexCompressFlags.Default;

if (DirectXTex.IsSRGB(Image.GetMetadata().Format))
{
flags |= TexCompressFlags.SrgbOut;
}

if (DirectXTex.IsSRGB((int)format)){
flags |= TexCompressFlags.SrgbIn;
}

DirectXTex.Compress2(Image.GetImages(), Image.GetImageCount(), ref originalMetadata, (int)format, flags, 0.5f, ref transformedImage).ThrowIf();

Image.Release();
Image = transformedImage;
Expand Down Expand Up @@ -731,7 +745,7 @@ public void TransformTexture(ImageAdvancedOptions options, bool keepOriginal = f
Deswizzle(options.PlatformType);
}

Decompress(DXGIFormat.R8G8B8A8_UNORM);
Decompress();

if (options.EnableNormalMap)
{
Expand Down Expand Up @@ -769,32 +783,35 @@ public void TransformTexture(ImageAdvancedOptions options, bool keepOriginal = f
}
}

if (options.EnableAutomaticCompression)
if (convertingOnly)
{
if (options.EnableNormalMap && options.IsTelltaleXYNormalMap)
{
Compress(DXGIFormat.BC5_UNORM);
}
else if (OriginalImage.IsAlphaAllOpaque())
if (options.EnableAutomaticCompression)
{
if (options.IsSRGB)
if (options.EnableNormalMap && options.IsTelltaleXYNormalMap)
{
Compress(DXGIFormat.BC1_UNORM_SRGB);
Compress(DXGIFormat.BC5_UNORM);
}
else
else if (OriginalImage.IsAlphaAllOpaque())
{
Compress(DXGIFormat.BC1_UNORM);
}
}
else
{
if (options.IsSRGB)
{
Compress(DXGIFormat.BC3_UNORM_SRGB);
if (options.IsSRGB)
{
Compress(DXGIFormat.BC1_UNORM_SRGB);
}
else
{
Compress(DXGIFormat.BC1_UNORM);
}
}
else
{
Compress(DXGIFormat.BC3_UNORM);
if (options.IsSRGB)
{
Compress(DXGIFormat.BC3_UNORM_SRGB);
}
else
{
Compress(DXGIFormat.BC3_UNORM);
}
}
}
}
Expand All @@ -803,7 +820,6 @@ public void TransformTexture(ImageAdvancedOptions options, bool keepOriginal = f
Compress((DXGIFormat)OriginalImage.GetMetadata().Format);
}


if (options.EnableSwizzle && options.IsSwizzle)
{
Swizzle(options.PlatformType);
Expand Down

0 comments on commit e9d5acd

Please sign in to comment.