diff --git a/AssetStudio/Classes/Mesh.cs b/AssetStudio/Classes/Mesh.cs index d429958..1eeb046 100644 --- a/AssetStudio/Classes/Mesh.cs +++ b/AssetStudio/Classes/Mesh.cs @@ -1,4 +1,5 @@ using System; +using System.Buffers.Binary; using System.Collections; using System.Collections.Generic; using System.IO; @@ -808,7 +809,8 @@ namespace AssetStudio for (var d = 0; d < m_Channel.dimension; d++) { var componentOffset = vertexOffset + componentByteSize * d; - Buffer.BlockCopy(m_VertexData.m_DataSize, componentOffset, componentBytes, componentByteSize * (v * m_Channel.dimension + d), componentByteSize); + var dstOffset = componentByteSize * (v * m_Channel.dimension + d); + m_VertexData.m_DataSize.AsSpan(componentOffset, componentByteSize).CopyTo(componentBytes.AsSpan(dstOffset)); } } @@ -816,10 +818,7 @@ namespace AssetStudio { for (var i = 0; i < componentBytes.Length / componentByteSize; i++) { - var buff = new byte[componentByteSize]; - Buffer.BlockCopy(componentBytes, i * componentByteSize, buff, 0, componentByteSize); - buff = buff.Reverse().ToArray(); - Buffer.BlockCopy(buff, 0, componentBytes, i * componentByteSize, componentByteSize); + componentBytes.AsSpan(i * componentByteSize, componentByteSize).Reverse(); } } @@ -897,6 +896,9 @@ namespace AssetStudio } } break; + default: + Logger.Warning($"Unknown vertex attribute: {chn}"); + break; } } else @@ -934,6 +936,9 @@ namespace AssetStudio case 7: //kShaderChannelTangent m_Tangents = componentsFloatArray; break; + default: + Logger.Warning($"Unknown vertex attribute: {chn}"); + break; } } } @@ -990,11 +995,9 @@ namespace AssetStudio { m_BindPose = new Matrix4x4[m_CompressedMesh.m_BindPoses.m_NumItems / 16]; var m_BindPoses_Unpacked = m_CompressedMesh.m_BindPoses.UnpackFloats(16, 4 * 16); - var buffer = new float[16]; for (var i = 0; i < m_BindPose.Length; i++) { - Array.Copy(m_BindPoses_Unpacked, i * 16, buffer, 0, 16); - m_BindPose[i] = new Matrix4x4(buffer); + m_BindPose[i] = new Matrix4x4(m_BindPoses_Unpacked.AsSpan(i * 16, 16)); } } } @@ -1415,7 +1418,11 @@ namespace AssetStudio switch (format) { case VertexFormat.Float: +#if NET + result[i] = BinaryPrimitives.ReadSingleLittleEndian(inputBytes.AsSpan(i * 4)); +#else result[i] = BitConverter.ToSingle(inputBytes, i * 4); +#endif break; case VertexFormat.Float16: result[i] = (float)HalfHelper.ToHalf(inputBytes, i * 2); @@ -1427,17 +1434,17 @@ namespace AssetStudio result[i] = Math.Max((sbyte)inputBytes[i] / 127f, -1f); break; case VertexFormat.UNorm16: - result[i] = BitConverter.ToUInt16(inputBytes, i * 2) / 65535f; + result[i] = BinaryPrimitives.ReadUInt16LittleEndian(inputBytes.AsSpan(i * 2)) / 65535f; break; case VertexFormat.SNorm16: - result[i] = Math.Max(BitConverter.ToInt16(inputBytes, i * 2) / 32767f, -1f); + result[i] = Math.Max(BinaryPrimitives.ReadInt16LittleEndian(inputBytes.AsSpan(i * 2)) / 32767f, -1f); break; } } return result; } - public static int[] BytesToIntArray(byte[] inputBytes, VertexFormat format) + public static int[] BytesToIntArray(ReadOnlySpan inputBytes, VertexFormat format) { var size = GetFormatSize(format); var len = inputBytes.Length / size; @@ -1451,12 +1458,16 @@ namespace AssetStudio result[i] = inputBytes[i]; break; case VertexFormat.UInt16: + result[i] = BinaryPrimitives.ReadUInt16LittleEndian(inputBytes.Slice(i * 2)); + break; case VertexFormat.SInt16: - result[i] = BitConverter.ToInt16(inputBytes, i * 2); + result[i] = BinaryPrimitives.ReadInt16LittleEndian(inputBytes.Slice(i * 2)); break; case VertexFormat.UInt32: + result[i] = (int)BinaryPrimitives.ReadUInt32LittleEndian(inputBytes.Slice(i * 4)); + break; case VertexFormat.SInt32: - result[i] = BitConverter.ToInt32(inputBytes, i * 4); + result[i] = BinaryPrimitives.ReadInt32LittleEndian(inputBytes.Slice(i * 4)); break; } } diff --git a/AssetStudio/EndianBinaryReader.cs b/AssetStudio/EndianBinaryReader.cs index 12097d2..d66c32c 100644 --- a/AssetStudio/EndianBinaryReader.cs +++ b/AssetStudio/EndianBinaryReader.cs @@ -88,7 +88,7 @@ namespace AssetStudio if (Endian == EndianType.BigEndian) { Read(buffer, 0, 4); - Array.Reverse(buffer, 0, 4); + buffer.AsSpan(0, 4).Reverse(); return BitConverter.ToSingle(buffer, 0); } return base.ReadSingle(); @@ -99,7 +99,7 @@ namespace AssetStudio if (Endian == EndianType.BigEndian) { Read(buffer, 0, 8); - Array.Reverse(buffer); + buffer.AsSpan().Reverse(); return BitConverter.ToDouble(buffer, 0); } return base.ReadDouble(); diff --git a/AssetStudio/Math/Matrix4x4.cs b/AssetStudio/Math/Matrix4x4.cs index 429afc7..5d2e99d 100644 --- a/AssetStudio/Math/Matrix4x4.cs +++ b/AssetStudio/Math/Matrix4x4.cs @@ -26,9 +26,9 @@ namespace AssetStudio public float M23; public float M33; - public Matrix4x4(float[] values) + public Matrix4x4(Span values) { - if (values == null) + if (values.IsEmpty) throw new ArgumentNullException(nameof(values)); if (values.Length != 16) throw new ArgumentOutOfRangeException(nameof(values), "There must be sixteen and only sixteen input values for Matrix."); diff --git a/AssetStudioUtility/Texture2DConverter.cs b/AssetStudioUtility/Texture2DConverter.cs index 34675f5..a076b47 100644 --- a/AssetStudioUtility/Texture2DConverter.cs +++ b/AssetStudioUtility/Texture2DConverter.cs @@ -1,4 +1,5 @@ using System; +using System.Buffers.Binary; using System.Runtime.CompilerServices; using Texture2DDecoder; @@ -289,22 +290,21 @@ namespace AssetStudio return flag; } - private void SwapBytesForXbox(byte[] image_data) + private void SwapBytesForXbox(Span image_data) { if (platform == BuildTarget.XBOX360) { for (var i = 0; i < reader.Size / 2; i++) { - (image_data[i * 2 + 1], image_data[i * 2]) = (image_data[i * 2], image_data[i * 2 + 1]); + image_data.Slice(i * 2, 2).Reverse(); } } } - private bool DecodeAlpha8(byte[] image_data, byte[] buff) + private bool DecodeAlpha8(ReadOnlySpan image_data, Span buff) { var size = m_Width * m_Height; - var span = new Span(buff); - span.Fill(0xFF); + buff.Fill(0xFF); for (var i = 0; i < size; i++) { buff[i * 4 + 3] = image_data[i]; @@ -312,25 +312,25 @@ namespace AssetStudio return true; } - private bool DecodeARGB4444(byte[] image_data, byte[] buff) + private bool DecodeARGB4444(ReadOnlySpan image_data, Span buff) { var size = m_Width * m_Height; - var pixelNew = new byte[4]; + var pixelNew = new byte[4].AsSpan(); for (var i = 0; i < size; i++) { - var pixelOldShort = BitConverter.ToUInt16(image_data, i * 2); + var pixelOldShort = BinaryPrimitives.ReadUInt16LittleEndian(image_data.Slice(i * 2)); pixelNew[0] = (byte)(pixelOldShort & 0x000f); pixelNew[1] = (byte)((pixelOldShort & 0x00f0) >> 4); pixelNew[2] = (byte)((pixelOldShort & 0x0f00) >> 8); pixelNew[3] = (byte)((pixelOldShort & 0xf000) >> 12); for (var j = 0; j < 4; j++) pixelNew[j] = (byte)((pixelNew[j] << 4) | pixelNew[j]); - pixelNew.CopyTo(buff, i * 4); + pixelNew.CopyTo(buff.Slice(i * 4)); } return true; } - private bool DecodeRGB24(byte[] image_data, byte[] buff) + private bool DecodeRGB24(ReadOnlySpan image_data, Span buff) { var size = m_Width * m_Height; for (var i = 0; i < size; i++) @@ -343,7 +343,7 @@ namespace AssetStudio return true; } - private bool DecodeRGBA32(byte[] image_data, byte[] buff) + private bool DecodeRGBA32(ReadOnlySpan image_data, Span buff) { for (var i = 0; i < outPutDataSize; i += 4) { @@ -355,7 +355,7 @@ namespace AssetStudio return true; } - private bool DecodeARGB32(byte[] image_data, byte[] buff) + private bool DecodeARGB32(ReadOnlySpan image_data, Span buff) { for (var i = 0; i < outPutDataSize; i += 4) { @@ -367,12 +367,12 @@ namespace AssetStudio return true; } - private bool DecodeRGB565(byte[] image_data, byte[] buff) + private bool DecodeRGB565(ReadOnlySpan image_data, Span buff) { var size = m_Width * m_Height; for (var i = 0; i < size; i++) { - var p = BitConverter.ToUInt16(image_data, i * 2); + var p = BinaryPrimitives.ReadUInt16LittleEndian(image_data.Slice(i * 2)); buff[i * 4] = (byte)((p << 3) | (p >> 2 & 7)); buff[i * 4 + 1] = (byte)((p >> 3 & 0xfc) | (p >> 9 & 3)); buff[i * 4 + 2] = (byte)((p >> 8 & 0xf8) | (p >> 13)); @@ -381,48 +381,48 @@ namespace AssetStudio return true; } - private bool DecodeR16(byte[] image_data, byte[] buff) + private bool DecodeR16(ReadOnlySpan image_data, Span buff) { var size = m_Width * m_Height; for (var i = 0; i < size; i++) { buff[i * 4] = 0; //b buff[i * 4 + 1] = 0; //g - buff[i * 4 + 2] = DownScaleFrom16BitTo8Bit(BitConverter.ToUInt16(image_data, i * 2)); //r + buff[i * 4 + 2] = DownScaleFrom16BitTo8Bit(BinaryPrimitives.ReadUInt16LittleEndian(image_data.Slice(i * 2))); //r buff[i * 4 + 3] = 255; //a } return true; } - private bool DecodeDXT1(byte[] image_data, byte[] buff) + private bool DecodeDXT1(ReadOnlySpan image_data, Span buff) { return TextureDecoder.DecodeDXT1(image_data, m_Width, m_Height, buff); } - private bool DecodeDXT5(byte[] image_data, byte[] buff) + private bool DecodeDXT5(ReadOnlySpan image_data, Span buff) { return TextureDecoder.DecodeDXT5(image_data, m_Width, m_Height, buff); } - private bool DecodeRGBA4444(byte[] image_data, byte[] buff) + private bool DecodeRGBA4444(ReadOnlySpan image_data, Span buff) { var size = m_Width * m_Height; - var pixelNew = new byte[4]; + var pixelNew = new byte[4].AsSpan(); for (var i = 0; i < size; i++) { - var pixelOldShort = BitConverter.ToUInt16(image_data, i * 2); + var pixelOldShort = BinaryPrimitives.ReadUInt16LittleEndian(image_data.Slice(i * 2)); pixelNew[0] = (byte)((pixelOldShort & 0x00f0) >> 4); pixelNew[1] = (byte)((pixelOldShort & 0x0f00) >> 8); pixelNew[2] = (byte)((pixelOldShort & 0xf000) >> 12); pixelNew[3] = (byte)(pixelOldShort & 0x000f); for (var j = 0; j < 4; j++) pixelNew[j] = (byte)((pixelNew[j] << 4) | pixelNew[j]); - pixelNew.CopyTo(buff, i * 4); + pixelNew.CopyTo(buff.Slice(i * 4)); } return true; } - private bool DecodeBGRA32(byte[] image_data, byte[] buff) + private bool DecodeBGRA32(ReadOnlySpan image_data, Span buff) { for (var i = 0; i < outPutDataSize; i += 4) { @@ -434,7 +434,7 @@ namespace AssetStudio return true; } - private bool DecodeRHalf(byte[] image_data, byte[] buff) + private bool DecodeRHalf(ReadOnlySpan image_data, Span buff) { for (var i = 0; i < outPutDataSize; i += 4) { @@ -446,7 +446,7 @@ namespace AssetStudio return true; } - private bool DecodeRGHalf(byte[] image_data, byte[] buff) + private bool DecodeRGHalf(ReadOnlySpan image_data, Span buff) { for (var i = 0; i < outPutDataSize; i += 4) { @@ -458,7 +458,7 @@ namespace AssetStudio return true; } - private bool DecodeRGBAHalf(byte[] image_data, byte[] buff) + private bool DecodeRGBAHalf(ReadOnlySpan image_data, Span buff) { for (var i = 0; i < outPutDataSize; i += 4) { @@ -470,7 +470,7 @@ namespace AssetStudio return true; } - private bool DecodeRFloat(byte[] image_data, byte[] buff) + private bool DecodeRFloat(byte[] image_data, Span buff) { for (var i = 0; i < outPutDataSize; i += 4) { @@ -482,7 +482,7 @@ namespace AssetStudio return true; } - private bool DecodeRGFloat(byte[] image_data, byte[] buff) + private bool DecodeRGFloat(byte[] image_data, Span buff) { for (var i = 0; i < outPutDataSize; i += 4) { @@ -494,7 +494,7 @@ namespace AssetStudio return true; } - private bool DecodeRGBAFloat(byte[] image_data, byte[] buff) + private bool DecodeRGBAFloat(byte[] image_data, Span buff) { for (var i = 0; i < outPutDataSize; i += 4) { @@ -512,7 +512,7 @@ namespace AssetStudio return (byte)(byte.MaxValue < x ? byte.MaxValue : (x > byte.MinValue ? x : byte.MinValue)); } - private bool DecodeYUY2(byte[] image_data, byte[] buff) + private bool DecodeYUY2(ReadOnlySpan image_data, Span buff) { int p = 0; int o = 0; @@ -542,11 +542,11 @@ namespace AssetStudio return true; } - private bool DecodeRGB9e5Float(byte[] image_data, byte[] buff) + private bool DecodeRGB9e5Float(ReadOnlySpan image_data, Span buff) { for (var i = 0; i < outPutDataSize; i += 4) { - var n = BitConverter.ToInt32(image_data, i); + var n = BinaryPrimitives.ReadInt32LittleEndian(image_data.Slice(i)); var scale = n >> 27 & 0x1f; var scalef = MathF.Pow(2, scale - 24); var b = n >> 18 & 0x1ff; @@ -560,27 +560,27 @@ namespace AssetStudio return true; } - private bool DecodeBC4(byte[] image_data, byte[] buff) + private bool DecodeBC4(ReadOnlySpan image_data, Span buff) { return TextureDecoder.DecodeBC4(image_data, m_Width, m_Height, buff); } - private bool DecodeBC5(byte[] image_data, byte[] buff) + private bool DecodeBC5(ReadOnlySpan image_data, Span buff) { return TextureDecoder.DecodeBC5(image_data, m_Width, m_Height, buff); } - private bool DecodeBC6H(byte[] image_data, byte[] buff) + private bool DecodeBC6H(ReadOnlySpan image_data, Span buff) { return TextureDecoder.DecodeBC6(image_data, m_Width, m_Height, buff); } - private bool DecodeBC7(byte[] image_data, byte[] buff) + private bool DecodeBC7(ReadOnlySpan image_data, Span buff) { return TextureDecoder.DecodeBC7(image_data, m_Width, m_Height, buff); } - private bool DecodeDXT1Crunched(byte[] image_data, byte[] buff) + private bool DecodeDXT1Crunched(ReadOnlySpan image_data, Span buff) { if (UnpackCrunch(image_data, out var result)) { @@ -592,7 +592,7 @@ namespace AssetStudio return false; } - private bool DecodeDXT5Crunched(byte[] image_data, byte[] buff) + private bool DecodeDXT5Crunched(ReadOnlySpan image_data, Span buff) { if (UnpackCrunch(image_data, out var result)) { @@ -604,67 +604,67 @@ namespace AssetStudio return false; } - private bool DecodePVRTC(byte[] image_data, byte[] buff, bool is2bpp) + private bool DecodePVRTC(ReadOnlySpan image_data, Span buff, bool is2bpp) { return TextureDecoder.DecodePVRTC(image_data, m_Width, m_Height, buff, is2bpp); } - private bool DecodeETC1(byte[] image_data, byte[] buff) + private bool DecodeETC1(ReadOnlySpan image_data, Span buff) { return TextureDecoder.DecodeETC1(image_data, m_Width, m_Height, buff); } - private bool DecodeATCRGB4(byte[] image_data, byte[] buff) + private bool DecodeATCRGB4(ReadOnlySpan image_data, Span buff) { return TextureDecoder.DecodeATCRGB4(image_data, m_Width, m_Height, buff); } - private bool DecodeATCRGBA8(byte[] image_data, byte[] buff) + private bool DecodeATCRGBA8(ReadOnlySpan image_data, Span buff) { return TextureDecoder.DecodeATCRGBA8(image_data, m_Width, m_Height, buff); } - private bool DecodeEACR(byte[] image_data, byte[] buff) + private bool DecodeEACR(ReadOnlySpan image_data, Span buff) { return TextureDecoder.DecodeEACR(image_data, m_Width, m_Height, buff); } - private bool DecodeEACRSigned(byte[] image_data, byte[] buff) + private bool DecodeEACRSigned(ReadOnlySpan image_data, Span buff) { return TextureDecoder.DecodeEACRSigned(image_data, m_Width, m_Height, buff); } - private bool DecodeEACRG(byte[] image_data, byte[] buff) + private bool DecodeEACRG(ReadOnlySpan image_data, Span buff) { return TextureDecoder.DecodeEACRG(image_data, m_Width, m_Height, buff); } - private bool DecodeEACRGSigned(byte[] image_data, byte[] buff) + private bool DecodeEACRGSigned(ReadOnlySpan image_data, Span buff) { return TextureDecoder.DecodeEACRGSigned(image_data, m_Width, m_Height, buff); } - private bool DecodeETC2(byte[] image_data, byte[] buff) + private bool DecodeETC2(ReadOnlySpan image_data, Span buff) { return TextureDecoder.DecodeETC2(image_data, m_Width, m_Height, buff); } - private bool DecodeETC2A1(byte[] image_data, byte[] buff) + private bool DecodeETC2A1(ReadOnlySpan image_data, Span buff) { return TextureDecoder.DecodeETC2A1(image_data, m_Width, m_Height, buff); } - private bool DecodeETC2A8(byte[] image_data, byte[] buff) + private bool DecodeETC2A8(ReadOnlySpan image_data, Span buff) { return TextureDecoder.DecodeETC2A8(image_data, m_Width, m_Height, buff); } - private bool DecodeASTC(byte[] image_data, byte[] buff, int blocksize) + private bool DecodeASTC(ReadOnlySpan image_data, Span buff, int blocksize) { return TextureDecoder.DecodeASTC(image_data, m_Width, m_Height, blocksize, blocksize, buff); } - private bool DecodeRG16(byte[] image_data, byte[] buff) + private bool DecodeRG16(ReadOnlySpan image_data, Span buff) { var size = m_Width * m_Height; for (var i = 0; i < size; i++) @@ -677,7 +677,7 @@ namespace AssetStudio return true; } - private bool DecodeR8(byte[] image_data, byte[] buff) + private bool DecodeR8(ReadOnlySpan image_data, Span buff) { var size = m_Width * m_Height; for (var i = 0; i < size; i++) @@ -690,7 +690,7 @@ namespace AssetStudio return true; } - private bool DecodeETC1Crunched(byte[] image_data, byte[] buff) + private bool DecodeETC1Crunched(ReadOnlySpan image_data, Span buff) { if (UnpackCrunch(image_data, out var result)) { @@ -702,7 +702,7 @@ namespace AssetStudio return false; } - private bool DecodeETC2A8Crunched(byte[] image_data, byte[] buff) + private bool DecodeETC2A8Crunched(ReadOnlySpan image_data, Span buff) { if (UnpackCrunch(image_data, out var result)) { @@ -720,44 +720,44 @@ namespace AssetStudio return (byte)(((component * 255) + 32895) >> 16); } - private bool DecodeRG32(byte[] image_data, byte[] buff) + private bool DecodeRG32(ReadOnlySpan image_data, Span buff) { for (var i = 0; i < outPutDataSize; i += 4) { buff[i] = 0; //b - buff[i + 1] = DownScaleFrom16BitTo8Bit(BitConverter.ToUInt16(image_data, i + 2)); //g - buff[i + 2] = DownScaleFrom16BitTo8Bit(BitConverter.ToUInt16(image_data, i)); //r + buff[i + 1] = DownScaleFrom16BitTo8Bit(BinaryPrimitives.ReadUInt16LittleEndian(image_data.Slice(i + 2))); //g + buff[i + 2] = DownScaleFrom16BitTo8Bit(BinaryPrimitives.ReadUInt16LittleEndian(image_data.Slice(i))); //r buff[i + 3] = byte.MaxValue; //a } return true; } - private bool DecodeRGB48(byte[] image_data, byte[] buff) + private bool DecodeRGB48(ReadOnlySpan image_data, Span buff) { var size = m_Width * m_Height; for (var i = 0; i < size; i++) { - buff[i * 4] = DownScaleFrom16BitTo8Bit(BitConverter.ToUInt16(image_data, i * 6 + 4)); //b - buff[i * 4 + 1] = DownScaleFrom16BitTo8Bit(BitConverter.ToUInt16(image_data, i * 6 + 2)); //g - buff[i * 4 + 2] = DownScaleFrom16BitTo8Bit(BitConverter.ToUInt16(image_data, i * 6)); //r + buff[i * 4] = DownScaleFrom16BitTo8Bit(BinaryPrimitives.ReadUInt16LittleEndian(image_data.Slice(i * 6 + 4))); //b + buff[i * 4 + 1] = DownScaleFrom16BitTo8Bit(BinaryPrimitives.ReadUInt16LittleEndian(image_data.Slice(i * 6 + 2))); //g + buff[i * 4 + 2] = DownScaleFrom16BitTo8Bit(BinaryPrimitives.ReadUInt16LittleEndian(image_data.Slice(i * 6))); //r buff[i * 4 + 3] = byte.MaxValue; //a } return true; } - private bool DecodeRGBA64(byte[] image_data, byte[] buff) + private bool DecodeRGBA64(ReadOnlySpan image_data, Span buff) { for (var i = 0; i < outPutDataSize; i += 4) { - buff[i] = DownScaleFrom16BitTo8Bit(BitConverter.ToUInt16(image_data, i * 2 + 4)); //b - buff[i + 1] = DownScaleFrom16BitTo8Bit(BitConverter.ToUInt16(image_data, i * 2 + 2)); //g - buff[i + 2] = DownScaleFrom16BitTo8Bit(BitConverter.ToUInt16(image_data, i * 2)); //r - buff[i + 3] = DownScaleFrom16BitTo8Bit(BitConverter.ToUInt16(image_data, i * 2 + 6)); //a + buff[i] = DownScaleFrom16BitTo8Bit(BinaryPrimitives.ReadUInt16LittleEndian(image_data.Slice(i * 2 + 4))); //b + buff[i + 1] = DownScaleFrom16BitTo8Bit(BinaryPrimitives.ReadUInt16LittleEndian(image_data.Slice(i * 2 + 2))); //g + buff[i + 2] = DownScaleFrom16BitTo8Bit(BinaryPrimitives.ReadUInt16LittleEndian(image_data.Slice(i * 2))); //r + buff[i + 3] = DownScaleFrom16BitTo8Bit(BinaryPrimitives.ReadUInt16LittleEndian(image_data.Slice(i * 2 + 6))); //a } return true; } - private bool UnpackCrunch(byte[] image_data, out byte[] result) + private bool UnpackCrunch(ReadOnlySpan image_data, out ReadOnlySpan result) { if (version >= (2017, 3) //2017.3 and up || m_TextureFormat == TextureFormat.ETC_RGB4Crunched @@ -769,11 +769,7 @@ namespace AssetStudio { result = TextureDecoder.UnpackCrunch(image_data); } - if (result != null) - { - return true; - } - return false; + return !result.IsEmpty; } } } diff --git a/Texture2DDecoderWrapper/Texture2DDecoderWrapper.csproj b/Texture2DDecoderWrapper/Texture2DDecoderWrapper.csproj index e50c51d..2afff6d 100644 --- a/Texture2DDecoderWrapper/Texture2DDecoderWrapper.csproj +++ b/Texture2DDecoderWrapper/Texture2DDecoderWrapper.csproj @@ -8,6 +8,10 @@ embedded + + + + diff --git a/Texture2DDecoderWrapper/TextureDecoder.cs b/Texture2DDecoderWrapper/TextureDecoder.cs index a3bcad2..4318fb7 100644 --- a/Texture2DDecoderWrapper/TextureDecoder.cs +++ b/Texture2DDecoderWrapper/TextureDecoder.cs @@ -16,7 +16,7 @@ namespace Texture2DDecoder } #endif - public static bool DecodeDXT1(byte[] data, int width, int height, byte[] image) + public static bool DecodeDXT1(ReadOnlySpan data, int width, int height, Span image) { fixed (byte* pData = data) { @@ -27,7 +27,7 @@ namespace Texture2DDecoder } } - public static bool DecodeDXT5(byte[] data, int width, int height, byte[] image) + public static bool DecodeDXT5(ReadOnlySpan data, int width, int height, Span image) { fixed (byte* pData = data) { @@ -38,7 +38,7 @@ namespace Texture2DDecoder } } - public static bool DecodePVRTC(byte[] data, int width, int height, byte[] image, bool is2bpp) + public static bool DecodePVRTC(ReadOnlySpan data, int width, int height, Span image, bool is2bpp) { fixed (byte* pData = data) { @@ -49,7 +49,7 @@ namespace Texture2DDecoder } } - public static bool DecodeETC1(byte[] data, int width, int height, byte[] image) + public static bool DecodeETC1(ReadOnlySpan data, int width, int height, Span image) { fixed (byte* pData = data) { @@ -60,7 +60,7 @@ namespace Texture2DDecoder } } - public static bool DecodeETC2(byte[] data, int width, int height, byte[] image) + public static bool DecodeETC2(ReadOnlySpan data, int width, int height, Span image) { fixed (byte* pData = data) { @@ -71,7 +71,7 @@ namespace Texture2DDecoder } } - public static bool DecodeETC2A1(byte[] data, int width, int height, byte[] image) + public static bool DecodeETC2A1(ReadOnlySpan data, int width, int height, Span image) { fixed (byte* pData = data) { @@ -82,7 +82,7 @@ namespace Texture2DDecoder } } - public static bool DecodeETC2A8(byte[] data, int width, int height, byte[] image) + public static bool DecodeETC2A8(ReadOnlySpan data, int width, int height, Span image) { fixed (byte* pData = data) { @@ -93,7 +93,7 @@ namespace Texture2DDecoder } } - public static bool DecodeEACR(byte[] data, int width, int height, byte[] image) + public static bool DecodeEACR(ReadOnlySpan data, int width, int height, Span image) { fixed (byte* pData = data) { @@ -104,7 +104,7 @@ namespace Texture2DDecoder } } - public static bool DecodeEACRSigned(byte[] data, int width, int height, byte[] image) + public static bool DecodeEACRSigned(ReadOnlySpan data, int width, int height, Span image) { fixed (byte* pData = data) { @@ -115,7 +115,7 @@ namespace Texture2DDecoder } } - public static bool DecodeEACRG(byte[] data, int width, int height, byte[] image) + public static bool DecodeEACRG(ReadOnlySpan data, int width, int height, Span image) { fixed (byte* pData = data) { @@ -126,7 +126,7 @@ namespace Texture2DDecoder } } - public static bool DecodeEACRGSigned(byte[] data, int width, int height, byte[] image) + public static bool DecodeEACRGSigned(ReadOnlySpan data, int width, int height, Span image) { fixed (byte* pData = data) { @@ -137,7 +137,7 @@ namespace Texture2DDecoder } } - public static bool DecodeBC4(byte[] data, int width, int height, byte[] image) + public static bool DecodeBC4(ReadOnlySpan data, int width, int height, Span image) { fixed (byte* pData = data) { @@ -148,7 +148,7 @@ namespace Texture2DDecoder } } - public static bool DecodeBC5(byte[] data, int width, int height, byte[] image) + public static bool DecodeBC5(ReadOnlySpan data, int width, int height, Span image) { fixed (byte* pData = data) { @@ -159,7 +159,7 @@ namespace Texture2DDecoder } } - public static bool DecodeBC6(byte[] data, int width, int height, byte[] image) + public static bool DecodeBC6(ReadOnlySpan data, int width, int height, Span image) { fixed (byte* pData = data) { @@ -170,7 +170,7 @@ namespace Texture2DDecoder } } - public static bool DecodeBC7(byte[] data, int width, int height, byte[] image) + public static bool DecodeBC7(ReadOnlySpan data, int width, int height, Span image) { fixed (byte* pData = data) { @@ -181,7 +181,7 @@ namespace Texture2DDecoder } } - public static bool DecodeATCRGB4(byte[] data, int width, int height, byte[] image) + public static bool DecodeATCRGB4(ReadOnlySpan data, int width, int height, Span image) { fixed (byte* pData = data) { @@ -192,7 +192,7 @@ namespace Texture2DDecoder } } - public static bool DecodeATCRGBA8(byte[] data, int width, int height, byte[] image) + public static bool DecodeATCRGBA8(ReadOnlySpan data, int width, int height, Span image) { fixed (byte* pData = data) { @@ -203,7 +203,7 @@ namespace Texture2DDecoder } } - public static bool DecodeASTC(byte[] data, int width, int height, int blockWidth, int blockHeight, byte[] image) + public static bool DecodeASTC(ReadOnlySpan data, int width, int height, int blockWidth, int blockHeight, Span image) { fixed (byte* pData = data) { @@ -214,7 +214,7 @@ namespace Texture2DDecoder } } - public static byte[] UnpackCrunch(byte[] data) + public static byte[] UnpackCrunch(ReadOnlySpan data) { void* pBuffer; uint bufferSize; @@ -238,7 +238,7 @@ namespace Texture2DDecoder return result; } - public static byte[] UnpackUnityCrunch(byte[] data) + public static byte[] UnpackUnityCrunch(ReadOnlySpan data) { void* pBuffer; uint bufferSize; @@ -261,6 +261,5 @@ namespace Texture2DDecoder return result; } - } }