mirror of
https://github.com/AssetRipper/AssetRipper.TextureDecoder.git
synced 2026-11-13 12:41:27 -10:00
Aggressive Optimization
This commit is contained in:
1 parent
750dae931e
commit
e5da67340b
13 files changed
+98
-117
No files matched your search
@@ -855,19 +855,19 @@ namespace AssetRipper.TextureDecoder.Astc
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static uint Color(uint r, uint g, uint b, uint a)
|
||||
{
|
||||
return r << 16 | g << 8 | b | a << 24;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static byte BitReverseU8(byte c, int bits)
|
||||
{
|
||||
return (byte)(BitReverseTable[c] >> (8 - bits));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static ulong BitReverseU64(ulong d, int bits)
|
||||
{
|
||||
ulong ret;
|
||||
@@ -886,13 +886,13 @@ namespace AssetRipper.TextureDecoder.Astc
|
||||
return ret >> (64 - bits);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private unsafe static int GetBits(byte* input, int bit, int len)
|
||||
{
|
||||
return (*((int*)(input + bit / 8)) >> (bit % 8)) & ((1 << len) - 1);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private unsafe static ulong GetBits64(byte* input, int bit, int len)
|
||||
{
|
||||
ulong mask = len == 64 ? 0xffffffffffffffff : (1UL << len) - 1;
|
||||
@@ -918,13 +918,13 @@ namespace AssetRipper.TextureDecoder.Astc
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static byte Clamp(int n)
|
||||
{
|
||||
return n < 0 ? byte.MinValue : n > 255 ? byte.MaxValue : (byte)n;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static unsafe void BitTransferSigned(int* a, int* b)
|
||||
{
|
||||
*b = (*b >> 1) | (*a & 0x80);
|
||||
@@ -935,7 +935,7 @@ namespace AssetRipper.TextureDecoder.Astc
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private unsafe static void SetEndpoint(int* endpoint, int r1, int g1, int b1, int a1, int r2, int g2, int b2, int a2)
|
||||
{
|
||||
endpoint[0] = r1;
|
||||
@@ -948,7 +948,7 @@ namespace AssetRipper.TextureDecoder.Astc
|
||||
endpoint[7] = a2;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private unsafe static void SetEndpointClamp(int* endpoint, int r1, int g1, int b1, int a1, int r2, int g2, int b2, int a2)
|
||||
{
|
||||
endpoint[0] = Clamp(r1);
|
||||
@@ -961,7 +961,7 @@ namespace AssetRipper.TextureDecoder.Astc
|
||||
endpoint[7] = Clamp(a2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private unsafe static void SetEndpointBlue(int* endpoint, int r1, int g1, int b1, int a1, int r2, int g2, int b2, int a2)
|
||||
{
|
||||
endpoint[0] = (r1 + b1) >> 1;
|
||||
@@ -974,7 +974,7 @@ namespace AssetRipper.TextureDecoder.Astc
|
||||
endpoint[7] = a2;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private unsafe static void SetEndpointBlueClamp(int* endpoint, int r1, int g1, int b1, int a1, int r2, int g2, int b2, int a2)
|
||||
{
|
||||
endpoint[0] = Clamp((r1 + b1) >> 1);
|
||||
@@ -987,7 +987,7 @@ namespace AssetRipper.TextureDecoder.Astc
|
||||
endpoint[7] = Clamp(a2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static byte SelectColor(int v0, int v1, int weight)
|
||||
{
|
||||
return (byte)(((((v0 << 8 | v0) * (64 - weight) + (v1 << 8 | v1) * weight + 32) >> 6) * 255 + 32768) / 65536);
|
||||
|
||||
@@ -143,13 +143,13 @@ namespace AssetRipper.TextureDecoder.Atc
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static T ReadAtOffset<T>(this ReadOnlySpan<byte> input, int offset) where T : unmanaged
|
||||
{
|
||||
return MemoryMarshal.Read<T>(input.Slice(offset));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static void DecodeColors(Span<int> colors, int c0, int c1)
|
||||
{
|
||||
if ((c0 & 0x8000) == 0)
|
||||
@@ -190,7 +190,7 @@ namespace AssetRipper.TextureDecoder.Atc
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static void DecodeAlphas(Span<int> alphas, int a0, int a1)
|
||||
{
|
||||
alphas[0] = a0;
|
||||
@@ -215,14 +215,14 @@ namespace AssetRipper.TextureDecoder.Atc
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static int Extend(int value, int from, int to)
|
||||
{
|
||||
// bit-pattern replicating scaling (can at most double the bits)
|
||||
return (value << (to - from)) | (value >> (from * 2 - to));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static uint Color(int r, int g, int b, int a)
|
||||
{
|
||||
return unchecked((uint)(r << 16 | g << 8 | b | a << 24));
|
||||
|
||||
@@ -251,7 +251,7 @@ namespace AssetRipper.TextureDecoder.Dxt
|
||||
return offset;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static void Rgb565(int c, out int r, out int g, out int b)
|
||||
{
|
||||
r = (c & 0xf800) >> 8;
|
||||
@@ -262,7 +262,7 @@ namespace AssetRipper.TextureDecoder.Dxt
|
||||
b |= b >> 5;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static int Color(int r, int g, int b, int a)
|
||||
{
|
||||
return r << 16 | g << 8 | b | a << 24;
|
||||
@@ -276,19 +276,19 @@ namespace AssetRipper.TextureDecoder.Dxt
|
||||
/// <param name="destination">The destination buffer.</param>
|
||||
/// <param name="destinationOffset">The zero-based byte offset into destination.</param>
|
||||
/// <param name="count">The number of bytes to copy.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static void BlockCopy(ReadOnlySpan<byte> source, int sourceOffset, Span<byte> destination, int destinationOffset, int count)
|
||||
{
|
||||
source.Slice(sourceOffset, count).CopyTo(destination.Slice(destinationOffset));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static uint ToUInt32(ReadOnlySpan<byte> input, int offset)
|
||||
{
|
||||
return BinaryPrimitives.ReadUInt32LittleEndian(input.Slice(offset));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static ulong ToUInt64(ReadOnlySpan<byte> input, int offset)
|
||||
{
|
||||
return BinaryPrimitives.ReadUInt64LittleEndian(input.Slice(offset));
|
||||
|
||||
@@ -640,7 +640,7 @@ namespace AssetRipper.TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static void DecodeEtc2a1Block(ReadOnlySpan<byte> input, Span<uint> output)
|
||||
{
|
||||
if ((input[3] & 2) != 0)
|
||||
@@ -856,7 +856,7 @@ namespace AssetRipper.TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static void DecodeEac11Block(Span<byte> output, int @base)
|
||||
{
|
||||
for (int i = 0; i < 16; i++)
|
||||
@@ -865,7 +865,7 @@ namespace AssetRipper.TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static void DecodeEac11Block(Span<byte> output, int @base, int ti, int mul, ulong l)
|
||||
{
|
||||
ReadOnlySpan<sbyte> table = Etc2AlphaModTable.AsSpan(ti * 8, 8);
|
||||
@@ -876,37 +876,37 @@ namespace AssetRipper.TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static uint Color(int r, int g, int b, int a)
|
||||
{
|
||||
return unchecked((uint)(r << 16 | g << 8 | b | a << 24));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static byte Clamp255(int n)
|
||||
{
|
||||
return n < 0 ? (byte)0 : n > 255 ? (byte)255 : unchecked((byte)n);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static uint ApplicateColor(ReadOnlySpan<byte> c, int o, int m)
|
||||
{
|
||||
return Color(Clamp255(c[o * 3 + 0] + m), Clamp255(c[o * 3 + 1] + m), Clamp255(c[o * 3 + 2] + m), 255);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static uint ApplicateColor(ReadOnlySpan<int> c, int o, int m)
|
||||
{
|
||||
return Color(Clamp255(c[o * 3 + 0] + m), Clamp255(c[o * 3 + 1] + m), Clamp255(c[o * 3 + 2] + m), 255);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static uint ApplicateColorRaw(ReadOnlySpan<byte> c, int o)
|
||||
{
|
||||
return Color(c[o * 3 + 0], c[o * 3 + 1], c[o * 3 + 2], 255);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static ulong Get6SwapedBytes(ReadOnlySpan<byte> data)
|
||||
{
|
||||
return data[7] | (uint)data[6] << 8 | (uint)data[5] << 16 | (uint)data[4] << 24 | (ulong)data[3] << 32 | (ulong)data[2] << 40;
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace AssetRipper.TextureDecoder
|
||||
{
|
||||
internal static class OptimizationConstants
|
||||
{
|
||||
#if NETCOREAPP
|
||||
internal const MethodImplOptions AggressiveInliningAndOptimization = MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization;
|
||||
#else
|
||||
internal const MethodImplOptions AggressiveInliningAndOptimization = MethodImplOptions.AggressiveInlining;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ namespace AssetRipper.TextureDecoder.Pvrtc
|
||||
/// <param name="output">The decompressed texture data</param>
|
||||
/// <param name="do2bitMode">Signifies whether the data is PVRTC2 or PVRTC4</param>
|
||||
/// <returns>The number of bytes read from <paramref name="input"/></returns>
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int DecompressPVRTC(ReadOnlySpan<byte> input, int xDim, int yDim, bool do2bitMode, out byte[] output)
|
||||
{
|
||||
output = new byte[xDim * yDim * sizeof(uint)];
|
||||
@@ -32,7 +32,7 @@ namespace AssetRipper.TextureDecoder.Pvrtc
|
||||
/// <param name="output">The decompressed texture data</param>
|
||||
/// <param name="do2bitMode">Signifies whether the data is PVRTC2 or PVRTC4</param>
|
||||
/// <returns>The number of bytes read from <paramref name="input"/></returns>
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int DecompressPVRTC(ReadOnlySpan<byte> input, int xDim, int yDim, bool do2bitMode, Span<byte> output)
|
||||
{
|
||||
int xBlockSize = do2bitMode ? BlockX2bpp : BlockX4bpp;
|
||||
@@ -455,7 +455,7 @@ namespace AssetRipper.TextureDecoder.Pvrtc
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static Span<int> GetIntSpanForColor(this Span<Colours5554> colorSpan, int index)
|
||||
{
|
||||
return MemoryMarshal.Cast<Colours5554, int>(colorSpan.Slice(index, 1));
|
||||
@@ -466,7 +466,7 @@ namespace AssetRipper.TextureDecoder.Pvrtc
|
||||
/// </summary>
|
||||
/// <param name="input">A number</param>
|
||||
/// <returns>True if the number is an integer power of two, else false</returns>
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static bool IsPowerOf2(uint input)
|
||||
{
|
||||
if (input == 0)
|
||||
@@ -481,7 +481,7 @@ namespace AssetRipper.TextureDecoder.Pvrtc
|
||||
/// <summary>
|
||||
/// Define an expression to either wrap or clamp large or small vals to the legal coordinate range
|
||||
/// </summary>
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static int LimitCoord(int value, int size)
|
||||
{
|
||||
#if ASSUME_IMAGE_TILING
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{
|
||||
internal static class DefaultColorMethods
|
||||
{
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
internal static void GetChannels<T, TArg>(T color, out TArg r, out TArg g, out TArg b, out TArg a)
|
||||
where TArg : unmanaged
|
||||
where T : unmanaged, IColor<TArg>
|
||||
@@ -13,7 +13,7 @@
|
||||
a = color.A;
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
internal static void SetChannels<T, TArg>(ref T color, TArg r, TArg g, TArg b, TArg a)
|
||||
where TArg : unmanaged
|
||||
where T : unmanaged, IColor<TArg>
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
set { }
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public readonly void GetChannels(out double r, out double g, out double b, out double a)
|
||||
{
|
||||
double scale = Scale;
|
||||
@@ -53,13 +53,13 @@
|
||||
a = 1;
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public void SetChannels(double r, double g, double b, double a)
|
||||
{
|
||||
SetChannels(r, g, b);
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public void SetChannels(double r, double g, double b)
|
||||
{
|
||||
int exponent = CalculateExponent(r, g, b);
|
||||
@@ -80,7 +80,7 @@
|
||||
private readonly uint GBits => (bits >> GreenOffset) & ChannelBitMask;
|
||||
private readonly uint BBits => (bits >> BlueOffset) & ChannelBitMask;
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static int CalculateExponent(double r, double g, double b)
|
||||
{
|
||||
double maxChannel = double.Max(r, double.Max(g, b));
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
|
||||
public static class ColorExtensions
|
||||
{
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
internal static void SetConvertedChannels<TThis, TThisArg, TSourceArg>(this ref TThis color, TSourceArg r, TSourceArg g, TSourceArg b, TSourceArg a)
|
||||
where TThisArg : unmanaged
|
||||
where TSourceArg : unmanaged
|
||||
@@ -81,7 +81,7 @@
|
||||
NumericConversion.Convert<TSourceArg, TThisArg>(a));
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static TTarget Convert<TThis, TThisArg, TTarget, TTargetArg>(this TThis color)
|
||||
where TThisArg : unmanaged
|
||||
where TTargetArg : unmanaged
|
||||
|
||||
@@ -25,8 +25,9 @@ public static partial class NumericConversion
|
||||
#else
|
||||
return default; //exceptions prevent inlining
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static TTo ToSignedNumber<TFrom, TTo>(TFrom value)
|
||||
where TFrom : unmanaged, IUnsignedNumber<TFrom>, IShiftOperators<TFrom, int, TFrom>, IBitwiseOperators<TFrom, TFrom, TFrom>
|
||||
where TTo : unmanaged, ISignedNumber<TTo>
|
||||
@@ -39,8 +40,9 @@ public static partial class NumericConversion
|
||||
TFrom SignBit = TFrom.One << (Unsafe.SizeOf<TFrom>() * 8 - 1);
|
||||
TFrom converted = (SignBit ^ value);
|
||||
return Unsafe.As<TFrom, TTo>(ref converted);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static TTo ToUnsignedNumber<TFrom, TTo>(TFrom value)
|
||||
where TFrom : unmanaged, ISignedNumber<TFrom>
|
||||
where TTo : unmanaged, IUnsignedNumber<TTo>, IShiftOperators<TTo, int, TTo>, IBitwiseOperators<TTo, TTo, TTo>
|
||||
|
||||
@@ -5,14 +5,14 @@ namespace AssetRipper.TextureDecoder.Rgb
|
||||
{
|
||||
public static class RgbConverter
|
||||
{
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int A8ToBGRA32(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * 4];
|
||||
return A8ToBGRA32(input, width, height, output);
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int A8ToBGRA32(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -32,14 +32,14 @@ namespace AssetRipper.TextureDecoder.Rgb
|
||||
return io;
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RGB24ToBGRA32(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * 4];
|
||||
return RGB24ToBGRA32(input, width, height, output);
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RGB24ToBGRA32(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -59,14 +59,14 @@ namespace AssetRipper.TextureDecoder.Rgb
|
||||
return io;
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RGBA32ToBGRA32(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * 4];
|
||||
return RGBA32ToBGRA32(input, width, height, output);
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RGBA32ToBGRA32(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -86,14 +86,14 @@ namespace AssetRipper.TextureDecoder.Rgb
|
||||
return io;
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int ARGB32ToBGRA32(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * 4];
|
||||
return ARGB32ToBGRA32(input, width, height, output);
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int ARGB32ToBGRA32(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -113,14 +113,14 @@ namespace AssetRipper.TextureDecoder.Rgb
|
||||
return io;
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RGB16ToBGRA32(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * 4];
|
||||
return RGB16ToBGRA32(input, width, height, output);
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RGB16ToBGRA32(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -143,14 +143,14 @@ namespace AssetRipper.TextureDecoder.Rgb
|
||||
return io;
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RG16ToBGRA32(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * 4];
|
||||
return RG16ToBGRA32(input, width, height, output);
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RG16ToBGRA32(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -170,14 +170,14 @@ namespace AssetRipper.TextureDecoder.Rgb
|
||||
return io;
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int R8ToBGRA32(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * 4];
|
||||
return R8ToBGRA32(input, width, height, output);
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int R8ToBGRA32(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -197,14 +197,14 @@ namespace AssetRipper.TextureDecoder.Rgb
|
||||
return io;
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RHalfToBGRA32(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * 4];
|
||||
return RHalfToBGRA32(input, width, height, output);
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RHalfToBGRA32(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -225,14 +225,14 @@ namespace AssetRipper.TextureDecoder.Rgb
|
||||
return io;
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RGHalfToBGRA32(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * 4];
|
||||
return RGHalfToBGRA32(input, width, height, output);
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RGHalfToBGRA32(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -254,14 +254,14 @@ namespace AssetRipper.TextureDecoder.Rgb
|
||||
return io;
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RGBAHalfToBGRA32(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * 4];
|
||||
return RGBAHalfToBGRA32(input, width, height, output);
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RGBAHalfToBGRA32(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -285,14 +285,14 @@ namespace AssetRipper.TextureDecoder.Rgb
|
||||
return io;
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RFloatToBGRA32(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * 4];
|
||||
return RFloatToBGRA32(input, width, height, output);
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RFloatToBGRA32(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -313,14 +313,14 @@ namespace AssetRipper.TextureDecoder.Rgb
|
||||
return io;
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RGFloatToBGRA32(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * 4];
|
||||
return RGFloatToBGRA32(input, width, height, output);
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RGFloatToBGRA32(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -342,14 +342,14 @@ namespace AssetRipper.TextureDecoder.Rgb
|
||||
return io;
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RGBAFloatToBGRA32(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * 4];
|
||||
return RGBAFloatToBGRA32(input, width, height, output);
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RGBAFloatToBGRA32(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -373,14 +373,14 @@ namespace AssetRipper.TextureDecoder.Rgb
|
||||
return io;
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RGB9e5FloatToBGRA32(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * 4];
|
||||
return RGB9e5FloatToBGRA32(input, width, height, output);
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RGB9e5FloatToBGRA32(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -405,14 +405,14 @@ namespace AssetRipper.TextureDecoder.Rgb
|
||||
return io;
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RG32ToBGRA32(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * 4];
|
||||
return RG32ToBGRA32(input, width, height, output);
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RG32ToBGRA32(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -432,14 +432,14 @@ namespace AssetRipper.TextureDecoder.Rgb
|
||||
return io;
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RGB48ToBGRA32(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * 4];
|
||||
return RGB48ToBGRA32(input, width, height, output);
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RGB48ToBGRA32(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -459,14 +459,14 @@ namespace AssetRipper.TextureDecoder.Rgb
|
||||
return io;
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RGBA64ToBGRA32(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * 4];
|
||||
return RGBA64ToBGRA32(input, width, height, output);
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int RGBA64ToBGRA32(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -486,7 +486,7 @@ namespace AssetRipper.TextureDecoder.Rgb
|
||||
return io;
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int Convert<TSource, TSourceArg, TDestination, TDestinationArg>(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
where TSourceArg : unmanaged
|
||||
where TSource : unmanaged, IColor<TSourceArg>
|
||||
@@ -497,7 +497,7 @@ namespace AssetRipper.TextureDecoder.Rgb
|
||||
return Convert<TSource, TSourceArg, TDestination, TDestinationArg>(input, width, height, output);
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int Convert<TSource, TSourceArg, TDestination, TDestinationArg>(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
where TSourceArg : unmanaged
|
||||
where TSource : unmanaged, IColor<TSourceArg>
|
||||
@@ -510,7 +510,7 @@ namespace AssetRipper.TextureDecoder.Rgb
|
||||
return width * height * Unsafe.SizeOf<TSource>();
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static void Convert<TSource, TSourceArg, TDestination, TDestinationArg>(ReadOnlySpan<TSource> sourceSpan, Span<TDestination> destinationSpan)
|
||||
where TSourceArg : unmanaged
|
||||
where TSource : unmanaged, IColor<TSourceArg>
|
||||
@@ -523,35 +523,25 @@ namespace AssetRipper.TextureDecoder.Rgb
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static float ToHalf(ReadOnlySpan<byte> input, int offset)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return (float)BinaryPrimitives.ReadHalfLittleEndian(input.Slice(offset, 2));
|
||||
#else
|
||||
ushort bits = BinaryPrimitives.ReadUInt16LittleEndian(input.Slice(offset, 2));
|
||||
return (float)Unsafe.As<ushort, Half>(ref bits);
|
||||
#endif
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static float ToSingle(ReadOnlySpan<byte> input, int offset)
|
||||
{
|
||||
#if NET5_0_OR_GREATER
|
||||
return BinaryPrimitives.ReadSingleLittleEndian(input.Slice(offset, 4));
|
||||
#else
|
||||
uint bits = BinaryPrimitives.ReadUInt32LittleEndian(input.Slice(offset, 4));
|
||||
return Unsafe.As<uint, float>(ref bits);
|
||||
#endif
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static byte ClampByte(float x)
|
||||
{
|
||||
return byte.MaxValue < x ? byte.MaxValue : (x > byte.MinValue ? (byte)x : byte.MinValue);
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static byte ClampByte(double x)
|
||||
{
|
||||
return byte.MaxValue < x ? byte.MaxValue : (x > byte.MinValue ? (byte)x : byte.MinValue);
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static uint Convert8BitsTo4Bits(byte value)
|
||||
{
|
||||
//See https://github.com/AssetRipper/TextureDecoder/issues/19
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace AssetRipper.TextureDecoder.Yuy2
|
||||
/// <param name="height">Pixel height of the image.</param>
|
||||
/// <param name="output">An output buffer of size 4 * width * height.</param>
|
||||
/// <returns>Number of bytes read from <paramref name="input"/></returns>
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int DecompressYUY2(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
{
|
||||
output = new byte[width * height * sizeof(uint)];
|
||||
@@ -28,7 +28,7 @@ namespace AssetRipper.TextureDecoder.Yuy2
|
||||
/// <param name="height">Pixel height of the image.</param>
|
||||
/// <param name="output">An output buffer. Must be at least 4 * width * height.</param>
|
||||
/// <returns>Number of bytes read from <paramref name="input"/></returns>
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int DecompressYUY2(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
{
|
||||
ThrowHelper.ThrowIfNotEnoughSpace(output, width, height);
|
||||
@@ -72,7 +72,7 @@ namespace AssetRipper.TextureDecoder.Yuy2
|
||||
/// <param name="height">Pixel height of the image.</param>
|
||||
/// <param name="output">An output buffer. Must be at least width * height * pixelSize.</param>
|
||||
/// <returns>Number of bytes read from <paramref name="input"/></returns>
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int DecompressYUY2<TOutput, TOutputArg>(ReadOnlySpan<byte> input, int width, int height, out byte[] output)
|
||||
where TOutputArg : unmanaged
|
||||
where TOutput : unmanaged, IColor<TOutputArg>
|
||||
@@ -91,7 +91,7 @@ namespace AssetRipper.TextureDecoder.Yuy2
|
||||
/// <param name="height">Pixel height of the image.</param>
|
||||
/// <param name="output">An output buffer. Must be at least width * height * pixelSize.</param>
|
||||
/// <returns>Number of bytes read from <paramref name="input"/></returns>
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int DecompressYUY2<TOutput, TOutputArg>(ReadOnlySpan<byte> input, int width, int height, Span<byte> output)
|
||||
where TOutputArg : unmanaged
|
||||
where TOutput : unmanaged, IColor<TOutputArg>
|
||||
@@ -109,7 +109,7 @@ namespace AssetRipper.TextureDecoder.Yuy2
|
||||
/// <param name="height">Pixel height of the image.</param>
|
||||
/// <param name="output">An output buffer. Must be at least width * height.</param>
|
||||
/// <returns>Number of bytes read from <paramref name="input"/></returns>
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int DecompressYUY2<TOutput, TOutputArg>(ReadOnlySpan<byte> input, int width, int height, Span<TOutput> output)
|
||||
where TOutputArg : unmanaged
|
||||
where TOutput : unmanaged, IColor<TOutputArg>
|
||||
@@ -145,7 +145,7 @@ namespace AssetRipper.TextureDecoder.Yuy2
|
||||
return p;
|
||||
}
|
||||
|
||||
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private static byte ClampByte(int x)
|
||||
{
|
||||
return (byte)(byte.MaxValue < x ? byte.MaxValue : (x > byte.MinValue ? x : byte.MinValue));
|
||||
|
||||
Reference in new issue
Block a user