mirror of
https://github.com/AssetRipper/AssetRipper.TextureDecoder.git
synced 2026-11-13 12:41:27 -10:00
Rename IColorBase to IColor
This commit is contained in:
1 parent
d8918771a9
commit
bed45ee60e
17 files changed
+130
-127
No files matched your search
+4
@@ -1,5 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AssetRipper.Text.SourceGeneration" Version="1.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace AssetRipper.TextureDecoder.TestGenerator
|
||||
|
||||
public string ChannelTypeName => CSharpPrimitives.Dictionary[ChannelType].LangName;
|
||||
|
||||
public static GenerationData Create<T>(int colorSize) where T : IColorBase
|
||||
public static GenerationData Create<T>(int colorSize) where T : IColor
|
||||
{
|
||||
return new GenerationData()
|
||||
{
|
||||
|
||||
@@ -68,7 +68,7 @@ public static class Color
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int GetChannelCount<T>() where T : IColorBase
|
||||
public static int GetChannelCount<T>() where T : IColor
|
||||
{
|
||||
return (T.HasRedChannel ? 1 : 0) + (T.HasGreenChannel ? 1 : 0) + (T.HasBlueChannel ? 1 : 0) + (T.HasAlphaChannel ? 1 : 0);
|
||||
}
|
||||
|
||||
@@ -42,12 +42,12 @@ public partial struct ColorA<T> : IColor<T> where T : unmanaged, INumberBase<T>,
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -4,12 +4,12 @@ namespace AssetRipper.TextureDecoder.Rgb.Formats
|
||||
{
|
||||
public partial struct ColorARGB16 : IColor<byte>
|
||||
{
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -4,12 +4,12 @@ namespace AssetRipper.TextureDecoder.Rgb.Formats
|
||||
{
|
||||
public partial struct ColorARGB32 : IColor<byte>
|
||||
{
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -4,12 +4,12 @@ namespace AssetRipper.TextureDecoder.Rgb.Formats
|
||||
{
|
||||
public partial struct ColorBGRA32 : IColor<byte>
|
||||
{
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -42,12 +42,12 @@ public partial struct ColorR<T> : IColor<T> where T : unmanaged, INumberBase<T>,
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -40,12 +40,12 @@ public partial struct ColorRG<T> : IColor<T> where T : unmanaged, INumberBase<T>
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -38,12 +38,12 @@ public partial struct ColorRGB<T> : IColor<T> where T : unmanaged, INumberBase<T
|
||||
B = b;
|
||||
}
|
||||
|
||||
static bool IColorBase.HasRedChannel => 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()
|
||||
{
|
||||
|
||||
@@ -4,12 +4,12 @@ namespace AssetRipper.TextureDecoder.Rgb.Formats
|
||||
{
|
||||
public partial struct ColorRGB16 : IColor<byte>
|
||||
{
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -4,12 +4,12 @@ namespace AssetRipper.TextureDecoder.Rgb.Formats
|
||||
{
|
||||
public partial struct ColorRGB9e5 : IColor<double>
|
||||
{
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -36,12 +36,12 @@ public partial struct ColorRGBA<T> : IColor<T> 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()
|
||||
{
|
||||
|
||||
@@ -4,12 +4,12 @@ namespace AssetRipper.TextureDecoder.Rgb.Formats
|
||||
{
|
||||
public partial struct ColorRGBA16 : IColor<byte>
|
||||
{
|
||||
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()
|
||||
{
|
||||
|
||||
+1
-1
@@ -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 <see langword="struct"/>.
|
||||
/// </remarks>
|
||||
public interface IColorBase
|
||||
public interface IColor
|
||||
{
|
||||
/// <summary>
|
||||
/// Does the format have a red channel?
|
||||
@@ -1,54 +1,53 @@
|
||||
namespace AssetRipper.TextureDecoder.Rgb
|
||||
namespace AssetRipper.TextureDecoder.Rgb;
|
||||
|
||||
/// <summary>
|
||||
/// An <see langword="interface"/> for handling color formats with up to 4 channels.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 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 <see langword="struct"/>.
|
||||
/// </remarks>
|
||||
/// <typeparam name="T">
|
||||
/// Supported types are:
|
||||
/// <list type="bullet">
|
||||
/// <item><see cref="sbyte"/></item>
|
||||
/// <item><see cref="byte"/></item>
|
||||
/// <item><see cref="short"/></item>
|
||||
/// <item><see cref="ushort"/></item>
|
||||
/// <item><see cref="int"/></item>
|
||||
/// <item><see cref="uint"/></item>
|
||||
/// <item><see cref="nint"/></item>
|
||||
/// <item><see cref="nuint"/></item>
|
||||
/// <item><see cref="long"/></item>
|
||||
/// <item><see cref="ulong"/></item>
|
||||
/// <item><see cref="Int128"/></item>
|
||||
/// <item><see cref="UInt128"/></item>
|
||||
/// <item><see cref="Half"/></item>
|
||||
/// <item><see cref="float"/></item>
|
||||
/// <item><see cref="NFloat"/></item>
|
||||
/// <item><see cref="double"/></item>
|
||||
/// <item><see cref="decimal"/></item>
|
||||
/// </list>
|
||||
/// </typeparam>
|
||||
public interface IColor<T> : IColor where T : unmanaged
|
||||
{
|
||||
/// <summary>
|
||||
/// An <see langword="interface"/> for handling color formats with up to 4 channels.
|
||||
/// The red channel
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 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 <see langword="struct"/>.
|
||||
/// </remarks>
|
||||
/// <typeparam name="T">
|
||||
/// Supported types are:
|
||||
/// <list type="bullet">
|
||||
/// <item><see cref="sbyte"/></item>
|
||||
/// <item><see cref="byte"/></item>
|
||||
/// <item><see cref="short"/></item>
|
||||
/// <item><see cref="ushort"/></item>
|
||||
/// <item><see cref="int"/></item>
|
||||
/// <item><see cref="uint"/></item>
|
||||
/// <item><see cref="nint"/></item>
|
||||
/// <item><see cref="nuint"/></item>
|
||||
/// <item><see cref="long"/></item>
|
||||
/// <item><see cref="ulong"/></item>
|
||||
/// <item><see cref="Int128"/></item>
|
||||
/// <item><see cref="UInt128"/></item>
|
||||
/// <item><see cref="Half"/></item>
|
||||
/// <item><see cref="float"/></item>
|
||||
/// <item><see cref="NFloat"/></item>
|
||||
/// <item><see cref="double"/></item>
|
||||
/// <item><see cref="decimal"/></item>
|
||||
/// </list>
|
||||
/// </typeparam>
|
||||
public interface IColor<T> : IColorBase where T : unmanaged
|
||||
{
|
||||
/// <summary>
|
||||
/// The red channel
|
||||
/// </summary>
|
||||
T R { get; set; }
|
||||
/// <summary>
|
||||
/// The green channel
|
||||
/// </summary>
|
||||
T G { get; set; }
|
||||
/// <summary>
|
||||
/// The blue channel
|
||||
/// </summary>
|
||||
T B { get; set; }
|
||||
/// <summary>
|
||||
/// The alpha channel
|
||||
/// </summary>
|
||||
T A { get; set; }
|
||||
T R { get; set; }
|
||||
/// <summary>
|
||||
/// The green channel
|
||||
/// </summary>
|
||||
T G { get; set; }
|
||||
/// <summary>
|
||||
/// The blue channel
|
||||
/// </summary>
|
||||
T B { get; set; }
|
||||
/// <summary>
|
||||
/// The alpha channel
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
Reference in new issue
Block a user