diff --git a/AssetRipper.TextureDecoder.ColorGenerator/AssetRipper.TextureDecoder.ColorGenerator.csproj b/AssetRipper.TextureDecoder.ColorGenerator/AssetRipper.TextureDecoder.ColorGenerator.csproj index 999644c..7c7d58b 100644 --- a/AssetRipper.TextureDecoder.ColorGenerator/AssetRipper.TextureDecoder.ColorGenerator.csproj +++ b/AssetRipper.TextureDecoder.ColorGenerator/AssetRipper.TextureDecoder.ColorGenerator.csproj @@ -1,5 +1,9 @@  + + Exe + + diff --git a/AssetRipper.TextureDecoder.ColorGenerator/Program.cs b/AssetRipper.TextureDecoder.ColorGenerator/Program.cs index 67d1411..ed39e3d 100644 --- a/AssetRipper.TextureDecoder.ColorGenerator/Program.cs +++ b/AssetRipper.TextureDecoder.ColorGenerator/Program.cs @@ -76,7 +76,7 @@ internal static partial class Program writer.WriteLine($"public partial struct {name} : IColor<{typeName}>"); using (new CurlyBrackets(writer)) { - WriteColorBaseStaticProperties(writer, hasRed, hasGreen, hasBlue, hasAlpha, fullyUtilized, typeName); + WriteNonGenericStaticProperties(writer, hasRed, hasGreen, hasBlue, hasAlpha, fullyUtilized, typeName); writer.WriteLineNoTabs(); WriteToString(writer, hasRed, hasGreen, hasBlue, hasAlpha); } @@ -127,14 +127,14 @@ internal static partial class Program } } - private static void WriteColorBaseStaticProperties(IndentedTextWriter writer, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha, bool fullyUtilized, string typeName) + private static void WriteNonGenericStaticProperties(IndentedTextWriter writer, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha, bool fullyUtilized, string typeName) { - writer.WriteLine($"static bool IColorBase.HasRedChannel => {hasRed.ToLowerString()};"); - writer.WriteLine($"static bool IColorBase.HasGreenChannel => {hasGreen.ToLowerString()};"); - writer.WriteLine($"static bool IColorBase.HasBlueChannel => {hasBlue.ToLowerString()};"); - writer.WriteLine($"static bool IColorBase.HasAlphaChannel => {hasAlpha.ToLowerString()};"); - writer.WriteLine($"static bool IColorBase.ChannelsAreFullyUtilized => {fullyUtilized.ToLowerString()};"); - writer.WriteLine($"static Type IColorBase.ChannelType => typeof({typeName});"); + writer.WriteLine($"static bool IColor.HasRedChannel => {hasRed.ToLowerString()};"); + writer.WriteLine($"static bool IColor.HasGreenChannel => {hasGreen.ToLowerString()};"); + writer.WriteLine($"static bool IColor.HasBlueChannel => {hasBlue.ToLowerString()};"); + writer.WriteLine($"static bool IColor.HasAlphaChannel => {hasAlpha.ToLowerString()};"); + writer.WriteLine($"static bool IColor.ChannelsAreFullyUtilized => {fullyUtilized.ToLowerString()};"); + writer.WriteLine($"static Type IColor.ChannelType => typeof({typeName});"); } private static void WriteGenericColor(IndentedTextWriter writer, string name, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha) @@ -170,7 +170,7 @@ internal static partial class Program writer.WriteLineNoTabs(); WriteSetChannels(writer, typeName, hasRed, hasGreen, hasBlue, hasAlpha); writer.WriteLineNoTabs(); - WriteColorBaseStaticProperties(writer, hasRed, hasGreen, hasBlue, hasAlpha, true, typeName); + WriteNonGenericStaticProperties(writer, hasRed, hasGreen, hasBlue, hasAlpha, true, typeName); writer.WriteLineNoTabs(); WriteToString(writer, hasRed, hasGreen, hasBlue, hasAlpha); } diff --git a/AssetRipper.TextureDecoder.TestGenerator/GenerationData.cs b/AssetRipper.TextureDecoder.TestGenerator/GenerationData.cs index b0a7015..942761d 100644 --- a/AssetRipper.TextureDecoder.TestGenerator/GenerationData.cs +++ b/AssetRipper.TextureDecoder.TestGenerator/GenerationData.cs @@ -21,7 +21,7 @@ namespace AssetRipper.TextureDecoder.TestGenerator public string ChannelTypeName => CSharpPrimitives.Dictionary[ChannelType].LangName; - public static GenerationData Create(int colorSize) where T : IColorBase + public static GenerationData Create(int colorSize) where T : IColor { return new GenerationData() { diff --git a/AssetRipper.TextureDecoder/Rgb/Color.cs b/AssetRipper.TextureDecoder/Rgb/Color.cs index fb065e2..f93e235 100644 --- a/AssetRipper.TextureDecoder/Rgb/Color.cs +++ b/AssetRipper.TextureDecoder/Rgb/Color.cs @@ -68,7 +68,7 @@ public static class Color } [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - public static int GetChannelCount() where T : IColorBase + public static int GetChannelCount() where T : IColor { return (T.HasRedChannel ? 1 : 0) + (T.HasGreenChannel ? 1 : 0) + (T.HasBlueChannel ? 1 : 0) + (T.HasAlphaChannel ? 1 : 0); } diff --git a/AssetRipper.TextureDecoder/Rgb/Formats/ColorA.g.cs b/AssetRipper.TextureDecoder/Rgb/Formats/ColorA.g.cs index dd65671..a86b442 100644 --- a/AssetRipper.TextureDecoder/Rgb/Formats/ColorA.g.cs +++ b/AssetRipper.TextureDecoder/Rgb/Formats/ColorA.g.cs @@ -42,12 +42,12 @@ public partial struct ColorA : IColor where T : unmanaged, INumberBase, A = a; } - static bool IColorBase.HasRedChannel => false; - static bool IColorBase.HasGreenChannel => false; - static bool IColorBase.HasBlueChannel => false; - static bool IColorBase.HasAlphaChannel => true; - static bool IColorBase.ChannelsAreFullyUtilized => true; - static Type IColorBase.ChannelType => typeof(T); + static bool IColor.HasRedChannel => false; + static bool IColor.HasGreenChannel => false; + static bool IColor.HasBlueChannel => false; + static bool IColor.HasAlphaChannel => true; + static bool IColor.ChannelsAreFullyUtilized => true; + static Type IColor.ChannelType => typeof(T); public override string ToString() { diff --git a/AssetRipper.TextureDecoder/Rgb/Formats/ColorARGB16.g.cs b/AssetRipper.TextureDecoder/Rgb/Formats/ColorARGB16.g.cs index 01be14c..28ef710 100644 --- a/AssetRipper.TextureDecoder/Rgb/Formats/ColorARGB16.g.cs +++ b/AssetRipper.TextureDecoder/Rgb/Formats/ColorARGB16.g.cs @@ -4,12 +4,12 @@ namespace AssetRipper.TextureDecoder.Rgb.Formats { public partial struct ColorARGB16 : IColor { - static bool IColorBase.HasRedChannel => true; - static bool IColorBase.HasGreenChannel => true; - static bool IColorBase.HasBlueChannel => true; - static bool IColorBase.HasAlphaChannel => true; - static bool IColorBase.ChannelsAreFullyUtilized => false; - static Type IColorBase.ChannelType => typeof(byte); + static bool IColor.HasRedChannel => true; + static bool IColor.HasGreenChannel => true; + static bool IColor.HasBlueChannel => true; + static bool IColor.HasAlphaChannel => true; + static bool IColor.ChannelsAreFullyUtilized => false; + static Type IColor.ChannelType => typeof(byte); public override string ToString() { diff --git a/AssetRipper.TextureDecoder/Rgb/Formats/ColorARGB32.g.cs b/AssetRipper.TextureDecoder/Rgb/Formats/ColorARGB32.g.cs index f654de7..84e36b5 100644 --- a/AssetRipper.TextureDecoder/Rgb/Formats/ColorARGB32.g.cs +++ b/AssetRipper.TextureDecoder/Rgb/Formats/ColorARGB32.g.cs @@ -4,12 +4,12 @@ namespace AssetRipper.TextureDecoder.Rgb.Formats { public partial struct ColorARGB32 : IColor { - static bool IColorBase.HasRedChannel => true; - static bool IColorBase.HasGreenChannel => true; - static bool IColorBase.HasBlueChannel => true; - static bool IColorBase.HasAlphaChannel => true; - static bool IColorBase.ChannelsAreFullyUtilized => true; - static Type IColorBase.ChannelType => typeof(byte); + static bool IColor.HasRedChannel => true; + static bool IColor.HasGreenChannel => true; + static bool IColor.HasBlueChannel => true; + static bool IColor.HasAlphaChannel => true; + static bool IColor.ChannelsAreFullyUtilized => true; + static Type IColor.ChannelType => typeof(byte); public override string ToString() { diff --git a/AssetRipper.TextureDecoder/Rgb/Formats/ColorBGRA32.g.cs b/AssetRipper.TextureDecoder/Rgb/Formats/ColorBGRA32.g.cs index 15655f5..a509120 100644 --- a/AssetRipper.TextureDecoder/Rgb/Formats/ColorBGRA32.g.cs +++ b/AssetRipper.TextureDecoder/Rgb/Formats/ColorBGRA32.g.cs @@ -4,12 +4,12 @@ namespace AssetRipper.TextureDecoder.Rgb.Formats { public partial struct ColorBGRA32 : IColor { - static bool IColorBase.HasRedChannel => true; - static bool IColorBase.HasGreenChannel => true; - static bool IColorBase.HasBlueChannel => true; - static bool IColorBase.HasAlphaChannel => true; - static bool IColorBase.ChannelsAreFullyUtilized => true; - static Type IColorBase.ChannelType => typeof(byte); + static bool IColor.HasRedChannel => true; + static bool IColor.HasGreenChannel => true; + static bool IColor.HasBlueChannel => true; + static bool IColor.HasAlphaChannel => true; + static bool IColor.ChannelsAreFullyUtilized => true; + static Type IColor.ChannelType => typeof(byte); public override string ToString() { diff --git a/AssetRipper.TextureDecoder/Rgb/Formats/ColorR.g.cs b/AssetRipper.TextureDecoder/Rgb/Formats/ColorR.g.cs index 01458ef..adbeacc 100644 --- a/AssetRipper.TextureDecoder/Rgb/Formats/ColorR.g.cs +++ b/AssetRipper.TextureDecoder/Rgb/Formats/ColorR.g.cs @@ -42,12 +42,12 @@ public partial struct ColorR : IColor where T : unmanaged, INumberBase, R = r; } - static bool IColorBase.HasRedChannel => true; - static bool IColorBase.HasGreenChannel => false; - static bool IColorBase.HasBlueChannel => false; - static bool IColorBase.HasAlphaChannel => false; - static bool IColorBase.ChannelsAreFullyUtilized => true; - static Type IColorBase.ChannelType => typeof(T); + static bool IColor.HasRedChannel => true; + static bool IColor.HasGreenChannel => false; + static bool IColor.HasBlueChannel => false; + static bool IColor.HasAlphaChannel => false; + static bool IColor.ChannelsAreFullyUtilized => true; + static Type IColor.ChannelType => typeof(T); public override string ToString() { diff --git a/AssetRipper.TextureDecoder/Rgb/Formats/ColorRG.g.cs b/AssetRipper.TextureDecoder/Rgb/Formats/ColorRG.g.cs index 0270eb1..44882a8 100644 --- a/AssetRipper.TextureDecoder/Rgb/Formats/ColorRG.g.cs +++ b/AssetRipper.TextureDecoder/Rgb/Formats/ColorRG.g.cs @@ -40,12 +40,12 @@ public partial struct ColorRG : IColor where T : unmanaged, INumberBase G = g; } - static bool IColorBase.HasRedChannel => true; - static bool IColorBase.HasGreenChannel => true; - static bool IColorBase.HasBlueChannel => false; - static bool IColorBase.HasAlphaChannel => false; - static bool IColorBase.ChannelsAreFullyUtilized => true; - static Type IColorBase.ChannelType => typeof(T); + static bool IColor.HasRedChannel => true; + static bool IColor.HasGreenChannel => true; + static bool IColor.HasBlueChannel => false; + static bool IColor.HasAlphaChannel => false; + static bool IColor.ChannelsAreFullyUtilized => true; + static Type IColor.ChannelType => typeof(T); public override string ToString() { diff --git a/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGB.g.cs b/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGB.g.cs index bd64fc8..01ee331 100644 --- a/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGB.g.cs +++ b/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGB.g.cs @@ -38,12 +38,12 @@ public partial struct ColorRGB : IColor where T : unmanaged, INumberBase true; - static bool IColorBase.HasGreenChannel => true; - static bool IColorBase.HasBlueChannel => true; - static bool IColorBase.HasAlphaChannel => false; - static bool IColorBase.ChannelsAreFullyUtilized => true; - static Type IColorBase.ChannelType => typeof(T); + static bool IColor.HasRedChannel => true; + static bool IColor.HasGreenChannel => true; + static bool IColor.HasBlueChannel => true; + static bool IColor.HasAlphaChannel => false; + static bool IColor.ChannelsAreFullyUtilized => true; + static Type IColor.ChannelType => typeof(T); public override string ToString() { diff --git a/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGB16.g.cs b/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGB16.g.cs index 4ab5a86..eae72ca 100644 --- a/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGB16.g.cs +++ b/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGB16.g.cs @@ -4,12 +4,12 @@ namespace AssetRipper.TextureDecoder.Rgb.Formats { public partial struct ColorRGB16 : IColor { - static bool IColorBase.HasRedChannel => true; - static bool IColorBase.HasGreenChannel => true; - static bool IColorBase.HasBlueChannel => true; - static bool IColorBase.HasAlphaChannel => false; - static bool IColorBase.ChannelsAreFullyUtilized => false; - static Type IColorBase.ChannelType => typeof(byte); + static bool IColor.HasRedChannel => true; + static bool IColor.HasGreenChannel => true; + static bool IColor.HasBlueChannel => true; + static bool IColor.HasAlphaChannel => false; + static bool IColor.ChannelsAreFullyUtilized => false; + static Type IColor.ChannelType => typeof(byte); public override string ToString() { diff --git a/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGB9e5.g.cs b/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGB9e5.g.cs index d623a25..b92437d 100644 --- a/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGB9e5.g.cs +++ b/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGB9e5.g.cs @@ -4,12 +4,12 @@ namespace AssetRipper.TextureDecoder.Rgb.Formats { public partial struct ColorRGB9e5 : IColor { - static bool IColorBase.HasRedChannel => true; - static bool IColorBase.HasGreenChannel => true; - static bool IColorBase.HasBlueChannel => true; - static bool IColorBase.HasAlphaChannel => false; - static bool IColorBase.ChannelsAreFullyUtilized => false; - static Type IColorBase.ChannelType => typeof(double); + static bool IColor.HasRedChannel => true; + static bool IColor.HasGreenChannel => true; + static bool IColor.HasBlueChannel => true; + static bool IColor.HasAlphaChannel => false; + static bool IColor.ChannelsAreFullyUtilized => false; + static Type IColor.ChannelType => typeof(double); public override string ToString() { diff --git a/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGBA.g.cs b/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGBA.g.cs index db02418..440d06e 100644 --- a/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGBA.g.cs +++ b/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGBA.g.cs @@ -36,12 +36,12 @@ public partial struct ColorRGBA : IColor where T : unmanaged A = a; } - static bool IColorBase.HasRedChannel => true; - static bool IColorBase.HasGreenChannel => true; - static bool IColorBase.HasBlueChannel => true; - static bool IColorBase.HasAlphaChannel => true; - static bool IColorBase.ChannelsAreFullyUtilized => true; - static Type IColorBase.ChannelType => typeof(T); + static bool IColor.HasRedChannel => true; + static bool IColor.HasGreenChannel => true; + static bool IColor.HasBlueChannel => true; + static bool IColor.HasAlphaChannel => true; + static bool IColor.ChannelsAreFullyUtilized => true; + static Type IColor.ChannelType => typeof(T); public override string ToString() { diff --git a/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGBA16.g.cs b/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGBA16.g.cs index 523a324..b830bb0 100644 --- a/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGBA16.g.cs +++ b/AssetRipper.TextureDecoder/Rgb/Formats/ColorRGBA16.g.cs @@ -4,12 +4,12 @@ namespace AssetRipper.TextureDecoder.Rgb.Formats { public partial struct ColorRGBA16 : IColor { - static bool IColorBase.HasRedChannel => true; - static bool IColorBase.HasGreenChannel => true; - static bool IColorBase.HasBlueChannel => true; - static bool IColorBase.HasAlphaChannel => true; - static bool IColorBase.ChannelsAreFullyUtilized => false; - static Type IColorBase.ChannelType => typeof(byte); + static bool IColor.HasRedChannel => true; + static bool IColor.HasGreenChannel => true; + static bool IColor.HasBlueChannel => true; + static bool IColor.HasAlphaChannel => true; + static bool IColor.ChannelsAreFullyUtilized => false; + static Type IColor.ChannelType => typeof(byte); public override string ToString() { diff --git a/AssetRipper.TextureDecoder/Rgb/IColorBase.cs b/AssetRipper.TextureDecoder/Rgb/IColor.cs similarity index 97% rename from AssetRipper.TextureDecoder/Rgb/IColorBase.cs rename to AssetRipper.TextureDecoder/Rgb/IColor.cs index a1a69c8..6cf35c4 100644 --- a/AssetRipper.TextureDecoder/Rgb/IColorBase.cs +++ b/AssetRipper.TextureDecoder/Rgb/IColor.cs @@ -7,7 +7,7 @@ /// When used as a generic type constraint, the methods and properties get devirtualized by the JIT compiler. /// This prevents boxing when the implementing type is a . /// -public interface IColorBase +public interface IColor { /// /// Does the format have a red channel? diff --git a/AssetRipper.TextureDecoder/Rgb/IColor`1.cs b/AssetRipper.TextureDecoder/Rgb/IColor`1.cs index ad28bfe..4a73a69 100644 --- a/AssetRipper.TextureDecoder/Rgb/IColor`1.cs +++ b/AssetRipper.TextureDecoder/Rgb/IColor`1.cs @@ -1,54 +1,53 @@ -namespace AssetRipper.TextureDecoder.Rgb +namespace AssetRipper.TextureDecoder.Rgb; + +/// +/// An for handling color formats with up to 4 channels. +/// +/// +/// When used as a generic type constraint, the methods and properties get devirtualized by the JIT compiler. +/// This prevents boxing when the implementing type is a . +/// +/// +/// Supported types are: +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +public interface IColor : IColor where T : unmanaged { /// - /// An for handling color formats with up to 4 channels. + /// The red channel /// - /// - /// When used as a generic type constraint, the methods and properties get devirtualized by the JIT compiler. - /// This prevents boxing when the implementing type is a . - /// - /// - /// Supported types are: - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public interface IColor : IColorBase where T : unmanaged - { - /// - /// The red channel - /// - T R { get; set; } - /// - /// The green channel - /// - T G { get; set; } - /// - /// The blue channel - /// - T B { get; set; } - /// - /// The alpha channel - /// - T A { get; set; } + T R { get; set; } + /// + /// The green channel + /// + T G { get; set; } + /// + /// The blue channel + /// + T B { get; set; } + /// + /// The alpha channel + /// + T A { get; set; } - void GetChannels(out T r, out T g, out T b, out T a); - void SetChannels(T r, T g, T b, T a); - } + void GetChannels(out T r, out T g, out T b, out T a); + void SetChannels(T r, T g, T b, T a); }