diff --git a/AssetRipper.TextureDecoder.ColorGenerator/AssetRipper.TextureDecoder.ColorGenerator.csproj b/AssetRipper.TextureDecoder.ColorGenerator/AssetRipper.TextureDecoder.ColorGenerator.csproj
index 00eab3e..47d0b3d 100644
--- a/AssetRipper.TextureDecoder.ColorGenerator/AssetRipper.TextureDecoder.ColorGenerator.csproj
+++ b/AssetRipper.TextureDecoder.ColorGenerator/AssetRipper.TextureDecoder.ColorGenerator.csproj
@@ -11,4 +11,8 @@
+
+
+
+
diff --git a/AssetRipper.TextureDecoder.ColorGenerator/NumericConversionGenerator.cs b/AssetRipper.TextureDecoder.ColorGenerator/NumericConversionGenerator.cs
index bfa00bb..6c39e5f 100644
--- a/AssetRipper.TextureDecoder.ColorGenerator/NumericConversionGenerator.cs
+++ b/AssetRipper.TextureDecoder.ColorGenerator/NumericConversionGenerator.cs
@@ -1,4 +1,5 @@
using AssetRipper.Text.SourceGeneration;
+using AssetRipper.TextureDecoder.SourceGeneration.Common;
using System.CodeDom.Compiler;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
@@ -108,7 +109,7 @@ internal static class NumericConversionGenerator
writer.WriteLine($"private static TTo {methodName}({fromName} value) where TTo : unmanaged");
using (new CurlyBrackets(writer))
{
- if (IsSignedInteger(from, out Type? unsignedFrom))
+ if (CSharpPrimitives.IsSignedInteger(from, out Type? unsignedFrom))
{
writer.WriteLine($"{CSharpPrimitives.TypeNames[unsignedFrom]} unsigned = {ChangeSign}(value);");
writer.WriteLine($"return {ConvertMethodName(unsignedFrom)}(unsigned);");
@@ -125,22 +126,22 @@ internal static class NumericConversionGenerator
{
writer.WriteLine($"return Unsafe.As<{toName}, TTo>(ref value);");
}
- else if (IsSignedInteger(to, out Type? unsignedTo))
+ else if (CSharpPrimitives.IsSignedInteger(to, out Type? unsignedTo))
{
string unsignedToName = CSharpPrimitives.TypeNames[unsignedTo];
writer.WriteLine($"{toName} converted = {ChangeSign}({methodName}<{unsignedToName}>(value));");
writer.WriteLine($"return Unsafe.As<{toName}, TTo>(ref converted);");
}
- else if (IsFloatingPoint(from))
+ else if (CSharpPrimitives.IsFloatingPoint(from))
{
- if (IsFloatingPoint(to))
+ if (CSharpPrimitives.IsFloatingPoint(to))
{
writer.WriteLine($"{toName} converted = ({toName})value;");
writer.WriteLine($"return Unsafe.As<{toName}, TTo>(ref converted);");
}
else
{
- Debug.Assert(IsUnsignedInteger(to));
+ Debug.Assert(CSharpPrimitives.IsUnsignedInteger(to));
if (from == typeof(Half))
{
writer.WriteComment("We use float because it has enough precision to convert from Half to any integer type.");
@@ -159,8 +160,8 @@ internal static class NumericConversionGenerator
}
else
{
- Debug.Assert(IsUnsignedInteger(from));
- if (IsFloatingPoint(to))
+ Debug.Assert(CSharpPrimitives.IsUnsignedInteger(from));
+ if (CSharpPrimitives.IsFloatingPoint(to))
{
if (to == typeof(Half))
{
@@ -178,7 +179,7 @@ internal static class NumericConversionGenerator
}
else
{
- Debug.Assert(IsUnsignedInteger(to));
+ Debug.Assert(CSharpPrimitives.IsUnsignedInteger(to));
writer.WriteComment("See https://github.com/AssetRipper/TextureDecoder/issues/19");
int fromSize = CSharpPrimitives.Sizes[from];
int toSize = CSharpPrimitives.Sizes[to];
@@ -214,8 +215,8 @@ internal static class NumericConversionGenerator
string conversionType = fromSize <= sizeof(uint) ? "uint" : "ulong";
writer.WriteLine("unchecked");
using (new CurlyBrackets(writer))
- {
- int offset = (fromSize / toSize - 1) * toSize * 8;
+ {
+ int offset = (fromSize / toSize - 1) * toSize * 8;
writer.WriteLine($"{toName} converted = ({toName})(({conversionType})value >> {offset});");
writer.WriteLine($"return Unsafe.As<{toName}, TTo>(ref converted);");
}
@@ -239,39 +240,4 @@ internal static class NumericConversionGenerator
{
return $"Convert{from.Name}";
}
-
- private static bool IsFloatingPoint(Type type)
- {
- return type == typeof(Half) || type == typeof(float) || type == typeof(double) || type == typeof(decimal);
- }
-
- private static bool IsSignedInteger(Type type, [NotNullWhen(true)] out Type? unsignedType)
- {
- if (type == typeof(sbyte))
- {
- unsignedType = typeof(byte);
- }
- else if (type == typeof(short))
- {
- unsignedType = typeof(ushort);
- }
- else if (type == typeof(int))
- {
- unsignedType = typeof(uint);
- }
- else if (type == typeof(long))
- {
- unsignedType = typeof(ulong);
- }
- else
- {
- unsignedType = null;
- }
- return unsignedType is not null;
- }
-
- private static bool IsUnsignedInteger(Type type)
- {
- return type == typeof(byte) || type == typeof(ushort) || type == typeof(uint) || type == typeof(ulong);
- }
}
diff --git a/AssetRipper.TextureDecoder.ColorGenerator/Program.cs b/AssetRipper.TextureDecoder.ColorGenerator/Program.cs
index 1868877..162425e 100644
--- a/AssetRipper.TextureDecoder.ColorGenerator/Program.cs
+++ b/AssetRipper.TextureDecoder.ColorGenerator/Program.cs
@@ -1,60 +1,20 @@
-using System.CodeDom.Compiler;
-
+using AssetRipper.Text.SourceGeneration;
+using AssetRipper.TextureDecoder.SourceGeneration.Common;
+using System.CodeDom.Compiler;
+using System.Text;
+
namespace AssetRipper.TextureDecoder.ColorGenerator;
-internal static class Program
+internal static partial class Program
{
private const string AttributeNamespace = "AssetRipper.TextureDecoder.Attributes";
private const string OutputNamespace = "AssetRipper.TextureDecoder.Rgb.Formats";
private const string OutputFolder = "../../../../AssetRipper.TextureDecoder/Rgb/Formats/";
- ///
- /// Name, Type, Red, Blue, Green, Alpha
- ///
- private static readonly List<(string, Type, bool, bool, bool, bool)> Colors = new()
- {
- ( "ColorA8", typeof(byte), false, false, false, true ),
-
- ( "ColorR8", typeof(byte), true, false, false, false ),
- ( "ColorRG16", typeof(byte), true, true, false, false ),
- ( "ColorRGB24", typeof(byte), true, true, true, false ),
- ( "ColorRGBA32", typeof(byte), true, true, true, true ),
-
- ( "ColorR8Signed", typeof(sbyte), true, false, false, false ),
- ( "ColorRG16Signed", typeof(sbyte), true, true, false, false ),
- ( "ColorRGB24Signed", typeof(sbyte), true, true, true, false ),
- ( "ColorRGBA32Signed", typeof(sbyte), true, true, true, true ),
-
- ( "ColorR16", typeof(ushort), true, false, false, false ),
- ( "ColorRG32", typeof(ushort), true, true, false, false ),
- ( "ColorRGB48", typeof(ushort), true, true, true, false ),
- ( "ColorRGBA64", typeof(ushort), true, true, true, true ),
-
- ( "ColorR16Signed", typeof(short), true, false, false, false ),
- ( "ColorRG32Signed", typeof(short), true, true, false, false ),
- ( "ColorRGB48Signed", typeof(short), true, true, true, false ),
- ( "ColorRGBA64Signed", typeof(short), true, true, true, true ),
-
- ( "ColorR16Half", typeof(Half), true, false, false, false ),
- ( "ColorRG32Half", typeof(Half), true, true, false, false ),
- ( "ColorRGB48Half", typeof(Half), true, true, true, false ),
- ( "ColorRGBA64Half", typeof(Half), true, true, true, true ),
-
- ( "ColorR32Single", typeof(float), true, false, false, false ),
- ( "ColorRG64Single", typeof(float), true, true, false, false ),
- ( "ColorRGB96Single", typeof(float), true, true, true, false ),
- ( "ColorRGBA128Single", typeof(float), true, true, true, true ),
-
- ( "ColorR64Double", typeof(double), true, false, false, false ),
- ( "ColorRG128Double", typeof(double), true, true, false, false ),
- ( "ColorRGB192Double", typeof(double), true, true, true, false ),
- ( "ColorRGBA256Double", typeof(double), true, true, true, true ),
- };
-
///
/// Name, Type, Red, Blue, Green, Alpha, Fully Utilized
///
- private static readonly List<(string, Type, bool, bool, bool, bool, bool)> OtherColors = new()
+ private static readonly List<(string, Type, bool, bool, bool, bool, bool)> CustomColors = new()
{
( "ColorARGB16", typeof(byte), true, true, true, true, false ),
( "ColorARGB32", typeof(byte), true, true, true, true, true ),
@@ -65,45 +25,49 @@ internal static class Program
( "ColorRGB32Half", typeof(Half), true, true, true, false, false ),
};
+ ///
+ /// Name, Red, Blue, Green, Alpha
+ ///
+ private static readonly List<(string, bool, bool, bool, bool)> GenericColors = new()
+ {
+ ( "ColorR", true, false, false, false ),
+ ( "ColorRG", true, true, false, false ),
+ ( "ColorRGB", true, true, true, false ),
+ ( "ColorRGBA", true, true, true, true ),
+ ( "ColorA", false, false, false, true ),
+ };
+
static void Main()
{
- foreach (var color in Colors)
+ foreach (var customColor in CustomColors)
{
- WriteColor(color);
+ WriteCustomColor(customColor);
}
- foreach (var otherColor in OtherColors)
+ foreach (var genericColor in GenericColors)
{
- WriteOtherColor(otherColor);
+ WriteGenericColor(genericColor);
}
NumericConversionGenerator.Run();
Console.WriteLine("Done!");
}
- private static void WriteColor((string, Type, bool, bool, bool, bool) details)
- {
- (string name, Type type, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha) = details;
- Console.WriteLine(name);
- using FileStream stream = File.Create($"{OutputFolder}{name}.g.cs");
- using StreamWriter streamWriter = new StreamWriter(stream);
- streamWriter.NewLine = "\n";
- using IndentedTextWriter writer = new IndentedTextWriter(streamWriter, "\t");
- writer.NewLine = "\n";
- WriteColor(writer, name, type, hasRed, hasGreen, hasBlue, hasAlpha);
- }
-
- private static void WriteOtherColor((string, Type, bool, bool, bool, bool, bool) details)
+ private static void WriteCustomColor((string, Type, bool, bool, bool, bool, bool) details)
{
(string name, Type type, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha, bool fullyUtilized) = details;
Console.WriteLine(name);
- using FileStream stream = File.Create($"{OutputFolder}{name}.g.cs");
- using StreamWriter streamWriter = new StreamWriter(stream);
- streamWriter.NewLine = "\n";
- using IndentedTextWriter writer = new IndentedTextWriter(streamWriter, "\t");
- writer.NewLine = "\n";
- WriteOtherColor(writer, name, type, hasRed, hasGreen, hasBlue, hasAlpha, fullyUtilized);
+ using IndentedTextWriter writer = IndentedTextWriterFactory.Create(OutputFolder, name);
+ WriteCustomColor(writer, name, type, hasRed, hasGreen, hasBlue, hasAlpha, fullyUtilized);
}
- private static void WriteOtherColor(IndentedTextWriter writer, string name, Type type, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha, bool fullyUtilized)
+ private static void WriteGenericColor((string, bool, bool, bool, bool) details)
+ {
+ (string name, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha) = details;
+ Console.WriteLine(name);
+ using IndentedTextWriter writer = IndentedTextWriterFactory.Create(OutputFolder, name);
+ WriteGenericColor(writer, name, hasRed, hasGreen, hasBlue, hasAlpha);
+ }
+
+ private static void WriteCustomColor(IndentedTextWriter writer, string name, Type type, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha, bool fullyUtilized)
{
string typeName = CSharpPrimitives.TypeNames[type];
writer.WriteLine("//This code is source generated. Do not edit manually.");
@@ -111,19 +75,66 @@ internal static class Program
writer.WriteLine($"using {AttributeNamespace};");
writer.WriteLine();
writer.WriteLine($"namespace {OutputNamespace}");
- writer.WriteLine('{');
- writer.Indent++;
+ using (new CurlyBrackets(writer))
+ {
+ WriteRgbaAttribute(writer, hasRed, hasGreen, hasBlue, hasAlpha, fullyUtilized);
+ writer.WriteLine($"public partial struct {name} : IColor<{typeName}>");
+ using (new CurlyBrackets(writer))
+ {
+ WriteHasChannelStaticProperties(writer, hasRed, hasGreen, hasBlue, hasAlpha, typeName);
+ writer.WriteLineNoTabs();
+ WriteToString(writer, hasRed, hasGreen, hasBlue, hasAlpha);
+ }
+ }
+ }
+ private static void WriteRgbaAttribute(IndentedTextWriter writer, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha, bool fullyUtilized)
+ {
writer.WriteLine($"[RgbaAttribute(RedChannel = {hasRed.ToLowerString()}, GreenChannel = {hasGreen.ToLowerString()}, BlueChannel = {hasBlue.ToLowerString()}, AlphaChannel = {hasAlpha.ToLowerString()}, FullyUtilizedChannels = {fullyUtilized.ToLowerString()})]");
- writer.WriteLine($"public partial struct {name} : IColor<{typeName}>");
- writer.WriteLine('{');
- writer.Indent++;
- WriteHasChannelStaticProperties(writer, hasRed, hasGreen, hasBlue, hasAlpha, typeName);
- writer.Indent--;
- writer.WriteLine('}');
+ }
- writer.Indent--;
- writer.WriteLine('}');
+ private static void WriteToString(IndentedTextWriter writer, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha)
+ {
+ writer.WriteLine("public override string ToString()");
+ using (new CurlyBrackets(writer))
+ {
+ StringBuilder sb = new();
+ sb.Append("return $\"{{ ");
+ bool first = true;
+ if (hasRed)
+ {
+ sb.Append("R: {R}");
+ first = false;
+ }
+ if (hasGreen)
+ {
+ if (!first)
+ {
+ sb.Append(", ");
+ }
+ sb.Append("G: {G}");
+ first = false;
+ }
+ if (hasBlue)
+ {
+ if (!first)
+ {
+ sb.Append(", ");
+ }
+ sb.Append("B: {B}");
+ first = false;
+ }
+ if (hasAlpha)
+ {
+ if (!first)
+ {
+ sb.Append(", ");
+ }
+ sb.Append("A: {A}");
+ }
+ sb.Append(" }}\";");
+ writer.WriteLine(sb.ToString());
+ }
}
private static void WriteHasChannelStaticProperties(IndentedTextWriter writer, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha, string typeName)
@@ -134,81 +145,81 @@ internal static class Program
writer.WriteLine($"static bool IColor<{typeName}>.HasAlphaChannel => {hasAlpha.ToLowerString()};");
}
- private static void WriteColor(IndentedTextWriter writer, string name, Type type, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha)
+ private static void WriteGenericColor(IndentedTextWriter writer, string name, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha)
{
- string typeName = CSharpPrimitives.TypeNames[type];
- writer.WriteLine("//This code is source generated. Do not edit manually.");
- writer.WriteLine();
+ const string typeName = "T";
+ const string minValue = $"NumericConversion.GetMinimumValue()";
+ const string maxValue = $"NumericConversion.GetMaximumValue()";
+
+ writer.WriteGeneratedCodeWarning();
+ writer.WriteLineNoTabs();
+
writer.WriteLine($"using {AttributeNamespace};");
- writer.WriteLine();
- writer.WriteLine($"namespace {OutputNamespace}");
- writer.WriteLine('{');
- writer.Indent++;
+ writer.WriteLineNoTabs();
- writer.WriteLine($"[RgbaAttribute(RedChannel = {hasRed.ToLowerString()}, GreenChannel = {hasGreen.ToLowerString()}, BlueChannel = {hasBlue.ToLowerString()}, AlphaChannel = {hasAlpha.ToLowerString()}, FullyUtilizedChannels = true)]");
- writer.WriteLine($"public partial struct {name} : IColor<{typeName}>");
- writer.WriteLine('{');
- writer.Indent++;
+ writer.WriteFileScopedNamespace(OutputNamespace);
+ writer.WriteLineNoTabs();
- WriteProperty(writer, hasRed, typeName, 'R', CSharpPrimitives.MinimumValues[type]);
- writer.WriteLine();
- WriteProperty(writer, hasGreen, typeName, 'G', CSharpPrimitives.MinimumValues[type]);
- writer.WriteLine();
- WriteProperty(writer, hasBlue, typeName, 'B', CSharpPrimitives.MinimumValues[type]);
- writer.WriteLine();
- WriteProperty(writer, hasAlpha, typeName, 'A', CSharpPrimitives.MaximumValues[type]);
- writer.WriteLine();
+ WriteRgbaAttribute(writer, hasRed, hasGreen, hasBlue, hasAlpha, true);
+ string constraints = hasRed && hasGreen && hasBlue && hasAlpha
+ ? "unmanaged"
+ : "unmanaged, INumberBase, IMinMaxValue";
+ writer.WriteLine($"public partial struct {name} : IColor<{typeName}> where T : {constraints}");
+ using (new CurlyBrackets(writer))
+ {
+ WriteProperty(writer, hasRed, typeName, 'R', minValue);
+ writer.WriteLineNoTabs();
+ WriteProperty(writer, hasGreen, typeName, 'G', minValue);
+ writer.WriteLineNoTabs();
+ WriteProperty(writer, hasBlue, typeName, 'B', minValue);
+ writer.WriteLineNoTabs();
+ WriteProperty(writer, hasAlpha, typeName, 'A', maxValue);
+ writer.WriteLineNoTabs();
- WriteGetChannels(writer, typeName);
- writer.WriteLine();
- WriteSetChannels(writer, type, hasRed, hasGreen, hasBlue, hasAlpha);
- writer.WriteLine();
- WriteHasChannelStaticProperties(writer, hasRed, hasGreen, hasBlue, hasAlpha, typeName);
-
- writer.Indent--;
- writer.WriteLine('}');
-
- writer.Indent--;
- writer.WriteLine('}');
+ WriteGetChannels(writer, typeName);
+ writer.WriteLineNoTabs();
+ WriteSetChannels(writer, typeName, hasRed, hasGreen, hasBlue, hasAlpha);
+ writer.WriteLineNoTabs();
+ WriteHasChannelStaticProperties(writer, hasRed, hasGreen, hasBlue, hasAlpha, typeName);
+ writer.WriteLineNoTabs();
+ WriteToString(writer, hasRed, hasGreen, hasBlue, hasAlpha);
+ }
}
private static void WriteGetChannels(IndentedTextWriter writer, string typeName)
{
writer.WriteLine($"public readonly void GetChannels(out {typeName} r, out {typeName} g, out {typeName} b, out {typeName} a)");
- writer.WriteLine('{');
- writer.Indent++;
- writer.WriteLine("r = R;");
- writer.WriteLine("g = G;");
- writer.WriteLine("b = B;");
- writer.WriteLine("a = A;");
- writer.Indent--;
- writer.WriteLine('}');
+ using (new CurlyBrackets(writer))
+ {
+ writer.WriteLine("r = R;");
+ writer.WriteLine("g = G;");
+ writer.WriteLine("b = B;");
+ writer.WriteLine("a = A;");
+ }
}
- private static void WriteSetChannels(IndentedTextWriter writer, Type type, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha)
+ private static void WriteSetChannels(IndentedTextWriter writer, string typeName, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha)
{
- string typeName = CSharpPrimitives.TypeNames[type];
writer.WriteLine($"public void SetChannels({typeName} r, {typeName} g, {typeName} b, {typeName} a)");
- writer.WriteLine('{');
- writer.Indent++;
- if (hasRed)
+ using (new CurlyBrackets(writer))
{
- writer.WriteLine("R = r;");
+ if (hasRed)
+ {
+ writer.WriteLine("R = r;");
+ }
+ if (hasGreen)
+ {
+ writer.WriteLine("G = g;");
+ }
+ if (hasBlue)
+ {
+ writer.WriteLine("B = b;");
+ }
+ if (hasAlpha)
+ {
+ writer.WriteLine("A = a;");
+ }
}
- if (hasGreen)
- {
- writer.WriteLine("G = g;");
- }
- if (hasBlue)
- {
- writer.WriteLine("B = b;");
- }
- if (hasAlpha)
- {
- writer.WriteLine("A = a;");
- }
- writer.Indent--;
- writer.WriteLine('}');
}
private static void WriteProperty(IndentedTextWriter writer, bool hasColor, string typeName, char channel, string defaultValue)
@@ -220,12 +231,11 @@ internal static class Program
else
{
writer.WriteLine($"public readonly {typeName} {channel} ");
- writer.WriteLine('{');
- writer.Indent++;
- writer.WriteLine($"get => {defaultValue};");
- writer.WriteLine("set { }");
- writer.Indent--;
- writer.WriteLine('}');
+ using (new CurlyBrackets(writer))
+ {
+ writer.WriteLine($"get => {defaultValue};");
+ writer.WriteLine("set { }");
+ }
}
}
diff --git a/AssetRipper.TextureDecoder.ConsoleApp/DirectBitmap.cs b/AssetRipper.TextureDecoder.ConsoleApp/DirectBitmap.cs
index 90640ac..a18420b 100644
--- a/AssetRipper.TextureDecoder.ConsoleApp/DirectBitmap.cs
+++ b/AssetRipper.TextureDecoder.ConsoleApp/DirectBitmap.cs
@@ -96,24 +96,24 @@ public readonly struct DirectBitmap
private void GetDataAndComponentsForSaving(out byte[] data, out ColorComponents components)
{
- if (typeof(TColor) == typeof(ColorRGBA32))
+ if (typeof(TColor) == typeof(ColorRGBA))
{
data = Data;
components = ColorComponents.RedGreenBlueAlpha;
}
- else if (typeof(TColor) == typeof(ColorRGB24))
+ else if (typeof(TColor) == typeof(ColorRGB))
{
data = Data;
components = ColorComponents.RedGreenBlue;
}
else if (TColor.HasAlphaChannel)
{
- RgbConverter.Convert(Bits, Width, Height, out data);
+ RgbConverter.Convert, byte>(Bits, Width, Height, out data);
components = ColorComponents.RedGreenBlueAlpha;
}
else
{
- RgbConverter.Convert(Bits, Width, Height, out data);
+ RgbConverter.Convert, byte>(Bits, Width, Height, out data);
components = ColorComponents.RedGreenBlue;
}
}
diff --git a/AssetRipper.TextureDecoder.ConsoleApp/Program.g.cs b/AssetRipper.TextureDecoder.ConsoleApp/Program.g.cs
index 83edc65..af67f6b 100644
--- a/AssetRipper.TextureDecoder.ConsoleApp/Program.g.cs
+++ b/AssetRipper.TextureDecoder.ConsoleApp/Program.g.cs
@@ -1,4 +1,4 @@
-//This code is source generated. Do not edit manually.
+// Auto-generated code. Do not modify manually.
using AssetRipper.TextureDecoder.Rgb;
using AssetRipper.TextureDecoder.Rgb.Formats;
@@ -9,152 +9,276 @@ static partial class Program
private static void DecodeRgb(ReadOnlySpan input, int width, int height, string modeString, Span output)
{
Console.WriteLine("Arg at index 5 : mode");
- Console.WriteLine(" 0 - A8");
- Console.WriteLine(" 1 - ARGB16");
- Console.WriteLine(" 2 - ARGB32");
- Console.WriteLine(" 3 - BGRA32");
- Console.WriteLine(" 4 - R16");
- Console.WriteLine(" 5 - R16Half");
- Console.WriteLine(" 6 - R16Signed");
- Console.WriteLine(" 7 - R32Single");
- Console.WriteLine(" 8 - R64Double");
- Console.WriteLine(" 9 - R8");
- Console.WriteLine(" 10 - R8Signed");
- Console.WriteLine(" 11 - RG16");
- Console.WriteLine(" 12 - RG32Half");
- Console.WriteLine(" 13 - RG16Signed");
- Console.WriteLine(" 14 - RG32");
- Console.WriteLine(" 15 - RG32Signed");
- Console.WriteLine(" 16 - RG64Single");
- Console.WriteLine(" 17 - RG128Double");
- Console.WriteLine(" 18 - RGB16");
- Console.WriteLine(" 19 - RGB24");
- Console.WriteLine(" 20 - RGB24Signed");
- Console.WriteLine(" 21 - RGB32Half");
- Console.WriteLine(" 22 - RGB48");
- Console.WriteLine(" 23 - RGB48Half");
- Console.WriteLine(" 24 - RGB48Signed");
- Console.WriteLine(" 25 - RGB96Single");
- Console.WriteLine(" 26 - RGB192Double");
- Console.WriteLine(" 27 - RGB9e5");
- Console.WriteLine(" 28 - RGBA128Single");
- Console.WriteLine(" 29 - RGBA16");
- Console.WriteLine(" 30 - RGBA256Double");
- Console.WriteLine(" 31 - RGBA32");
- Console.WriteLine(" 32 - RGBA32Signed");
- Console.WriteLine(" 33 - RGBA64");
- Console.WriteLine(" 34 - RGBA64Half");
- Console.WriteLine(" 35 - RGBA64Signed");
+ Console.WriteLine(" 0 - R8SByte");
+ Console.WriteLine(" 1 - RG8SByte");
+ Console.WriteLine(" 2 - RGB8SByte");
+ Console.WriteLine(" 3 - RGBA8SByte");
+ Console.WriteLine(" 4 - A8SByte");
+ Console.WriteLine(" 5 - R8Byte");
+ Console.WriteLine(" 6 - RG8Byte");
+ Console.WriteLine(" 7 - RGB8Byte");
+ Console.WriteLine(" 8 - RGBA8Byte");
+ Console.WriteLine(" 9 - A8Byte");
+ Console.WriteLine(" 10 - R16Int16");
+ Console.WriteLine(" 11 - RG16Int16");
+ Console.WriteLine(" 12 - RGB16Int16");
+ Console.WriteLine(" 13 - RGBA16Int16");
+ Console.WriteLine(" 14 - A16Int16");
+ Console.WriteLine(" 15 - R16UInt16");
+ Console.WriteLine(" 16 - RG16UInt16");
+ Console.WriteLine(" 17 - RGB16UInt16");
+ Console.WriteLine(" 18 - RGBA16UInt16");
+ Console.WriteLine(" 19 - A16UInt16");
+ Console.WriteLine(" 20 - R32Int32");
+ Console.WriteLine(" 21 - RG32Int32");
+ Console.WriteLine(" 22 - RGB32Int32");
+ Console.WriteLine(" 23 - RGBA32Int32");
+ Console.WriteLine(" 24 - A32Int32");
+ Console.WriteLine(" 25 - R32UInt32");
+ Console.WriteLine(" 26 - RG32UInt32");
+ Console.WriteLine(" 27 - RGB32UInt32");
+ Console.WriteLine(" 28 - RGBA32UInt32");
+ Console.WriteLine(" 29 - A32UInt32");
+ Console.WriteLine(" 30 - R64Int64");
+ Console.WriteLine(" 31 - RG64Int64");
+ Console.WriteLine(" 32 - RGB64Int64");
+ Console.WriteLine(" 33 - RGBA64Int64");
+ Console.WriteLine(" 34 - A64Int64");
+ Console.WriteLine(" 35 - R64UInt64");
+ Console.WriteLine(" 36 - RG64UInt64");
+ Console.WriteLine(" 37 - RGB64UInt64");
+ Console.WriteLine(" 38 - RGBA64UInt64");
+ Console.WriteLine(" 39 - A64UInt64");
+ Console.WriteLine(" 40 - R16Half");
+ Console.WriteLine(" 41 - RG16Half");
+ Console.WriteLine(" 42 - RGB16Half");
+ Console.WriteLine(" 43 - RGBA16Half");
+ Console.WriteLine(" 44 - A16Half");
+ Console.WriteLine(" 45 - R32Single");
+ Console.WriteLine(" 46 - RG32Single");
+ Console.WriteLine(" 47 - RGB32Single");
+ Console.WriteLine(" 48 - RGBA32Single");
+ Console.WriteLine(" 49 - A32Single");
+ Console.WriteLine(" 50 - R64Double");
+ Console.WriteLine(" 51 - RG64Double");
+ Console.WriteLine(" 52 - RGB64Double");
+ Console.WriteLine(" 53 - RGBA64Double");
+ Console.WriteLine(" 54 - A64Double");
+ Console.WriteLine(" 55 - R128Decimal");
+ Console.WriteLine(" 56 - RG128Decimal");
+ Console.WriteLine(" 57 - RGB128Decimal");
+ Console.WriteLine(" 58 - RGBA128Decimal");
+ Console.WriteLine(" 59 - A128Decimal");
+ Console.WriteLine(" 60 - ARGB16");
+ Console.WriteLine(" 61 - ARGB32");
+ Console.WriteLine(" 62 - BGRA32");
+ Console.WriteLine(" 63 - RGB16");
+ Console.WriteLine(" 64 - RGB32Half");
+ Console.WriteLine(" 65 - RGB9e5");
+ Console.WriteLine(" 66 - RGBA16");
int mode = int.Parse(modeString);
switch(mode)
{
case 0:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, sbyte, ColorBGRA32, byte>(input, width, height, output);
break;
case 1:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, sbyte, ColorBGRA32, byte>(input, width, height, output);
break;
case 2:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, sbyte, ColorBGRA32, byte>(input, width, height, output);
break;
case 3:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, sbyte, ColorBGRA32, byte>(input, width, height, output);
break;
case 4:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, sbyte, ColorBGRA32, byte>(input, width, height, output);
break;
case 5:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, byte, ColorBGRA32, byte>(input, width, height, output);
break;
case 6:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, byte, ColorBGRA32, byte>(input, width, height, output);
break;
case 7:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, byte, ColorBGRA32, byte>(input, width, height, output);
break;
case 8:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, byte, ColorBGRA32, byte>(input, width, height, output);
break;
case 9:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, byte, ColorBGRA32, byte>(input, width, height, output);
break;
case 10:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, short, ColorBGRA32, byte>(input, width, height, output);
break;
case 11:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, short, ColorBGRA32, byte>(input, width, height, output);
break;
case 12:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, short, ColorBGRA32, byte>(input, width, height, output);
break;
case 13:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, short, ColorBGRA32, byte>(input, width, height, output);
break;
case 14:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, short, ColorBGRA32, byte>(input, width, height, output);
break;
case 15:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, ushort, ColorBGRA32, byte>(input, width, height, output);
break;
case 16:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, ushort, ColorBGRA32, byte>(input, width, height, output);
break;
case 17:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, ushort, ColorBGRA32, byte>(input, width, height, output);
break;
case 18:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, ushort, ColorBGRA32, byte>(input, width, height, output);
break;
case 19:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, ushort, ColorBGRA32, byte>(input, width, height, output);
break;
case 20:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, int, ColorBGRA32, byte>(input, width, height, output);
break;
case 21:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, int, ColorBGRA32, byte>(input, width, height, output);
break;
case 22:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, int, ColorBGRA32, byte>(input, width, height, output);
break;
case 23:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, int, ColorBGRA32, byte>(input, width, height, output);
break;
case 24:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, int, ColorBGRA32, byte>(input, width, height, output);
break;
case 25:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, uint, ColorBGRA32, byte>(input, width, height, output);
break;
case 26:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, uint, ColorBGRA32, byte>(input, width, height, output);
break;
case 27:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, uint, ColorBGRA32, byte>(input, width, height, output);
break;
case 28:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, uint, ColorBGRA32, byte>(input, width, height, output);
break;
case 29:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, uint, ColorBGRA32, byte>(input, width, height, output);
break;
case 30:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, long, ColorBGRA32, byte>(input, width, height, output);
break;
case 31:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, long, ColorBGRA32, byte>(input, width, height, output);
break;
case 32:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, long, ColorBGRA32, byte>(input, width, height, output);
break;
case 33:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, long, ColorBGRA32, byte>(input, width, height, output);
break;
case 34:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, long, ColorBGRA32, byte>(input, width, height, output);
break;
case 35:
- RgbConverter.Convert(input, width, height, output);
+ RgbConverter.Convert, ulong, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 36:
+ RgbConverter.Convert, ulong, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 37:
+ RgbConverter.Convert, ulong, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 38:
+ RgbConverter.Convert, ulong, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 39:
+ RgbConverter.Convert, ulong, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 40:
+ RgbConverter.Convert, Half, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 41:
+ RgbConverter.Convert, Half, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 42:
+ RgbConverter.Convert, Half, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 43:
+ RgbConverter.Convert, Half, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 44:
+ RgbConverter.Convert, Half, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 45:
+ RgbConverter.Convert, float, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 46:
+ RgbConverter.Convert, float, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 47:
+ RgbConverter.Convert, float, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 48:
+ RgbConverter.Convert, float, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 49:
+ RgbConverter.Convert, float, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 50:
+ RgbConverter.Convert, double, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 51:
+ RgbConverter.Convert, double, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 52:
+ RgbConverter.Convert, double, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 53:
+ RgbConverter.Convert, double, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 54:
+ RgbConverter.Convert, double, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 55:
+ RgbConverter.Convert, decimal, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 56:
+ RgbConverter.Convert, decimal, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 57:
+ RgbConverter.Convert, decimal, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 58:
+ RgbConverter.Convert, decimal, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 59:
+ RgbConverter.Convert, decimal, ColorBGRA32, byte>(input, width, height, output);
+ break;
+ case 60:
+ RgbConverter.Convert(input, width, height, output);
+ break;
+ case 61:
+ RgbConverter.Convert(input, width, height, output);
+ break;
+ case 62:
+ RgbConverter.Convert(input, width, height, output);
+ break;
+ case 63:
+ RgbConverter.Convert(input, width, height, output);
+ break;
+ case 64:
+ RgbConverter.Convert(input, width, height, output);
+ break;
+ case 65:
+ RgbConverter.Convert(input, width, height, output);
+ break;
+ case 66:
+ RgbConverter.Convert(input, width, height, output);
break;
default:
throw new NotSupportedException(mode.ToString());
diff --git a/AssetRipper.TextureDecoder.SourceGeneration.Common/AssetRipper.TextureDecoder.SourceGeneration.Common.csproj b/AssetRipper.TextureDecoder.SourceGeneration.Common/AssetRipper.TextureDecoder.SourceGeneration.Common.csproj
new file mode 100644
index 0000000..6b0142d
--- /dev/null
+++ b/AssetRipper.TextureDecoder.SourceGeneration.Common/AssetRipper.TextureDecoder.SourceGeneration.Common.csproj
@@ -0,0 +1,9 @@
+
+
+
+ net7.0
+ enable
+ enable
+
+
+
diff --git a/AssetRipper.TextureDecoder.ColorGenerator/CSharpPrimitives.cs b/AssetRipper.TextureDecoder.SourceGeneration.Common/CSharpPrimitives.cs
similarity index 52%
rename from AssetRipper.TextureDecoder.ColorGenerator/CSharpPrimitives.cs
rename to AssetRipper.TextureDecoder.SourceGeneration.Common/CSharpPrimitives.cs
index b99ffb9..1fb2ac5 100644
--- a/AssetRipper.TextureDecoder.ColorGenerator/CSharpPrimitives.cs
+++ b/AssetRipper.TextureDecoder.SourceGeneration.Common/CSharpPrimitives.cs
@@ -1,10 +1,11 @@
-using System.Runtime.CompilerServices;
+using System.Diagnostics.CodeAnalysis;
+using System.Runtime.CompilerServices;
-namespace AssetRipper.TextureDecoder.ColorGenerator;
+namespace AssetRipper.TextureDecoder.SourceGeneration.Common;
-internal static class CSharpPrimitives
+public static class CSharpPrimitives
{
- internal static IReadOnlyDictionary MinimumValues { get; } = new Dictionary()
+ public static IReadOnlyDictionary MinimumValues { get; } = new Dictionary()
{
{ typeof(sbyte), "sbyte.MinValue" },
{ typeof(byte), "byte.MinValue" },
@@ -20,7 +21,7 @@ internal static class CSharpPrimitives
{ typeof(decimal), "0m" },
};
- internal static IReadOnlyDictionary MaximumValues { get; } = new Dictionary()
+ public static IReadOnlyDictionary MaximumValues { get; } = new Dictionary()
{
{ typeof(sbyte), "sbyte.MaxValue" },
{ typeof(byte), "byte.MaxValue" },
@@ -36,7 +37,7 @@ internal static class CSharpPrimitives
{ typeof(decimal), "1m" },
};
- internal static IReadOnlyDictionary TypeNames { get; } = new Dictionary()
+ public static IReadOnlyDictionary TypeNames { get; } = new Dictionary()
{
{ typeof(sbyte), "sbyte" },
{ typeof(byte), "byte" },
@@ -52,7 +53,7 @@ internal static class CSharpPrimitives
{ typeof(decimal), "decimal" },
};
- internal static IReadOnlyDictionary Sizes { get; } = new Dictionary()
+ public static IReadOnlyDictionary Sizes { get; } = new Dictionary()
{
{ typeof(sbyte), sizeof(sbyte) },
{ typeof(byte), sizeof(byte) },
@@ -68,7 +69,42 @@ internal static class CSharpPrimitives
{ typeof(decimal), sizeof(decimal) }
};
- internal static IEnumerable Types => TypeNames.Keys;
+ public static IEnumerable Types => TypeNames.Keys;
- internal static Type FirstType { get; } = Types.First();
+ public static Type FirstType { get; } = Types.First();
+
+ public static bool IsFloatingPoint(Type type)
+ {
+ return type == typeof(Half) || type == typeof(float) || type == typeof(double) || type == typeof(decimal);
+ }
+
+ public static bool IsSignedInteger(Type type, [NotNullWhen(true)] out Type? unsignedType)
+ {
+ if (type == typeof(sbyte))
+ {
+ unsignedType = typeof(byte);
+ }
+ else if (type == typeof(short))
+ {
+ unsignedType = typeof(ushort);
+ }
+ else if (type == typeof(int))
+ {
+ unsignedType = typeof(uint);
+ }
+ else if (type == typeof(long))
+ {
+ unsignedType = typeof(ulong);
+ }
+ else
+ {
+ unsignedType = null;
+ }
+ return unsignedType is not null;
+ }
+
+ public static bool IsUnsignedInteger(Type type)
+ {
+ return type == typeof(byte) || type == typeof(ushort) || type == typeof(uint) || type == typeof(ulong);
+ }
}
\ No newline at end of file
diff --git a/AssetRipper.TextureDecoder.TestGenerator/AssetRipper.TextureDecoder.TestGenerator.csproj b/AssetRipper.TextureDecoder.TestGenerator/AssetRipper.TextureDecoder.TestGenerator.csproj
index 360e5a2..35997c7 100644
--- a/AssetRipper.TextureDecoder.TestGenerator/AssetRipper.TextureDecoder.TestGenerator.csproj
+++ b/AssetRipper.TextureDecoder.TestGenerator/AssetRipper.TextureDecoder.TestGenerator.csproj
@@ -8,7 +8,12 @@
+
+
+
+
+
diff --git a/AssetRipper.TextureDecoder.TestGenerator/ColorRandomValues.cs b/AssetRipper.TextureDecoder.TestGenerator/ColorRandomValues.cs
deleted file mode 100644
index cd0baa2..0000000
--- a/AssetRipper.TextureDecoder.TestGenerator/ColorRandomValues.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-namespace AssetRipper.TextureDecoder.TestGenerator
-{
- internal struct ColorRandomValues
- {
- public string DefaultR;
- public string DefaultG;
- public string DefaultB;
- public string DefaultA;
- public string SetValue;
-
- public ColorRandomValues(string defaultR, string defaultG, string defaultB, string defaultA, string setValue)
- {
- DefaultR = defaultR;
- DefaultG = defaultG;
- DefaultB = defaultB;
- DefaultA = defaultA;
- SetValue = setValue;
- }
- }
-}
diff --git a/AssetRipper.TextureDecoder.TestGenerator/GenerationData.cs b/AssetRipper.TextureDecoder.TestGenerator/GenerationData.cs
index 832dd44..8348943 100644
--- a/AssetRipper.TextureDecoder.TestGenerator/GenerationData.cs
+++ b/AssetRipper.TextureDecoder.TestGenerator/GenerationData.cs
@@ -1,5 +1,6 @@
using AssetRipper.TextureDecoder.Attributes;
using AssetRipper.TextureDecoder.Rgb;
+using AssetRipper.TextureDecoder.SourceGeneration.Common;
using System.Reflection;
namespace AssetRipper.TextureDecoder.TestGenerator
@@ -16,57 +17,11 @@ namespace AssetRipper.TextureDecoder.TestGenerator
public bool AlphaChannel { get; }
public bool FullyUtilizedChannels { get; }
- public bool IsFloatingPoint
- {
- get
- {
- return ChannelType == typeof(Half) || ChannelType == typeof(float) || ChannelType == typeof(double);
- }
- }
+ public bool IsFloatingPoint => CSharpPrimitives.IsFloatingPoint(ChannelType);
- public int BitSizePerChannel
- {
- get
- {
- if (ChannelType == typeof(byte) || ChannelType == typeof(sbyte))
- {
- return 8;
- }
- else if (ChannelType == typeof(ushort) || ChannelType == typeof(short) || ChannelType == typeof(Half))
- {
- return 16;
- }
- else if (ChannelType == typeof(float))
- {
- return 32;
- }
- else if (ChannelType == typeof(double))
- {
- return 64;
- }
- else
- {
- throw new NotSupportedException(ChannelType.Name);
- }
- }
- }
+ public int BitSizePerChannel => CSharpPrimitives.Sizes[ChannelType] * 8;
- public string ChannelTypeName
- {
- get
- {
- return ChannelType.Name switch
- {
- "Byte" => "byte",
- "SByte" => "sbyte",
- "UInt16" => "ushort",
- "Int16" => "short",
- "Single" => "float",
- "Double" => "double",
- _ => ChannelType.Name,
- };
- }
- }
+ public string ChannelTypeName => CSharpPrimitives.TypeNames[ChannelType];
public GenerationData(Type colorType, int colorSize)
{
@@ -89,12 +44,7 @@ namespace AssetRipper.TextureDecoder.TestGenerator
return false;
}
- if (!IsFloatingPoint && other.IsFloatingPoint)
- {
- return false;
- }
-
- if (IsFloatingPoint && !other.IsFloatingPoint)
+ if (IsFloatingPoint != other.IsFloatingPoint)
{
return false;
}
diff --git a/AssetRipper.TextureDecoder.TestGenerator/IndentedTextWriterExtensions.cs b/AssetRipper.TextureDecoder.TestGenerator/IndentedTextWriterExtensions.cs
deleted file mode 100644
index d23664d..0000000
--- a/AssetRipper.TextureDecoder.TestGenerator/IndentedTextWriterExtensions.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-using System.CodeDom.Compiler;
-
-internal static class IndentedTextWriterExtensions
-{
- internal static void WriteSourceGenerationDisclaimer(this IndentedTextWriter textWriter)
- {
- textWriter.WriteLine($"//This code is source generated. Do not edit manually.");
- textWriter.WriteLine();
- }
-}
\ No newline at end of file
diff --git a/AssetRipper.TextureDecoder.TestGenerator/Program.cs b/AssetRipper.TextureDecoder.TestGenerator/Program.cs
index d705b45..7f1ceb2 100644
--- a/AssetRipper.TextureDecoder.TestGenerator/Program.cs
+++ b/AssetRipper.TextureDecoder.TestGenerator/Program.cs
@@ -1,5 +1,7 @@
-using AssetRipper.TextureDecoder.Rgb;
+using AssetRipper.Text.SourceGeneration;
+using AssetRipper.TextureDecoder.Rgb;
using AssetRipper.TextureDecoder.Rgb.Formats;
+using AssetRipper.TextureDecoder.SourceGeneration.Common;
using System.CodeDom.Compiler;
namespace AssetRipper.TextureDecoder.TestGenerator
@@ -8,42 +10,13 @@ namespace AssetRipper.TextureDecoder.TestGenerator
{
internal static readonly List dataList = new()
{
- new GenerationData(typeof(ColorA8), 1),
new GenerationData(typeof(ColorARGB16), 2),
new GenerationData(typeof(ColorARGB32), 4),
new GenerationData(typeof(ColorBGRA32), 4),
- new GenerationData(typeof(ColorR16), 2),
- new GenerationData(typeof(ColorR16Half), 2),
- new GenerationData(typeof(ColorR16Signed), 2),
- new GenerationData(typeof(ColorR32Single), 4),
- new GenerationData(typeof(ColorR64Double), 8),
- new GenerationData(typeof(ColorR8), 1),
- new GenerationData(typeof(ColorR8Signed), 1),
- new GenerationData(typeof(ColorRG16), 2),
- new GenerationData(typeof(ColorRG32Half), 4),
- new GenerationData(typeof(ColorRG16Signed), 2),
- new GenerationData(typeof(ColorRG32), 4),
- new GenerationData(typeof(ColorRG32Signed), 4),
- new GenerationData(typeof(ColorRG64Single), 8),
- new GenerationData(typeof(ColorRG128Double), 16),
new GenerationData(typeof(ColorRGB16), 2),
- new GenerationData(typeof(ColorRGB24), 3),
- new GenerationData(typeof(ColorRGB24Signed), 3),
new GenerationData(typeof(ColorRGB32Half), 4),
- new GenerationData(typeof(ColorRGB48), 6),
- new GenerationData(typeof(ColorRGB48Half), 6),
- new GenerationData(typeof(ColorRGB48Signed), 6),
- new GenerationData(typeof(ColorRGB96Single), 12),
- new GenerationData(typeof(ColorRGB192Double), 24),
new GenerationData(typeof(ColorRGB9e5), 4),
- new GenerationData(typeof(ColorRGBA128Single), 16),
new GenerationData(typeof(ColorRGBA16), 2),
- new GenerationData(typeof(ColorRGBA256Double), 32),
- new GenerationData(typeof(ColorRGBA32), 4),
- new GenerationData(typeof(ColorRGBA32Signed), 4),
- new GenerationData(typeof(ColorRGBA64), 8),
- new GenerationData(typeof(ColorRGBA64Half), 8),
- new GenerationData(typeof(ColorRGBA64Signed), 8),
};
static void Main()
@@ -55,64 +28,69 @@ namespace AssetRipper.TextureDecoder.TestGenerator
private static void GenerateRgbConsoleMethod()
{
- StringWriter streamWriter = new();
- IndentedTextWriter textWriter = new IndentedTextWriter(streamWriter, "\t");
- streamWriter.NewLine = "\n";
- textWriter.NewLine = "\n";
-
- textWriter.WriteSourceGenerationDisclaimer();
- textWriter.WriteLine($"using {typeof(RgbConverter).Namespace};");
- textWriter.WriteLine($"using {typeof(ColorBGRA32).Namespace};");
- textWriter.WriteLine();
-
- textWriter.WriteLine("namespace AssetRipper.TextureDecoder.ConsoleApp;");
- textWriter.WriteLine("static partial class Program");
- textWriter.WriteLine("{");
- textWriter.Indent++;
-
- textWriter.WriteLine("private static void DecodeRgb(ReadOnlySpan input, int width, int height, string modeString, Span output)");
- textWriter.WriteLine("{");
- textWriter.Indent++;
-
- textWriter.WriteLine("Console.WriteLine(\"Arg at index 5 : mode\");");
- for (int i = 0; i < dataList.Count; i++)
- {
- textWriter.WriteLine($"Console.WriteLine(\" {i} - {dataList[i].ColorType.Name.Substring(5)}\");");
- }
- textWriter.WriteLine("int mode = int.Parse(modeString);");
- textWriter.WriteLine("switch(mode)");
- textWriter.WriteLine("{");
- textWriter.Indent++;
-
- for (int i = 0; i < dataList.Count; i++)
- {
- textWriter.WriteLine($"case {i}:");
- textWriter.Indent++;
- GenerationData data = dataList[i];
- textWriter.WriteLine($"RgbConverter.Convert<{data.ColorType.Name}, {data.ChannelTypeName}, ColorBGRA32, byte>(input, width, height, output);");
- textWriter.WriteLine("break;");
- textWriter.Indent--;
- }
- {
- textWriter.WriteLine("default:");
- textWriter.Indent++;
- textWriter.WriteLine("throw new NotSupportedException(mode.ToString());");
- textWriter.Indent--;
- }
-
- textWriter.Indent--;
- textWriter.WriteLine("}");
-
- textWriter.Indent--;
- textWriter.WriteLine("}");
-
- textWriter.Indent--;
- textWriter.WriteLine("}");
-
- textWriter.Flush();
- streamWriter.Flush();
- File.WriteAllText("../../../../AssetRipper.TextureDecoder.ConsoleApp/Program.g.cs", streamWriter.ToString());
Console.WriteLine("Program");
+ using IndentedTextWriter writer = IndentedTextWriterFactory.Create("../../../../AssetRipper.TextureDecoder.ConsoleApp", "Program");
+
+ writer.WriteGeneratedCodeWarning();
+ writer.WriteLine();
+ writer.WriteLine($"using {typeof(RgbConverter).Namespace};");
+ writer.WriteLine($"using {typeof(ColorBGRA32).Namespace};");
+ writer.WriteLine();
+
+ writer.WriteFileScopedNamespace("AssetRipper.TextureDecoder.ConsoleApp");
+ writer.WriteLine("static partial class Program");
+ using (new CurlyBrackets(writer))
+ {
+ writer.WriteLine("private static void DecodeRgb(ReadOnlySpan input, int width, int height, string modeString, Span output)");
+ using (new CurlyBrackets(writer))
+ {
+ List<(string, string, string)> list = GetColorNames().ToList();
+ writer.WriteLine("Console.WriteLine(\"Arg at index 5 : mode\");");
+ for (int i = 0; i < list.Count; i++)
+ {
+ writer.WriteLine($"Console.WriteLine(\" {i} - {list[i].Item1.Substring(5)}\");");
+ }
+ writer.WriteLine("int mode = int.Parse(modeString);");
+ writer.WriteLine("switch(mode)");
+ using (new CurlyBrackets(writer))
+ {
+ for (int i = 0 ; i < list.Count; i++)
+ {
+ (string prettyName, string colorName, string channelName) = list[i];
+ writer.WriteLine($"case {i}:");
+ using (new IndentedBlock(writer))
+ {
+ writer.WriteLine($"RgbConverter.Convert<{colorName}, {channelName}, ColorBGRA32, byte>(input, width, height, output);");
+ writer.WriteLine("break;");
+ }
+ }
+ {
+ writer.WriteLine("default:");
+ using (new IndentedBlock(writer))
+ {
+ writer.WriteLine("throw new NotSupportedException(mode.ToString());");
+ }
+ }
+ }
+ }
+ }
+
+ static IEnumerable<(string, string, string)> GetColorNames()
+ {
+ foreach ((Type primitiveType, string primitiveName) in CSharpPrimitives.TypeNames)
+ {
+ int primitiveBitSize = CSharpPrimitives.Sizes[primitiveType] * 8;
+ foreach (string genericColorName in TestClassGenerator.GetGenericColorNames())
+ {
+ string prettyName = $"{genericColorName}{primitiveBitSize}{primitiveType.Name}";
+ yield return (prettyName, $"{genericColorName}<{primitiveName}>", primitiveName);
+ }
+ }
+ foreach (GenerationData data in dataList)
+ {
+ yield return (data.ColorType.Name, data.ColorType.Name, data.ChannelTypeName);
+ }
+ }
}
}
}
\ No newline at end of file
diff --git a/AssetRipper.TextureDecoder.TestGenerator/TestClassGenerator.cs b/AssetRipper.TextureDecoder.TestGenerator/TestClassGenerator.cs
index 77e0ab5..09a3af0 100644
--- a/AssetRipper.TextureDecoder.TestGenerator/TestClassGenerator.cs
+++ b/AssetRipper.TextureDecoder.TestGenerator/TestClassGenerator.cs
@@ -1,4 +1,7 @@
-using AssetRipper.TextureDecoder.Rgb;
+using AssetRipper.Text.SourceGeneration;
+using AssetRipper.TextureDecoder.Rgb;
+using AssetRipper.TextureDecoder.Rgb.Formats;
+using AssetRipper.TextureDecoder.SourceGeneration.Common;
using AssetRipper.TextureDecoder.TestGenerator;
using System.CodeDom.Compiler;
@@ -9,51 +12,86 @@ internal static class TestClassGenerator
private static readonly char[] channels = new char[] { 'R', 'G', 'B', 'A' };
- private static readonly Dictionary randomValueDictionary = new()
- {
- { typeof(sbyte), new ColorRandomValues("-0b01010101", "0b01110010", "-0b00001111", "-0b01000111", "0b01001110") },
- { typeof(byte), new ColorRandomValues("0b11010101", "0b01110010", "0b10001111", "0b11000111", "0b01001110") },
- { typeof(short), new ColorRandomValues("-24000", "21354", "-80", "347", "31871") },
- { typeof(ushort), new ColorRandomValues("44000", "21354", "60080", "347", "33871") },
- { typeof(Half), new ColorRandomValues("(Half)0.447f", "(Half)0.224f", "(Half)0.95f", "(Half)0.897f", "(Half)0.333f") },
- { typeof(float), new ColorRandomValues("0.447f", "0.224f", "0.95f", "0.897f", "0.333f") },
- { typeof(double), new ColorRandomValues("0.447", "0.224", "0.95", "0.897", "0.333") },
- };
-
internal static void GenerateTestClasses()
{
Directory.CreateDirectory(OutputFolder);
-
+ MakeGenericColorTests();
+ MakeLosslessColorTests();
foreach (GenerationData data in Program.dataList)
{
using StringWriter streamWriter = new();
using IndentedTextWriter textWriter = new IndentedTextWriter(streamWriter, "\t");
streamWriter.NewLine = "\n";
textWriter.NewLine = "\n";
- textWriter.WriteSourceGenerationDisclaimer();
- textWriter.WriteNamespaceUsings(data);
+ textWriter.WriteGeneratedCodeWarning();
+ textWriter.WriteLineNoTabs();
+ textWriter.WriteNamespaceUsings(data.ColorType.Namespace);
textWriter.WriteFileScopedNamespace();
textWriter.WriteClassDefinitionOpen(data);
textWriter.Indent++;
textWriter.WriteCorrectSizeTest(data);
- textWriter.WriteLine();
+ textWriter.WriteLineNoTabs();
textWriter.WritePropertySymmetryTests(data);
textWriter.WriteIndependenceTests(data);
textWriter.WriteGetMethodMatchesProperties();
- textWriter.WriteLine();
+ textWriter.WriteLineNoTabs();
textWriter.WriteMethodSymmetryTest();
- textWriter.WriteLine();
+ textWriter.WriteLineNoTabs();
textWriter.WriteMakeRandomColor(data);
+ textWriter.WriteLineNoTabs();
+ textWriter.WriteMakeRandomValue(data);
foreach (GenerationData otherData in Program.dataList)
{
if (otherData.Contains(data))
{
- textWriter.WriteLine();
+ textWriter.WriteLineNoTabs();
textWriter.WriteLosslessConversionTest(data, otherData);
}
}
+ foreach ((Type channelType, string channelTypeName) in CSharpPrimitives.TypeNames)
+ {
+ if (CSharpPrimitives.IsFloatingPoint(channelType) != CSharpPrimitives.IsFloatingPoint(data.ChannelType))
+ {
+ continue;
+ }
+
+ if (channelType == typeof(decimal) || data.ChannelType == typeof(decimal))
+ {
+ continue;
+ }
+
+ if (CSharpPrimitives.Sizes[data.ChannelType] > CSharpPrimitives.Sizes[channelType])
+ {
+ continue;
+ }
+
+ textWriter.WriteLineNoTabs();
+ textWriter.WriteLosslessConversionTest(data.ColorType.Name, data.ChannelTypeName, $"{nameof(ColorRGBA)}<{channelTypeName}>", channelTypeName);
+
+ if (!data.AlphaChannel)
+ {
+ textWriter.WriteLineNoTabs();
+ textWriter.WriteLosslessConversionTest(data.ColorType.Name, data.ChannelTypeName, $"{nameof(ColorRGB)}<{channelTypeName}>", channelTypeName);
+ if (!data.BlueChannel)
+ {
+ textWriter.WriteLineNoTabs();
+ textWriter.WriteLosslessConversionTest(data.ColorType.Name, data.ChannelTypeName, $"{nameof(ColorRG)}<{channelTypeName}>", channelTypeName);
+ if (!data.GreenChannel)
+ {
+ textWriter.WriteLineNoTabs();
+ textWriter.WriteLosslessConversionTest(data.ColorType.Name, data.ChannelTypeName, $"{nameof(ColorR)}<{channelTypeName}>", channelTypeName);
+ }
+ }
+ }
+ if (!data.RedChannel && !data.GreenChannel && !data.BlueChannel)
+ {
+ textWriter.WriteLineNoTabs();
+ textWriter.WriteLosslessConversionTest(data.ColorType.Name, data.ChannelTypeName, $"{nameof(ColorA)}<{channelTypeName}>", channelTypeName);
+ }
+ }
+
textWriter.Indent--;
textWriter.WriteClassDefinitionClose();
@@ -66,6 +104,76 @@ internal static class TestClassGenerator
}
}
+ private static void MakeGenericColorTests()
+ {
+ using IndentedTextWriter writer = IndentedTextWriterFactory.Create(OutputFolder, "GenericColorTests");
+ writer.WriteGeneratedCodeWarning();
+ writer.WriteLine();
+ writer.WriteUsing(typeof(ColorR<>).Namespace!);
+ writer.WriteLine();
+ writer.WriteFileScopedNamespace();
+
+ foreach (string channeName in CSharpPrimitives.TypeNames.Values)
+ {
+ foreach (string colorName in GetGenericColorNames())
+ {
+ writer.WriteLine($"[TestFixture(TypeArgs = new Type[] {{ typeof({colorName}<{channeName}>), typeof({channeName}) }})]");
+ }
+ }
+ writer.WriteLine("partial class GenericColorTests");
+ using (new CurlyBrackets(writer))
+ {
+ }
+ }
+
+ internal static IEnumerable GetGenericColorNames()
+ {
+ yield return nameof(ColorR);
+ yield return nameof(ColorRG);
+ yield return nameof(ColorRGB);
+ yield return nameof(ColorRGBA);
+ yield return nameof(ColorA);
+ }
+
+ private static void MakeLosslessColorTests()
+ {
+ using IndentedTextWriter writer = IndentedTextWriterFactory.Create(OutputFolder, "LosslessColorTests");
+ writer.WriteGeneratedCodeWarning();
+ writer.WriteLine();
+ writer.WriteUsing(typeof(ColorR<>).Namespace!);
+ writer.WriteLine();
+ writer.WriteFileScopedNamespace();
+
+ foreach ((Type t1, string t1Name) in CSharpPrimitives.TypeNames)
+ {
+ foreach ((Type t2, string t2Name) in CSharpPrimitives.TypeNames)
+ {
+ if (CSharpPrimitives.IsFloatingPoint(t1) != CSharpPrimitives.IsFloatingPoint(t2))
+ {
+ // one is floating point, the other is not
+ continue;
+ }
+
+ if (t1 == typeof(decimal) || t2 == typeof(decimal))
+ {
+ // decimal has rounding errors when converting to/from double and float
+ continue;
+ }
+
+ if (CSharpPrimitives.Sizes[t1] > CSharpPrimitives.Sizes[t2])
+ {
+ continue;
+ }
+
+ writer.WriteLine($"[TestFixture(TypeArgs = new Type[] {{ typeof({t1Name}), typeof({t2Name}) }})]");
+ }
+ }
+ writer.WriteLine("partial class LosslessColorTests");
+ using (new CurlyBrackets(writer))
+ {
+ }
+ }
+
private static void WriteClassDefinitionClose(this IndentedTextWriter textWriter)
{
textWriter.WriteLine("}");
@@ -131,7 +239,7 @@ internal static class TestClassGenerator
{
textWriter.WriteLine($"var {char.ToLowerInvariant(otherChannel)} = color.{otherChannel};");
}
- textWriter.WriteLine($"color.{channel} = {randomValueDictionary[data.ChannelType].SetValue};");
+ textWriter.WriteLine($"color.{channel} = MakeRandomValue();");
textWriter.WriteLine("Assert.Multiple(() =>");
textWriter.WriteLine("{");
@@ -160,44 +268,27 @@ internal static class TestClassGenerator
private static void WriteLosslessConversionTest(this IndentedTextWriter textWriter, GenerationData currentData, GenerationData containingData)
{
- string currentName = currentData.ColorType.Name;
- string containingName = containingData.ColorType.Name;
+ textWriter.WriteLosslessConversionTest(currentData.ColorType.Name, currentData.ChannelTypeName, containingData.ColorType.Name, containingData.ChannelTypeName);
+ }
- textWriter.WriteLine("[Test]");
- textWriter.WriteLine($"public void ConversionTo{containingName}IsLossless()");
- textWriter.WriteLine("{");
- textWriter.Indent += 1;
-
- textWriter.WriteLine($"{currentName} original = MakeRandomColor();");
- textWriter.WriteLine($"{containingName} converted = original.{nameof(ColorExtensions.Convert)}<{currentName}, {currentData.ChannelTypeName}, {containingName}, {containingData.ChannelTypeName}>();");
- textWriter.WriteLine($"{currentName} convertedBack = converted.{nameof(ColorExtensions.Convert)}<{containingName}, {containingData.ChannelTypeName}, {currentName}, {currentData.ChannelTypeName}>();");
- textWriter.WriteLine("Assert.That(convertedBack, Is.EqualTo(original));");
-
- textWriter.Indent -= 1;
- textWriter.WriteLine("}");
+ private static void WriteLosslessConversionTest(this IndentedTextWriter writer, string t1Color, string t1Channel, string t2Color, string t2Channel)
+ {
+ writer.WriteLine("[Test]");
+ writer.WriteLine($"public void ConversionIsLosslessTo{t2Color.Replace("<","_").Replace(">", "")}()");
+ using (new CurlyBrackets(writer))
+ {
+ writer.WriteLine($"LosslessConversion.Assert<{t1Color}, {t1Channel}, {t2Color}, {t2Channel}>();");
+ }
}
private static void WriteMakeRandomColor(this IndentedTextWriter textWriter, GenerationData data)
{
- textWriter.WriteLine($"public static {data.ColorType.Name} MakeRandomColor()");
- textWriter.WriteLine("{");
- textWriter.Indent += 1;
+ textWriter.WriteLine($"public static {data.ColorType.Name} MakeRandomColor() => ColorRandom<{data.ColorType.Name}, {data.ChannelTypeName}>.MakeRandomColor();");
+ }
- textWriter.WriteLine("return new()");
- textWriter.WriteLine("{");
- textWriter.Indent += 1;
-
- ColorRandomValues randomValues = randomValueDictionary[data.ChannelType];
- textWriter.WriteLine($"R = {randomValues.DefaultR},");
- textWriter.WriteLine($"G = {randomValues.DefaultG},");
- textWriter.WriteLine($"B = {randomValues.DefaultB},");
- textWriter.WriteLine($"A = {randomValues.DefaultA},");
-
- textWriter.Indent -= 1;
- textWriter.WriteLine("};");
-
- textWriter.Indent -= 1;
- textWriter.WriteLine("}");
+ private static void WriteMakeRandomValue(this IndentedTextWriter textWriter, GenerationData data)
+ {
+ textWriter.WriteLine($"public static {data.ChannelTypeName} MakeRandomValue() => ColorRandom<{data.ColorType.Name}, {data.ChannelTypeName}>.MakeRandomValue();");
}
private static void WriteMethodSymmetryTest(this IndentedTextWriter textWriter)
@@ -226,10 +317,9 @@ internal static class TestClassGenerator
textWriter.WriteLine("}");
}
- private static void WriteNamespaceUsings(this IndentedTextWriter textWriter, GenerationData data)
+ private static void WriteNamespaceUsings(this IndentedTextWriter textWriter, string? colorNamespace)
{
- textWriter.WriteLine($"using {typeof(ColorExtensions).Namespace};");
- textWriter.WriteLine($"using {data.ColorType.Namespace};");
+ textWriter.WriteLine($"using {colorNamespace};");
textWriter.WriteLine($"using {typeof(System.Runtime.CompilerServices.Unsafe).Namespace};");
textWriter.WriteLine();//An empty line after the usings
}
diff --git a/AssetRipper.TextureDecoder.Tests/Formats/ColorA8Tests.g.cs b/AssetRipper.TextureDecoder.Tests/Formats/ColorA8Tests.g.cs
deleted file mode 100644
index 0bf1fd4..0000000
--- a/AssetRipper.TextureDecoder.Tests/Formats/ColorA8Tests.g.cs
+++ /dev/null
@@ -1,219 +0,0 @@
-//This code is source generated. Do not edit manually.
-
-using AssetRipper.TextureDecoder.Rgb;
-using AssetRipper.TextureDecoder.Rgb.Formats;
-using System.Runtime.CompilerServices;
-
-namespace AssetRipper.TextureDecoder.Tests.Formats;
-
-public partial class ColorA8Tests
-{
- [Test]
- public void CorrectSizeTest()
- {
- Assert.That(Unsafe.SizeOf(), Is.EqualTo(1));
- }
-
- [Test]
- public void PropertyIsSymmetric_R()
- {
- var color = MakeRandomColor();
- var r = color.R;
- color.R = r;
- Assert.That(color.R, Is.EqualTo(r));
- }
-
- [Test]
- public void PropertyIsSymmetric_G()
- {
- var color = MakeRandomColor();
- var g = color.G;
- color.G = g;
- Assert.That(color.G, Is.EqualTo(g));
- }
-
- [Test]
- public void PropertyIsSymmetric_B()
- {
- var color = MakeRandomColor();
- var b = color.B;
- color.B = b;
- Assert.That(color.B, Is.EqualTo(b));
- }
-
- [Test]
- public void PropertyIsSymmetric_A()
- {
- var color = MakeRandomColor();
- var a = color.A;
- color.A = a;
- Assert.That(color.A, Is.EqualTo(a));
- }
-
- [Test]
- public void ChannelsAreIndependent_R()
- {
- var color = MakeRandomColor();
- var g = color.G;
- var b = color.B;
- var a = color.A;
- color.R = 0b01001110;
- Assert.Multiple(() =>
- {
- Assert.That(color.G, Is.EqualTo(g));
- Assert.That(color.B, Is.EqualTo(b));
- Assert.That(color.A, Is.EqualTo(a));
- });
- }
-
- [Test]
- public void ChannelsAreIndependent_G()
- {
- var color = MakeRandomColor();
- var r = color.R;
- var b = color.B;
- var a = color.A;
- color.G = 0b01001110;
- Assert.Multiple(() =>
- {
- Assert.That(color.R, Is.EqualTo(r));
- Assert.That(color.B, Is.EqualTo(b));
- Assert.That(color.A, Is.EqualTo(a));
- });
- }
-
- [Test]
- public void ChannelsAreIndependent_B()
- {
- var color = MakeRandomColor();
- var r = color.R;
- var g = color.G;
- var a = color.A;
- color.B = 0b01001110;
- Assert.Multiple(() =>
- {
- Assert.That(color.R, Is.EqualTo(r));
- Assert.That(color.G, Is.EqualTo(g));
- Assert.That(color.A, Is.EqualTo(a));
- });
- }
-
- [Test]
- public void ChannelsAreIndependent_A()
- {
- var color = MakeRandomColor();
- var r = color.R;
- var g = color.G;
- var b = color.B;
- color.A = 0b01001110;
- Assert.Multiple(() =>
- {
- Assert.That(color.R, Is.EqualTo(r));
- Assert.That(color.G, Is.EqualTo(g));
- Assert.That(color.B, Is.EqualTo(b));
- });
- }
-
- [Test]
- public void GetMethodMatchesProperties()
- {
- var color = MakeRandomColor();
- color.GetChannels(out var r, out var g, out var b, out var a);
- Assert.Multiple(() =>
- {
- Assert.That(color.R, Is.EqualTo(r));
- Assert.That(color.G, Is.EqualTo(g));
- Assert.That(color.B, Is.EqualTo(b));
- Assert.That(color.A, Is.EqualTo(a));
- });
- }
-
- [Test]
- public void MethodsAreSymmetric()
- {
- var color = MakeRandomColor();
- color.GetChannels(out var r, out var g, out var b, out var a);
- color.SetChannels(r, g, b, a);
- Assert.Multiple(() =>
- {
- Assert.That(color.R, Is.EqualTo(r));
- Assert.That(color.G, Is.EqualTo(g));
- Assert.That(color.B, Is.EqualTo(b));
- Assert.That(color.A, Is.EqualTo(a));
- });
- }
-
- public static ColorA8 MakeRandomColor()
- {
- return new()
- {
- R = 0b11010101,
- G = 0b01110010,
- B = 0b10001111,
- A = 0b11000111,
- };
- }
-
- [Test]
- public void ConversionToColorA8IsLossless()
- {
- ColorA8 original = MakeRandomColor();
- ColorA8 converted = original.Convert();
- ColorA8 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
- }
-
- [Test]
- public void ConversionToColorARGB32IsLossless()
- {
- ColorA8 original = MakeRandomColor();
- ColorARGB32 converted = original.Convert();
- ColorA8 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
- }
-
- [Test]
- public void ConversionToColorBGRA32IsLossless()
- {
- ColorA8 original = MakeRandomColor();
- ColorBGRA32 converted = original.Convert();
- ColorA8 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
- }
-
- [Test]
- public void ConversionToColorRGBA32IsLossless()
- {
- ColorA8 original = MakeRandomColor();
- ColorRGBA32 converted = original.Convert();
- ColorA8 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
- }
-
- [Test]
- public void ConversionToColorRGBA32SignedIsLossless()
- {
- ColorA8 original = MakeRandomColor();
- ColorRGBA32Signed converted = original.Convert();
- ColorA8 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
- }
-
- [Test]
- public void ConversionToColorRGBA64IsLossless()
- {
- ColorA8 original = MakeRandomColor();
- ColorRGBA64 converted = original.Convert();
- ColorA8 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
- }
-
- [Test]
- public void ConversionToColorRGBA64SignedIsLossless()
- {
- ColorA8 original = MakeRandomColor();
- ColorRGBA64Signed converted = original.Convert();
- ColorA8 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
- }
-}
diff --git a/AssetRipper.TextureDecoder.Tests/Formats/ColorARGB16Tests.g.cs b/AssetRipper.TextureDecoder.Tests/Formats/ColorARGB16Tests.g.cs
index cc09ba6..19b496b 100644
--- a/AssetRipper.TextureDecoder.Tests/Formats/ColorARGB16Tests.g.cs
+++ b/AssetRipper.TextureDecoder.Tests/Formats/ColorARGB16Tests.g.cs
@@ -1,6 +1,5 @@
-//This code is source generated. Do not edit manually.
+// Auto-generated code. Do not modify manually.
-using AssetRipper.TextureDecoder.Rgb;
using AssetRipper.TextureDecoder.Rgb.Formats;
using System.Runtime.CompilerServices;
@@ -13,7 +12,7 @@ public partial class ColorARGB16Tests
{
Assert.That(Unsafe.SizeOf(), Is.EqualTo(2));
}
-
+
[Test]
public void PropertyIsSymmetric_R()
{
@@ -57,7 +56,7 @@ public partial class ColorARGB16Tests
var g = color.G;
var b = color.B;
var a = color.A;
- color.R = 0b01001110;
+ color.R = MakeRandomValue();
Assert.Multiple(() =>
{
Assert.That(color.G, Is.EqualTo(g));
@@ -73,7 +72,7 @@ public partial class ColorARGB16Tests
var r = color.R;
var b = color.B;
var a = color.A;
- color.G = 0b01001110;
+ color.G = MakeRandomValue();
Assert.Multiple(() =>
{
Assert.That(color.R, Is.EqualTo(r));
@@ -89,7 +88,7 @@ public partial class ColorARGB16Tests
var r = color.R;
var g = color.G;
var a = color.A;
- color.B = 0b01001110;
+ color.B = MakeRandomValue();
Assert.Multiple(() =>
{
Assert.That(color.R, Is.EqualTo(r));
@@ -105,7 +104,7 @@ public partial class ColorARGB16Tests
var r = color.R;
var g = color.G;
var b = color.B;
- color.A = 0b01001110;
+ color.A = MakeRandomValue();
Assert.Multiple(() =>
{
Assert.That(color.R, Is.EqualTo(r));
@@ -127,7 +126,7 @@ public partial class ColorARGB16Tests
Assert.That(color.A, Is.EqualTo(a));
});
}
-
+
[Test]
public void MethodsAreSymmetric()
{
@@ -142,69 +141,68 @@ public partial class ColorARGB16Tests
Assert.That(color.A, Is.EqualTo(a));
});
}
-
- public static ColorARGB16 MakeRandomColor()
- {
- return new()
- {
- R = 0b11010101,
- G = 0b01110010,
- B = 0b10001111,
- A = 0b11000111,
- };
- }
-
+
+ public static ColorARGB16 MakeRandomColor() => ColorRandom.MakeRandomColor();
+
+ public static byte MakeRandomValue() => ColorRandom.MakeRandomValue();
+
[Test]
- public void ConversionToColorARGB32IsLossless()
+ public void ConversionIsLosslessToColorARGB32()
{
- ColorARGB16 original = MakeRandomColor();
- ColorARGB32 converted = original.Convert();
- ColorARGB16 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
+ LosslessConversion.Assert();
}
-
+
[Test]
- public void ConversionToColorBGRA32IsLossless()
+ public void ConversionIsLosslessToColorBGRA32()
{
- ColorARGB16 original = MakeRandomColor();
- ColorBGRA32 converted = original.Convert();
- ColorARGB16 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
+ LosslessConversion.Assert();
}
-
+
[Test]
- public void ConversionToColorRGBA32IsLossless()
+ public void ConversionIsLosslessToColorRGBA_sbyte()
{
- ColorARGB16 original = MakeRandomColor();
- ColorRGBA32 converted = original.Convert();
- ColorARGB16 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
+ LosslessConversion.Assert, sbyte>();
}
-
+
[Test]
- public void ConversionToColorRGBA32SignedIsLossless()
+ public void ConversionIsLosslessToColorRGBA_byte()
{
- ColorARGB16 original = MakeRandomColor();
- ColorRGBA32Signed converted = original.Convert();
- ColorARGB16 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
+ LosslessConversion.Assert, byte>();
}
-
+
[Test]
- public void ConversionToColorRGBA64IsLossless()
+ public void ConversionIsLosslessToColorRGBA_short()
{
- ColorARGB16 original = MakeRandomColor();
- ColorRGBA64 converted = original.Convert();
- ColorARGB16 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
+ LosslessConversion.Assert, short>();
}
-
+
[Test]
- public void ConversionToColorRGBA64SignedIsLossless()
+ public void ConversionIsLosslessToColorRGBA_ushort()
{
- ColorARGB16 original = MakeRandomColor();
- ColorRGBA64Signed converted = original.Convert();
- ColorARGB16 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
+ LosslessConversion.Assert, ushort>();
+ }
+
+ [Test]
+ public void ConversionIsLosslessToColorRGBA_int()
+ {
+ LosslessConversion.Assert, int>();
+ }
+
+ [Test]
+ public void ConversionIsLosslessToColorRGBA_uint()
+ {
+ LosslessConversion.Assert, uint>();
+ }
+
+ [Test]
+ public void ConversionIsLosslessToColorRGBA_long()
+ {
+ LosslessConversion.Assert, long>();
+ }
+
+ [Test]
+ public void ConversionIsLosslessToColorRGBA_ulong()
+ {
+ LosslessConversion.Assert, ulong>();
}
}
diff --git a/AssetRipper.TextureDecoder.Tests/Formats/ColorARGB32Tests.g.cs b/AssetRipper.TextureDecoder.Tests/Formats/ColorARGB32Tests.g.cs
index 512ff56..ea86c86 100644
--- a/AssetRipper.TextureDecoder.Tests/Formats/ColorARGB32Tests.g.cs
+++ b/AssetRipper.TextureDecoder.Tests/Formats/ColorARGB32Tests.g.cs
@@ -1,6 +1,5 @@
-//This code is source generated. Do not edit manually.
+// Auto-generated code. Do not modify manually.
-using AssetRipper.TextureDecoder.Rgb;
using AssetRipper.TextureDecoder.Rgb.Formats;
using System.Runtime.CompilerServices;
@@ -13,7 +12,7 @@ public partial class ColorARGB32Tests
{
Assert.That(Unsafe.SizeOf(), Is.EqualTo(4));
}
-
+
[Test]
public void PropertyIsSymmetric_R()
{
@@ -57,7 +56,7 @@ public partial class ColorARGB32Tests
var g = color.G;
var b = color.B;
var a = color.A;
- color.R = 0b01001110;
+ color.R = MakeRandomValue();
Assert.Multiple(() =>
{
Assert.That(color.G, Is.EqualTo(g));
@@ -73,7 +72,7 @@ public partial class ColorARGB32Tests
var r = color.R;
var b = color.B;
var a = color.A;
- color.G = 0b01001110;
+ color.G = MakeRandomValue();
Assert.Multiple(() =>
{
Assert.That(color.R, Is.EqualTo(r));
@@ -89,7 +88,7 @@ public partial class ColorARGB32Tests
var r = color.R;
var g = color.G;
var a = color.A;
- color.B = 0b01001110;
+ color.B = MakeRandomValue();
Assert.Multiple(() =>
{
Assert.That(color.R, Is.EqualTo(r));
@@ -105,7 +104,7 @@ public partial class ColorARGB32Tests
var r = color.R;
var g = color.G;
var b = color.B;
- color.A = 0b01001110;
+ color.A = MakeRandomValue();
Assert.Multiple(() =>
{
Assert.That(color.R, Is.EqualTo(r));
@@ -127,7 +126,7 @@ public partial class ColorARGB32Tests
Assert.That(color.A, Is.EqualTo(a));
});
}
-
+
[Test]
public void MethodsAreSymmetric()
{
@@ -142,69 +141,68 @@ public partial class ColorARGB32Tests
Assert.That(color.A, Is.EqualTo(a));
});
}
-
- public static ColorARGB32 MakeRandomColor()
- {
- return new()
- {
- R = 0b11010101,
- G = 0b01110010,
- B = 0b10001111,
- A = 0b11000111,
- };
- }
-
+
+ public static ColorARGB32 MakeRandomColor() => ColorRandom.MakeRandomColor();
+
+ public static byte MakeRandomValue() => ColorRandom.MakeRandomValue();
+
[Test]
- public void ConversionToColorARGB32IsLossless()
+ public void ConversionIsLosslessToColorARGB32()
{
- ColorARGB32 original = MakeRandomColor();
- ColorARGB32 converted = original.Convert();
- ColorARGB32 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
+ LosslessConversion.Assert();
}
-
+
[Test]
- public void ConversionToColorBGRA32IsLossless()
+ public void ConversionIsLosslessToColorBGRA32()
{
- ColorARGB32 original = MakeRandomColor();
- ColorBGRA32 converted = original.Convert();
- ColorARGB32 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
+ LosslessConversion.Assert();
}
-
+
[Test]
- public void ConversionToColorRGBA32IsLossless()
+ public void ConversionIsLosslessToColorRGBA_sbyte()
{
- ColorARGB32 original = MakeRandomColor();
- ColorRGBA32 converted = original.Convert();
- ColorARGB32 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
+ LosslessConversion.Assert, sbyte>();
}
-
+
[Test]
- public void ConversionToColorRGBA32SignedIsLossless()
+ public void ConversionIsLosslessToColorRGBA_byte()
{
- ColorARGB32 original = MakeRandomColor();
- ColorRGBA32Signed converted = original.Convert();
- ColorARGB32 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
+ LosslessConversion.Assert, byte>();
}
-
+
[Test]
- public void ConversionToColorRGBA64IsLossless()
+ public void ConversionIsLosslessToColorRGBA_short()
{
- ColorARGB32 original = MakeRandomColor();
- ColorRGBA64 converted = original.Convert();
- ColorARGB32 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
+ LosslessConversion.Assert, short>();
}
-
+
[Test]
- public void ConversionToColorRGBA64SignedIsLossless()
+ public void ConversionIsLosslessToColorRGBA_ushort()
{
- ColorARGB32 original = MakeRandomColor();
- ColorRGBA64Signed converted = original.Convert();
- ColorARGB32 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
+ LosslessConversion.Assert, ushort>();
+ }
+
+ [Test]
+ public void ConversionIsLosslessToColorRGBA_int()
+ {
+ LosslessConversion.Assert, int>();
+ }
+
+ [Test]
+ public void ConversionIsLosslessToColorRGBA_uint()
+ {
+ LosslessConversion.Assert, uint>();
+ }
+
+ [Test]
+ public void ConversionIsLosslessToColorRGBA_long()
+ {
+ LosslessConversion.Assert, long>();
+ }
+
+ [Test]
+ public void ConversionIsLosslessToColorRGBA_ulong()
+ {
+ LosslessConversion.Assert, ulong>();
}
}
diff --git a/AssetRipper.TextureDecoder.Tests/Formats/ColorBGRA32Tests.g.cs b/AssetRipper.TextureDecoder.Tests/Formats/ColorBGRA32Tests.g.cs
index 43ad5ed..0a4adbf 100644
--- a/AssetRipper.TextureDecoder.Tests/Formats/ColorBGRA32Tests.g.cs
+++ b/AssetRipper.TextureDecoder.Tests/Formats/ColorBGRA32Tests.g.cs
@@ -1,6 +1,5 @@
-//This code is source generated. Do not edit manually.
+// Auto-generated code. Do not modify manually.
-using AssetRipper.TextureDecoder.Rgb;
using AssetRipper.TextureDecoder.Rgb.Formats;
using System.Runtime.CompilerServices;
@@ -13,7 +12,7 @@ public partial class ColorBGRA32Tests
{
Assert.That(Unsafe.SizeOf(), Is.EqualTo(4));
}
-
+
[Test]
public void PropertyIsSymmetric_R()
{
@@ -57,7 +56,7 @@ public partial class ColorBGRA32Tests
var g = color.G;
var b = color.B;
var a = color.A;
- color.R = 0b01001110;
+ color.R = MakeRandomValue();
Assert.Multiple(() =>
{
Assert.That(color.G, Is.EqualTo(g));
@@ -73,7 +72,7 @@ public partial class ColorBGRA32Tests
var r = color.R;
var b = color.B;
var a = color.A;
- color.G = 0b01001110;
+ color.G = MakeRandomValue();
Assert.Multiple(() =>
{
Assert.That(color.R, Is.EqualTo(r));
@@ -89,7 +88,7 @@ public partial class ColorBGRA32Tests
var r = color.R;
var g = color.G;
var a = color.A;
- color.B = 0b01001110;
+ color.B = MakeRandomValue();
Assert.Multiple(() =>
{
Assert.That(color.R, Is.EqualTo(r));
@@ -105,7 +104,7 @@ public partial class ColorBGRA32Tests
var r = color.R;
var g = color.G;
var b = color.B;
- color.A = 0b01001110;
+ color.A = MakeRandomValue();
Assert.Multiple(() =>
{
Assert.That(color.R, Is.EqualTo(r));
@@ -127,7 +126,7 @@ public partial class ColorBGRA32Tests
Assert.That(color.A, Is.EqualTo(a));
});
}
-
+
[Test]
public void MethodsAreSymmetric()
{
@@ -142,69 +141,68 @@ public partial class ColorBGRA32Tests
Assert.That(color.A, Is.EqualTo(a));
});
}
-
- public static ColorBGRA32 MakeRandomColor()
- {
- return new()
- {
- R = 0b11010101,
- G = 0b01110010,
- B = 0b10001111,
- A = 0b11000111,
- };
- }
-
+
+ public static ColorBGRA32 MakeRandomColor() => ColorRandom.MakeRandomColor();
+
+ public static byte MakeRandomValue() => ColorRandom.MakeRandomValue();
+
[Test]
- public void ConversionToColorARGB32IsLossless()
+ public void ConversionIsLosslessToColorARGB32()
{
- ColorBGRA32 original = MakeRandomColor();
- ColorARGB32 converted = original.Convert();
- ColorBGRA32 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
+ LosslessConversion.Assert();
}
-
+
[Test]
- public void ConversionToColorBGRA32IsLossless()
+ public void ConversionIsLosslessToColorBGRA32()
{
- ColorBGRA32 original = MakeRandomColor();
- ColorBGRA32 converted = original.Convert();
- ColorBGRA32 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
+ LosslessConversion.Assert();
}
-
+
[Test]
- public void ConversionToColorRGBA32IsLossless()
+ public void ConversionIsLosslessToColorRGBA_sbyte()
{
- ColorBGRA32 original = MakeRandomColor();
- ColorRGBA32 converted = original.Convert();
- ColorBGRA32 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
+ LosslessConversion.Assert, sbyte>();
}
-
+
[Test]
- public void ConversionToColorRGBA32SignedIsLossless()
+ public void ConversionIsLosslessToColorRGBA_byte()
{
- ColorBGRA32 original = MakeRandomColor();
- ColorRGBA32Signed converted = original.Convert();
- ColorBGRA32 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
+ LosslessConversion.Assert, byte>();
}
-
+
[Test]
- public void ConversionToColorRGBA64IsLossless()
+ public void ConversionIsLosslessToColorRGBA_short()
{
- ColorBGRA32 original = MakeRandomColor();
- ColorRGBA64 converted = original.Convert();
- ColorBGRA32 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
+ LosslessConversion.Assert, short>();
}
-
+
[Test]
- public void ConversionToColorRGBA64SignedIsLossless()
+ public void ConversionIsLosslessToColorRGBA_ushort()
{
- ColorBGRA32 original = MakeRandomColor();
- ColorRGBA64Signed converted = original.Convert();
- ColorBGRA32 convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
+ LosslessConversion.Assert, ushort>();
+ }
+
+ [Test]
+ public void ConversionIsLosslessToColorRGBA_int()
+ {
+ LosslessConversion.Assert, int>();
+ }
+
+ [Test]
+ public void ConversionIsLosslessToColorRGBA_uint()
+ {
+ LosslessConversion.Assert, uint>();
+ }
+
+ [Test]
+ public void ConversionIsLosslessToColorRGBA_long()
+ {
+ LosslessConversion.Assert, long>();
+ }
+
+ [Test]
+ public void ConversionIsLosslessToColorRGBA_ulong()
+ {
+ LosslessConversion.Assert, ulong>();
}
}
diff --git a/AssetRipper.TextureDecoder.Tests/Formats/ColorR16HalfTests.g.cs b/AssetRipper.TextureDecoder.Tests/Formats/ColorR16HalfTests.g.cs
deleted file mode 100644
index 6f62ef2..0000000
--- a/AssetRipper.TextureDecoder.Tests/Formats/ColorR16HalfTests.g.cs
+++ /dev/null
@@ -1,264 +0,0 @@
-//This code is source generated. Do not edit manually.
-
-using AssetRipper.TextureDecoder.Rgb;
-using AssetRipper.TextureDecoder.Rgb.Formats;
-using System.Runtime.CompilerServices;
-
-namespace AssetRipper.TextureDecoder.Tests.Formats;
-
-public partial class ColorR16HalfTests
-{
- [Test]
- public void CorrectSizeTest()
- {
- Assert.That(Unsafe.SizeOf(), Is.EqualTo(2));
- }
-
- [Test]
- public void PropertyIsSymmetric_R()
- {
- var color = MakeRandomColor();
- var r = color.R;
- color.R = r;
- Assert.That(color.R, Is.EqualTo(r));
- }
-
- [Test]
- public void PropertyIsSymmetric_G()
- {
- var color = MakeRandomColor();
- var g = color.G;
- color.G = g;
- Assert.That(color.G, Is.EqualTo(g));
- }
-
- [Test]
- public void PropertyIsSymmetric_B()
- {
- var color = MakeRandomColor();
- var b = color.B;
- color.B = b;
- Assert.That(color.B, Is.EqualTo(b));
- }
-
- [Test]
- public void PropertyIsSymmetric_A()
- {
- var color = MakeRandomColor();
- var a = color.A;
- color.A = a;
- Assert.That(color.A, Is.EqualTo(a));
- }
-
- [Test]
- public void ChannelsAreIndependent_R()
- {
- var color = MakeRandomColor();
- var g = color.G;
- var b = color.B;
- var a = color.A;
- color.R = (Half)0.333f;
- Assert.Multiple(() =>
- {
- Assert.That(color.G, Is.EqualTo(g));
- Assert.That(color.B, Is.EqualTo(b));
- Assert.That(color.A, Is.EqualTo(a));
- });
- }
-
- [Test]
- public void ChannelsAreIndependent_G()
- {
- var color = MakeRandomColor();
- var r = color.R;
- var b = color.B;
- var a = color.A;
- color.G = (Half)0.333f;
- Assert.Multiple(() =>
- {
- Assert.That(color.R, Is.EqualTo(r));
- Assert.That(color.B, Is.EqualTo(b));
- Assert.That(color.A, Is.EqualTo(a));
- });
- }
-
- [Test]
- public void ChannelsAreIndependent_B()
- {
- var color = MakeRandomColor();
- var r = color.R;
- var g = color.G;
- var a = color.A;
- color.B = (Half)0.333f;
- Assert.Multiple(() =>
- {
- Assert.That(color.R, Is.EqualTo(r));
- Assert.That(color.G, Is.EqualTo(g));
- Assert.That(color.A, Is.EqualTo(a));
- });
- }
-
- [Test]
- public void ChannelsAreIndependent_A()
- {
- var color = MakeRandomColor();
- var r = color.R;
- var g = color.G;
- var b = color.B;
- color.A = (Half)0.333f;
- Assert.Multiple(() =>
- {
- Assert.That(color.R, Is.EqualTo(r));
- Assert.That(color.G, Is.EqualTo(g));
- Assert.That(color.B, Is.EqualTo(b));
- });
- }
-
- [Test]
- public void GetMethodMatchesProperties()
- {
- var color = MakeRandomColor();
- color.GetChannels(out var r, out var g, out var b, out var a);
- Assert.Multiple(() =>
- {
- Assert.That(color.R, Is.EqualTo(r));
- Assert.That(color.G, Is.EqualTo(g));
- Assert.That(color.B, Is.EqualTo(b));
- Assert.That(color.A, Is.EqualTo(a));
- });
- }
-
- [Test]
- public void MethodsAreSymmetric()
- {
- var color = MakeRandomColor();
- color.GetChannels(out var r, out var g, out var b, out var a);
- color.SetChannels(r, g, b, a);
- Assert.Multiple(() =>
- {
- Assert.That(color.R, Is.EqualTo(r));
- Assert.That(color.G, Is.EqualTo(g));
- Assert.That(color.B, Is.EqualTo(b));
- Assert.That(color.A, Is.EqualTo(a));
- });
- }
-
- public static ColorR16Half MakeRandomColor()
- {
- return new()
- {
- R = (Half)0.447f,
- G = (Half)0.224f,
- B = (Half)0.95f,
- A = (Half)0.897f,
- };
- }
-
- [Test]
- public void ConversionToColorR16HalfIsLossless()
- {
- ColorR16Half original = MakeRandomColor();
- ColorR16Half converted = original.Convert();
- ColorR16Half convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
- }
-
- [Test]
- public void ConversionToColorR32SingleIsLossless()
- {
- ColorR16Half original = MakeRandomColor();
- ColorR32Single converted = original.Convert();
- ColorR16Half convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
- }
-
- [Test]
- public void ConversionToColorR64DoubleIsLossless()
- {
- ColorR16Half original = MakeRandomColor();
- ColorR64Double converted = original.Convert();
- ColorR16Half convertedBack = converted.Convert();
- Assert.That(convertedBack, Is.EqualTo(original));
- }
-
- [Test]
- public void ConversionToColorRG32HalfIsLossless()
- {
- ColorR16Half original = MakeRandomColor();
- ColorRG32Half converted = original.Convert();
- ColorR16Half convertedBack = converted.Convert