aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Texture
diff options
context:
space:
mode:
authorgdk <gab.dark.100@gmail.com>2019-11-08 21:55:53 -0300
committerThog <thog@protonmail.com>2020-01-09 02:13:00 +0100
commitfd196b3d19aa58e830376c93be40575463744aa2 (patch)
treed4e56927ce50dc4e24a6725d1f9caead74c8bea9 /Ryujinx.Graphics.Texture
parent769c02235f489f02b1791e6e76dc8b3ab18028ee (diff)
Do not throw for invalid ASTC compressed textures
Diffstat (limited to 'Ryujinx.Graphics.Texture')
-rw-r--r--Ryujinx.Graphics.Texture/Astc/AstcDecoder.cs34
1 files changed, 23 insertions, 11 deletions
diff --git a/Ryujinx.Graphics.Texture/Astc/AstcDecoder.cs b/Ryujinx.Graphics.Texture/Astc/AstcDecoder.cs
index 0b8172f7..41db7e05 100644
--- a/Ryujinx.Graphics.Texture/Astc/AstcDecoder.cs
+++ b/Ryujinx.Graphics.Texture/Astc/AstcDecoder.cs
@@ -47,16 +47,19 @@ namespace Ryujinx.Graphics.Texture.Astc
}
}
- public static Span<byte> DecodeToRgba8(
- Span<byte> data,
- int blockWidth,
- int blockHeight,
- int blockDepth,
- int width,
- int height,
- int depth,
- int levels)
+ public static bool TryDecodeToRgba8(
+ Span<byte> data,
+ int blockWidth,
+ int blockHeight,
+ int blockDepth,
+ int width,
+ int height,
+ int depth,
+ int levels,
+ out Span<byte> decoded)
{
+ bool success = true;
+
using (MemoryStream inputStream = new MemoryStream(data.ToArray()))
{
BinaryReader binReader = new BinaryReader(inputStream);
@@ -85,7 +88,14 @@ namespace Ryujinx.Graphics.Texture.Astc
{
int[] decompressedData = new int[144];
- DecompressBlock(binReader.ReadBytes(0x10), decompressedData, blockWidth, blockHeight);
+ try
+ {
+ DecompressBlock(binReader.ReadBytes(0x10), decompressedData, blockWidth, blockHeight);
+ }
+ catch (Exception)
+ {
+ success = false;
+ }
int decompressedWidth = Math.Min(blockWidth, width - i);
int decompressedHeight = Math.Min(blockHeight, height - j);
@@ -112,9 +122,11 @@ namespace Ryujinx.Graphics.Texture.Astc
height = Math.Max(1, height >> 1);
}
- return outputStream.ToArray();
+ decoded = outputStream.ToArray();
}
}
+
+ return success;
}
public static bool DecompressBlock(