mirror of
https://github.com/ryujinx-mirror/ryujinx.git
synced 2024-12-23 07:45:45 +00:00
Do not throw for invalid ASTC compressed textures
This commit is contained in:
parent
769c02235f
commit
fd196b3d19
2 changed files with 31 additions and 13 deletions
|
@ -253,7 +253,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||||
|
|
||||||
if (!_context.Capabilities.SupportsAstcCompression && _info.FormatInfo.Format.IsAstc())
|
if (!_context.Capabilities.SupportsAstcCompression && _info.FormatInfo.Format.IsAstc())
|
||||||
{
|
{
|
||||||
data = AstcDecoder.DecodeToRgba8(
|
if (!AstcDecoder.TryDecodeToRgba8(
|
||||||
data,
|
data,
|
||||||
_info.FormatInfo.BlockWidth,
|
_info.FormatInfo.BlockWidth,
|
||||||
_info.FormatInfo.BlockHeight,
|
_info.FormatInfo.BlockHeight,
|
||||||
|
@ -261,7 +261,13 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||||
_info.Width,
|
_info.Width,
|
||||||
_info.Height,
|
_info.Height,
|
||||||
_depth,
|
_depth,
|
||||||
_info.Levels);
|
_info.Levels,
|
||||||
|
out Span<byte> decoded))
|
||||||
|
{
|
||||||
|
// TODO: Error.
|
||||||
|
}
|
||||||
|
|
||||||
|
data = decoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
HostTexture.SetData(data);
|
HostTexture.SetData(data);
|
||||||
|
|
|
@ -47,7 +47,7 @@ namespace Ryujinx.Graphics.Texture.Astc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Span<byte> DecodeToRgba8(
|
public static bool TryDecodeToRgba8(
|
||||||
Span<byte> data,
|
Span<byte> data,
|
||||||
int blockWidth,
|
int blockWidth,
|
||||||
int blockHeight,
|
int blockHeight,
|
||||||
|
@ -55,8 +55,11 @@ namespace Ryujinx.Graphics.Texture.Astc
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
int depth,
|
int depth,
|
||||||
int levels)
|
int levels,
|
||||||
|
out Span<byte> decoded)
|
||||||
{
|
{
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
using (MemoryStream inputStream = new MemoryStream(data.ToArray()))
|
using (MemoryStream inputStream = new MemoryStream(data.ToArray()))
|
||||||
{
|
{
|
||||||
BinaryReader binReader = new BinaryReader(inputStream);
|
BinaryReader binReader = new BinaryReader(inputStream);
|
||||||
|
@ -85,7 +88,14 @@ namespace Ryujinx.Graphics.Texture.Astc
|
||||||
{
|
{
|
||||||
int[] decompressedData = new int[144];
|
int[] decompressedData = new int[144];
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
DecompressBlock(binReader.ReadBytes(0x10), decompressedData, blockWidth, blockHeight);
|
DecompressBlock(binReader.ReadBytes(0x10), decompressedData, blockWidth, blockHeight);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
|
||||||
int decompressedWidth = Math.Min(blockWidth, width - i);
|
int decompressedWidth = Math.Min(blockWidth, width - i);
|
||||||
int decompressedHeight = Math.Min(blockHeight, height - j);
|
int decompressedHeight = Math.Min(blockHeight, height - j);
|
||||||
|
@ -112,9 +122,11 @@ namespace Ryujinx.Graphics.Texture.Astc
|
||||||
height = Math.Max(1, height >> 1);
|
height = Math.Max(1, height >> 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return outputStream.ToArray();
|
decoded = outputStream.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool DecompressBlock(
|
public static bool DecompressBlock(
|
||||||
|
|
Loading…
Reference in a new issue