From cab5cabc4ee5245b68d5b580fe62c36b26bb267d Mon Sep 17 00:00:00 2001 From: Jeremy Pritts Date: Fri, 11 Feb 2022 20:44:02 -0500 Subject: [PATCH] update package info, add net 5 target, and bump version --- AstcTest/Program.cs | 2 +- AtcTest/Program.cs | 2 +- DxtTest/Program.cs | 2 +- EtcTest/Program.cs | 2 +- PvrtcTest/Program.cs | 2 +- RgbTest/Program.cs | 2 +- TextureDecoder/Astc/AstcDecoder.cs | 2 +- TextureDecoder/Atc/AtcDecoder.cs | 2 +- TextureDecoder/Dxt/DxtDecoder.cs | 2 +- TextureDecoder/Etc/EtcDecoder.cs | 2 +- TextureDecoder/Pvrtc/PvrtcDecoder.cs | 2 +- TextureDecoder/Rgb/RgbConverter.cs | 25 +++++++++++++++++-------- TextureDecoder/TextureDecoder.csproj | 9 +++++---- TextureDecoder/Yuy2/Yuy2Decoder.cs | 2 +- Yuy2Test/Program.cs | 2 +- 15 files changed, 35 insertions(+), 25 deletions(-) diff --git a/AstcTest/Program.cs b/AstcTest/Program.cs index e31c823..99af5a3 100644 --- a/AstcTest/Program.cs +++ b/AstcTest/Program.cs @@ -1,7 +1,7 @@ using System; using System.Drawing.Imaging; using System.IO; -using TextureDecoder.Astc; +using AssetRipper.TextureDecoder.Astc; namespace AstcTest { diff --git a/AtcTest/Program.cs b/AtcTest/Program.cs index d8917f8..cba81ec 100644 --- a/AtcTest/Program.cs +++ b/AtcTest/Program.cs @@ -2,7 +2,7 @@ using System.Diagnostics; using System.Drawing.Imaging; using System.IO; -using TextureDecoder.Atc; +using AssetRipper.TextureDecoder.Atc; namespace AtcTest { diff --git a/DxtTest/Program.cs b/DxtTest/Program.cs index 1a49134..cda9579 100644 --- a/DxtTest/Program.cs +++ b/DxtTest/Program.cs @@ -2,7 +2,7 @@ using System.Diagnostics; using System.Drawing.Imaging; using System.IO; -using TextureDecoder.Dxt; +using AssetRipper.TextureDecoder.Dxt; namespace DxtTest { diff --git a/EtcTest/Program.cs b/EtcTest/Program.cs index a182c5b..6b6c135 100644 --- a/EtcTest/Program.cs +++ b/EtcTest/Program.cs @@ -2,7 +2,7 @@ using System.Diagnostics; using System.Drawing.Imaging; using System.IO; -using TextureDecoder.Etc; +using AssetRipper.TextureDecoder.Etc; namespace EtcTest { diff --git a/PvrtcTest/Program.cs b/PvrtcTest/Program.cs index 20ab1b8..005d8df 100644 --- a/PvrtcTest/Program.cs +++ b/PvrtcTest/Program.cs @@ -2,7 +2,7 @@ using System.Diagnostics; using System.Drawing.Imaging; using System.IO; -using TextureDecoder.Pvrtc; +using AssetRipper.TextureDecoder.Pvrtc; namespace PvrtcTest { diff --git a/RgbTest/Program.cs b/RgbTest/Program.cs index de70f70..9db97e6 100644 --- a/RgbTest/Program.cs +++ b/RgbTest/Program.cs @@ -2,7 +2,7 @@ using System.Diagnostics; using System.Drawing.Imaging; using System.IO; -using TextureDecoder.Rgb; +using AssetRipper.TextureDecoder.Rgb; namespace RgbTest { diff --git a/TextureDecoder/Astc/AstcDecoder.cs b/TextureDecoder/Astc/AstcDecoder.cs index 08db2cc..6dc74dd 100644 --- a/TextureDecoder/Astc/AstcDecoder.cs +++ b/TextureDecoder/Astc/AstcDecoder.cs @@ -1,6 +1,6 @@ using System.Runtime.CompilerServices; -namespace TextureDecoder.Astc +namespace AssetRipper.TextureDecoder.Astc { /// /// diff --git a/TextureDecoder/Atc/AtcDecoder.cs b/TextureDecoder/Atc/AtcDecoder.cs index b04f958..dab1620 100644 --- a/TextureDecoder/Atc/AtcDecoder.cs +++ b/TextureDecoder/Atc/AtcDecoder.cs @@ -1,7 +1,7 @@ using System; using System.Runtime.CompilerServices; -namespace TextureDecoder.Atc +namespace AssetRipper.TextureDecoder.Atc { /// /// diff --git a/TextureDecoder/Dxt/DxtDecoder.cs b/TextureDecoder/Dxt/DxtDecoder.cs index 61da257..48c4d44 100644 --- a/TextureDecoder/Dxt/DxtDecoder.cs +++ b/TextureDecoder/Dxt/DxtDecoder.cs @@ -1,7 +1,7 @@ using System; using System.Runtime.CompilerServices; -namespace TextureDecoder.Dxt +namespace AssetRipper.TextureDecoder.Dxt { /// /// diff --git a/TextureDecoder/Etc/EtcDecoder.cs b/TextureDecoder/Etc/EtcDecoder.cs index 16ac866..cb64064 100644 --- a/TextureDecoder/Etc/EtcDecoder.cs +++ b/TextureDecoder/Etc/EtcDecoder.cs @@ -1,6 +1,6 @@ using System.Runtime.CompilerServices; -namespace TextureDecoder.Etc +namespace AssetRipper.TextureDecoder.Etc { /// /// diff --git a/TextureDecoder/Pvrtc/PvrtcDecoder.cs b/TextureDecoder/Pvrtc/PvrtcDecoder.cs index 36ade0e..b6d84c4 100644 --- a/TextureDecoder/Pvrtc/PvrtcDecoder.cs +++ b/TextureDecoder/Pvrtc/PvrtcDecoder.cs @@ -4,7 +4,7 @@ using System; using System.Runtime.CompilerServices; -namespace TextureDecoder.Pvrtc +namespace AssetRipper.TextureDecoder.Pvrtc { /// /// diff --git a/TextureDecoder/Rgb/RgbConverter.cs b/TextureDecoder/Rgb/RgbConverter.cs index 52fd1dd..e152172 100644 --- a/TextureDecoder/Rgb/RgbConverter.cs +++ b/TextureDecoder/Rgb/RgbConverter.cs @@ -1,7 +1,10 @@ using System; using System.Runtime.CompilerServices; +#if NET5_0_OR_GREATER +using System.Buffers.Binary; +#endif -namespace TextureDecoder.Rgb +namespace AssetRipper.TextureDecoder.Rgb { /// /// @@ -696,21 +699,26 @@ public static void RGB9e5FloatToBGRA32(byte[] input, int width, int height, byte private static float ToHalf(byte[] input, int offset) { #if NET6_0_OR_GREATER - return (float)System.Buffers.Binary.BinaryPrimitives.ReadHalfLittleEndian(input.AsSpan(offset, 2)); -#elif NET5_0_OR_GREATER - if(BitConverter.IsLittleEndian) - return (float)BitConverter.ToHalf(input, offset); - else - return (float)BitConverter.ToHalf(new byte[] { input[offset + 1], input[offset] }); + return (float)BinaryPrimitives.ReadHalfLittleEndian(input.AsSpan(offset, 2)); +#elif NET5_0 + return (float)ToHalf(BinaryPrimitives.ReadUInt16LittleEndian(input.AsSpan(offset, 2))); #else return (float)Half.ToHalf(input, offset); #endif } +#if NET5_0 + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe Half ToHalf(ushort bits) + { + return *((Half*)&bits); + } +#endif + private static float ToSingle(byte[] input, int offset) { #if NET5_0_OR_GREATER - return System.Buffers.Binary.BinaryPrimitives.ReadSingleLittleEndian(input.AsSpan(offset, 4)); + return BinaryPrimitives.ReadSingleLittleEndian(input.AsSpan(offset, 4)); #else if (BitConverter.IsLittleEndian) return BitConverter.ToSingle(input, offset); @@ -730,5 +738,6 @@ private static byte ClampByte(double x) { return byte.MaxValue < x ? byte.MaxValue : (x > byte.MinValue ? (byte)x : byte.MinValue); } + } } diff --git a/TextureDecoder/TextureDecoder.csproj b/TextureDecoder/TextureDecoder.csproj index 4f1a17e..09e10f4 100644 --- a/TextureDecoder/TextureDecoder.csproj +++ b/TextureDecoder/TextureDecoder.csproj @@ -1,17 +1,18 @@  - netstandard2.0;net6.0 + netstandard2.0;net5.0;net6.0 Latest enable disable true true + AssetRipper.TextureDecoder ds5678 AssetRipper - 1.0.2.0 - 1.0.2.0 - TextureDecoder + 1.1.0.0 + 1.1.0.0 + AssetRipper.TextureDecoder C# Texture https://github.com/AssetRipper/TextureDecoder MIT diff --git a/TextureDecoder/Yuy2/Yuy2Decoder.cs b/TextureDecoder/Yuy2/Yuy2Decoder.cs index 4d42f5d..726dcd1 100644 --- a/TextureDecoder/Yuy2/Yuy2Decoder.cs +++ b/TextureDecoder/Yuy2/Yuy2Decoder.cs @@ -1,6 +1,6 @@ using System.Runtime.CompilerServices; -namespace TextureDecoder.Yuy2 +namespace AssetRipper.TextureDecoder.Yuy2 { /// /// diff --git a/Yuy2Test/Program.cs b/Yuy2Test/Program.cs index 1a87a7c..b89fc57 100644 --- a/Yuy2Test/Program.cs +++ b/Yuy2Test/Program.cs @@ -2,7 +2,7 @@ using System.Diagnostics; using System.Drawing.Imaging; using System.IO; -using TextureDecoder.Yuy2; +using AssetRipper.TextureDecoder.Yuy2; namespace Yuy2Test {