mirror of
https://github.com/DarthAffe/HPPH.git
synced 2026-11-09 18:36:34 +00:00
Implemented a first draft of a ColorFormat-conversion
This commit is contained in:
1 parent
9f37a41f55
commit
ccd4a8d5c8
12 files changed
+309
-3
No files matched your search
@@ -1,9 +1,12 @@
|
||||
using System.Text;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace HPPH.Generators;
|
||||
|
||||
internal readonly struct ColorFormatData(string typeName, int bpp, char firstEntry, char secondEntry, char thirdEntry, char fourthEntry)
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
public readonly string TypeName = typeName;
|
||||
public readonly int Bpp = bpp;
|
||||
public readonly string FirstEntry = firstEntry.ToString().ToLowerInvariant();
|
||||
@@ -16,6 +19,8 @@ internal readonly struct ColorFormatData(string typeName, int bpp, char firstEnt
|
||||
public string ThirdEntryName => GetEntryName(ThirdEntry);
|
||||
public string FourthEntryName => GetEntryName(FourthEntry);
|
||||
|
||||
public string ByteMapping => CreateByteMapping();
|
||||
|
||||
public string Format
|
||||
{
|
||||
get
|
||||
@@ -38,13 +43,55 @@ internal readonly struct ColorFormatData(string typeName, int bpp, char firstEnt
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private string CreateByteMapping()
|
||||
{
|
||||
string[] mapping = new string[Bpp];
|
||||
if (Bpp > 0)
|
||||
{
|
||||
mapping[0] = GetByteMappingIndex(FirstEntry).ToString();
|
||||
|
||||
if (Bpp > 1)
|
||||
{
|
||||
mapping[1] = GetByteMappingIndex(SecondEntry).ToString();
|
||||
|
||||
if (Bpp > 2)
|
||||
{
|
||||
mapping[2] = GetByteMappingIndex(ThirdEntry).ToString();
|
||||
|
||||
if (Bpp > 3)
|
||||
{
|
||||
mapping[3] = GetByteMappingIndex(FourthEntry).ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return string.Join(", ", mapping);
|
||||
}
|
||||
|
||||
private static string GetEntryName(string entry)
|
||||
=> entry switch
|
||||
{
|
||||
"a" => "Alpha",
|
||||
"r" => "Red",
|
||||
"g" => "Green",
|
||||
"b" => "Blue",
|
||||
"a" => "Alpha",
|
||||
_ => string.Empty
|
||||
};
|
||||
|
||||
private static int GetByteMappingIndex(string entry)
|
||||
=> entry switch
|
||||
{
|
||||
"r" => 0,
|
||||
"g" => 1,
|
||||
"b" => 2,
|
||||
"a" => 3,
|
||||
_ => throw new IndexOutOfRangeException()
|
||||
};
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -18,7 +18,7 @@ internal class Colors : IGeneratorFeature
|
||||
|
||||
public IEnumerable<(string name, string source)> GenerateFor(ImmutableArray<ColorFormatData> colorFormats)
|
||||
{
|
||||
yield return ("IColorFormat.Instances.cs", GenerateColorFormats(colorFormats));
|
||||
yield return ("IColorFormat.Instances", GenerateColorFormats(colorFormats));
|
||||
}
|
||||
|
||||
private static string GenerateColorStructCode(ColorFormatData colorFormat)
|
||||
@@ -165,6 +165,8 @@ internal class Colors : IGeneratorFeature
|
||||
|
||||
public string Name => "{{colorFormat.Format}}";
|
||||
|
||||
ReadOnlySpan<byte> IColorFormat.ByteMapping => [{{colorFormat.ByteMapping}}];
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
Reference in new issue
Block a user