mirror of
https://github.com/DarthAffe/HPPH.git
synced 2026-11-11 11:26:35 +00:00
Initial commit (WIP)
This commit is contained in:
1 parent
5474273e70
commit
696f3b955f
121 files changed
+5723
-1
No files matched your search
@@ -0,0 +1,47 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace HPPH.Generators;
|
||||
|
||||
internal class Average : IGeneratorFeature
|
||||
{
|
||||
public IEnumerable<(string name, string source)> GenerateFor(ColorFormatData colorFormat)
|
||||
{
|
||||
yield return ($"ColorFormat{colorFormat.Format}.Average", GenerateColorFormatAverage(colorFormat));
|
||||
}
|
||||
|
||||
public IEnumerable<(string name, string source)> GenerateFor(ImmutableArray<ColorFormatData> colorFormats)
|
||||
{
|
||||
yield return ("IColorFormat.Average", GenerateColorFormatInterfaceAverage());
|
||||
}
|
||||
|
||||
private static string GenerateColorFormatAverage(ColorFormatData colorFormat)
|
||||
{
|
||||
return $$"""
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace HPPH;
|
||||
|
||||
public sealed partial class ColorFormat{{colorFormat.Format}}
|
||||
{
|
||||
#region Methods
|
||||
|
||||
unsafe IColor IColorFormat.Average(ReadOnlySpan<byte> data) => PixelHelper.Average(MemoryMarshal.Cast<byte, Color{{colorFormat.Format}}>(data));
|
||||
|
||||
#endregion
|
||||
}
|
||||
""";
|
||||
}
|
||||
|
||||
private static string GenerateColorFormatInterfaceAverage()
|
||||
{
|
||||
return """
|
||||
namespace HPPH;
|
||||
|
||||
public partial interface IColorFormat
|
||||
{
|
||||
internal IColor Average(ReadOnlySpan<byte> data);
|
||||
}
|
||||
""";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Text;
|
||||
|
||||
namespace HPPH.Generators;
|
||||
|
||||
internal class Colors : IGeneratorFeature
|
||||
{
|
||||
public IEnumerable<(string name, string source)> GenerateFor(ColorFormatData colorFormat)
|
||||
{
|
||||
string colorStructCode = GenerateColorStructCode(colorFormat);
|
||||
if (!string.IsNullOrWhiteSpace(colorStructCode))
|
||||
{
|
||||
yield return (colorFormat.TypeName, colorStructCode!);
|
||||
yield return ($"ColorFormat{colorFormat.Format}", GenerateColorFormatCode(colorFormat));
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<(string name, string source)> GenerateFor(ImmutableArray<ColorFormatData> colorFormats)
|
||||
{
|
||||
yield return ("IColorFormat.Instances.cs", GenerateColorFormats(colorFormats));
|
||||
}
|
||||
|
||||
private static string GenerateColorStructCode(ColorFormatData colorFormat)
|
||||
=> colorFormat.Bpp switch
|
||||
{
|
||||
3 => $$"""
|
||||
// ReSharper disable ConvertToAutoProperty
|
||||
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace HPPH;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a color in 24 bit {{colorFormat.Format}}-format.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Initializes a new instance of the <see cref="{{colorFormat.TypeName}}"/> class.
|
||||
/// </remarks>
|
||||
/// <param name="{{colorFormat.FirstEntry}}">The {{colorFormat.FirstEntryName}}-component of the color.</param>
|
||||
/// <param name="{{colorFormat.SecondEntry}}">The {{colorFormat.SecondEntryName}}-component of the color.</param>
|
||||
/// <param name="{{colorFormat.ThirdEntry}}">The {{colorFormat.ThirdEntryName}}-component of the color.</param>
|
||||
[DebuggerDisplay("[A: {A}, R: {R}, G: {G}, B: {B}]")]
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public readonly partial struct {{colorFormat.TypeName}}(byte {{colorFormat.FirstEntry}}, byte {{colorFormat.SecondEntry}}, byte {{colorFormat.ThirdEntry}}): IColor
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <inheritdoc />
|
||||
public static IColorFormat ColorFormat => IColorFormat.{{colorFormat.Format}};
|
||||
|
||||
private readonly byte _{{colorFormat.FirstEntry}} = {{colorFormat.FirstEntry}};
|
||||
private readonly byte _{{colorFormat.SecondEntry}} = {{colorFormat.SecondEntry}};
|
||||
private readonly byte _{{colorFormat.ThirdEntry}} = {{colorFormat.ThirdEntry}};
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte R => _r;
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte G => _g;
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte B => _b;
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte A => byte.MaxValue;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString() => $"[A: {A}, R: {R}, G: {G}, B: {B}]";
|
||||
|
||||
/// <inheritdoc />
|
||||
public static IColor Create(byte r, byte g, byte b, byte a) => new {{colorFormat.TypeName}}({{colorFormat.FirstEntry}}, {{colorFormat.SecondEntry}}, {{colorFormat.ThirdEntry}});
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
""",
|
||||
|
||||
4 => $$"""
|
||||
// ReSharper disable ConvertToAutoProperty
|
||||
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace HPPH;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a color in 32 bit {{colorFormat.Format}}-format.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Initializes a new instance of the <see cref="{{colorFormat.TypeName}}"/> class.
|
||||
/// </remarks>
|
||||
/// <param name="{{colorFormat.FirstEntry}}">The {{colorFormat.FirstEntryName}}-component of the color.</param>
|
||||
/// <param name="{{colorFormat.SecondEntry}}">The {{colorFormat.SecondEntryName}}-component of the color.</param>
|
||||
/// <param name="{{colorFormat.ThirdEntry}}">The {{colorFormat.ThirdEntryName}}-component of the color.</param>
|
||||
/// <param name="{{colorFormat.FourthEntry}}">The {{colorFormat.FourthEntryName}}-component of the color.</param>
|
||||
[DebuggerDisplay("[A: {A}, R: {R}, G: {G}, B: {B}]")]
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public readonly partial struct {{colorFormat.TypeName}}(byte {{colorFormat.FirstEntry}}, byte {{colorFormat.SecondEntry}}, byte {{colorFormat.ThirdEntry}}, byte {{colorFormat.FourthEntry}}) : IColor
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <inheritdoc />
|
||||
public static IColorFormat ColorFormat => IColorFormat.{{colorFormat.Format}};
|
||||
|
||||
private readonly byte _{{colorFormat.FirstEntry}} = {{colorFormat.FirstEntry}};
|
||||
private readonly byte _{{colorFormat.SecondEntry}} = {{colorFormat.SecondEntry}};
|
||||
private readonly byte _{{colorFormat.ThirdEntry}} = {{colorFormat.ThirdEntry}};
|
||||
private readonly byte _{{colorFormat.FourthEntry}} = {{colorFormat.FourthEntry}};
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte R => _r;
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte G => _g;
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte B => _b;
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte A => _a;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString() => $"[A: {A}, R: {R}, G: {G}, B: {B}]";
|
||||
|
||||
/// <inheritdoc />
|
||||
public static IColor Create(byte r, byte g, byte b, byte a) => new {{colorFormat.TypeName}}({{colorFormat.FirstEntry}}, {{colorFormat.SecondEntry}}, {{colorFormat.ThirdEntry}}, {{colorFormat.FourthEntry}});
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
""",
|
||||
_ => null
|
||||
};
|
||||
|
||||
private static string GenerateColorFormatCode(ColorFormatData colorFormat)
|
||||
{
|
||||
return $$"""
|
||||
namespace HPPH;
|
||||
|
||||
public sealed partial class ColorFormat{{colorFormat.Format}} : IColorFormat
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
public static ColorFormat{{colorFormat.Format}} Instance { get; } = new();
|
||||
|
||||
public int BytesPerPixel => {{colorFormat.Bpp}};
|
||||
|
||||
public string Name => "{{colorFormat.Format}}";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
private ColorFormat{{colorFormat.Format}}() {}
|
||||
|
||||
#endregion
|
||||
}
|
||||
""";
|
||||
}
|
||||
|
||||
private static string GenerateColorFormats(ImmutableArray<ColorFormatData> colorFormats)
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
sb.AppendLine("""
|
||||
namespace HPPH;
|
||||
|
||||
public partial interface IColorFormat
|
||||
{
|
||||
#region Instances
|
||||
""");
|
||||
|
||||
sb.AppendLine();
|
||||
|
||||
foreach (ColorFormatData colorFormat in colorFormats)
|
||||
sb.AppendLine($" public static ColorFormat{colorFormat.Format} {colorFormat.Format} => ColorFormat{colorFormat.Format}.Instance;");
|
||||
|
||||
sb.AppendLine();
|
||||
|
||||
sb.AppendLine("""
|
||||
#endregion
|
||||
}
|
||||
""");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace HPPH.Generators;
|
||||
|
||||
internal interface IGeneratorFeature
|
||||
{
|
||||
public IEnumerable<(string name, string source)> GenerateFor(ColorFormatData colorFormat);
|
||||
public IEnumerable<(string name, string source)> GenerateFor(ImmutableArray<ColorFormatData> colorFormats);
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace HPPH.Generators;
|
||||
|
||||
internal class MinMax : IGeneratorFeature
|
||||
{
|
||||
public IEnumerable<(string name, string source)> GenerateFor(ColorFormatData colorFormat)
|
||||
{
|
||||
yield return ($"MinMax{colorFormat.Format}", GenerateMinMaxStruct(colorFormat));
|
||||
yield return ($"ColorFormat{colorFormat.Format}.MinMax", GenerateColorFormatMinMax(colorFormat));
|
||||
}
|
||||
|
||||
public IEnumerable<(string name, string source)> GenerateFor(ImmutableArray<ColorFormatData> colorFormats)
|
||||
{
|
||||
yield return ("IColorFormat.MinMax", GenerateColorFormatInterfaceMinMax());
|
||||
}
|
||||
|
||||
private static string GenerateMinMaxStruct(ColorFormatData colorFormat)
|
||||
=> colorFormat.Bpp switch
|
||||
{
|
||||
3 => $$"""
|
||||
// ReSharper disable ConvertToAutoProperty
|
||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace HPPH;
|
||||
|
||||
[DebuggerDisplay("[A: {AlphaMin}-{AlphaMax}, R: {RedMin}-{RedMax}, G: {GreenMin}-{GreenMax}, B: {BlueMin}-{BlueMax}]")]
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public readonly partial struct MinMax{{colorFormat.Format}}(byte {{colorFormat.FirstEntry}}Min, byte {{colorFormat.FirstEntry}}Max, byte {{colorFormat.SecondEntry}}Min, byte {{colorFormat.SecondEntry}}Max, byte {{colorFormat.ThirdEntry}}Min, byte {{colorFormat.ThirdEntry}}Max) : IMinMax
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly byte _{{colorFormat.FirstEntry}}Min = {{colorFormat.FirstEntry}}Min;
|
||||
private readonly byte _{{colorFormat.FirstEntry}}Max = {{colorFormat.FirstEntry}}Max;
|
||||
|
||||
private readonly byte _{{colorFormat.SecondEntry}}Min = {{colorFormat.SecondEntry}}Min;
|
||||
private readonly byte _{{colorFormat.SecondEntry}}Max = {{colorFormat.SecondEntry}}Max;
|
||||
|
||||
private readonly byte _{{colorFormat.ThirdEntry}}Min = {{colorFormat.ThirdEntry}}Min;
|
||||
private readonly byte _{{colorFormat.ThirdEntry}}Max = {{colorFormat.ThirdEntry}}Max;
|
||||
|
||||
public byte RedMin => _rMin;
|
||||
public byte RedMax => _rMax;
|
||||
|
||||
public byte GreenMin => _gMin;
|
||||
public byte GreenMax => _gMax;
|
||||
|
||||
public byte BlueMin => _bMin;
|
||||
public byte BlueMax => _bMax;
|
||||
|
||||
public byte AlphaMin => byte.MaxValue;
|
||||
public byte AlphaMax => byte.MaxValue;
|
||||
|
||||
public byte RedRange => (byte)(_rMax - _rMin);
|
||||
public byte GreenRange => (byte)(_gMax - _gMin);
|
||||
public byte BlueRange => (byte)(_bMax - _bMin);
|
||||
public byte AlphaRange => 0;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString() => $"[A: {AlphaMin}-{AlphaMax}, R: {RedMin}-{RedMax}, G: {GreenMin}-{GreenMax}, B: {BlueMin}-{BlueMax}]";
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
""",
|
||||
|
||||
4 => $$"""
|
||||
// ReSharper disable ConvertToAutoProperty
|
||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace HPPH;
|
||||
|
||||
[DebuggerDisplay("[A: {AlphaMin}-{AlphaMax}, R: {RedMin}-{RedMax}, G: {GreenMin}-{GreenMax}, B: {BlueMin}-{BlueMax}]")]
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public readonly partial struct MinMax{{colorFormat.Format}}(byte {{colorFormat.FirstEntry}}Min, byte {{colorFormat.FirstEntry}}Max, byte {{colorFormat.SecondEntry}}Min, byte {{colorFormat.SecondEntry}}Max, byte {{colorFormat.ThirdEntry}}Min, byte {{colorFormat.ThirdEntry}}Max, byte {{colorFormat.FourthEntry}}Min, byte {{colorFormat.FourthEntry}}Max) : IMinMax
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly byte _{{colorFormat.FirstEntry}}Min = {{colorFormat.FirstEntry}}Min;
|
||||
private readonly byte _{{colorFormat.FirstEntry}}Max = {{colorFormat.FirstEntry}}Max;
|
||||
|
||||
private readonly byte _{{colorFormat.SecondEntry}}Min = {{colorFormat.SecondEntry}}Min;
|
||||
private readonly byte _{{colorFormat.SecondEntry}}Max = {{colorFormat.SecondEntry}}Max;
|
||||
|
||||
private readonly byte _{{colorFormat.ThirdEntry}}Min = {{colorFormat.ThirdEntry}}Min;
|
||||
private readonly byte _{{colorFormat.ThirdEntry}}Max = {{colorFormat.ThirdEntry}}Max;
|
||||
|
||||
private readonly byte _{{colorFormat.FourthEntry}}Min = {{colorFormat.FourthEntry}}Min;
|
||||
private readonly byte _{{colorFormat.FourthEntry}}Max = {{colorFormat.FourthEntry}}Max;
|
||||
|
||||
public byte RedMin => _rMin;
|
||||
public byte RedMax => _rMax;
|
||||
|
||||
public byte GreenMin => _gMin;
|
||||
public byte GreenMax => _gMax;
|
||||
|
||||
public byte BlueMin => _bMin;
|
||||
public byte BlueMax => _bMax;
|
||||
|
||||
public byte AlphaMin => _aMin;
|
||||
public byte AlphaMax => _aMax;
|
||||
|
||||
public byte RedRange => (byte)(_rMax - _rMin);
|
||||
public byte GreenRange => (byte)(_gMax - _gMin);
|
||||
public byte BlueRange => (byte)(_bMax - _bMin);
|
||||
public byte AlphaRange => (byte)(_aMax - _aMin);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString() => $"[A: {AlphaMin}-{AlphaMax}, R: {RedMin}-{RedMax}, G: {GreenMin}-{GreenMax}, B: {BlueMin}-{BlueMax}]";
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
""",
|
||||
_ => null
|
||||
};
|
||||
|
||||
private static string GenerateColorFormatMinMax(ColorFormatData colorFormat)
|
||||
{
|
||||
return $$"""
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace HPPH;
|
||||
|
||||
public sealed partial class ColorFormat{{colorFormat.Format}}
|
||||
{
|
||||
#region Methods
|
||||
|
||||
unsafe IMinMax IColorFormat.MinMax(ReadOnlySpan<byte> data) => PixelHelper.MinMax<Color{{colorFormat.Format}}, MinMax{{colorFormat.Format}}>(MemoryMarshal.Cast<byte, Color{{colorFormat.Format}}>(data));
|
||||
|
||||
#endregion
|
||||
}
|
||||
""";
|
||||
}
|
||||
|
||||
private static string GenerateColorFormatInterfaceMinMax()
|
||||
{
|
||||
return """
|
||||
namespace HPPH;
|
||||
|
||||
public partial interface IColorFormat
|
||||
{
|
||||
internal IMinMax MinMax(ReadOnlySpan<byte> data);
|
||||
}
|
||||
""";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace HPPH.Generators;
|
||||
|
||||
internal class Quantize : IGeneratorFeature
|
||||
{
|
||||
public IEnumerable<(string name, string source)> GenerateFor(ColorFormatData colorFormat)
|
||||
{
|
||||
yield return ($"ColorFormat{colorFormat.Format}.Quantize", GenerateColorFormatQuantize(colorFormat));
|
||||
}
|
||||
|
||||
public IEnumerable<(string name, string source)> GenerateFor(ImmutableArray<ColorFormatData> colorFormats)
|
||||
{
|
||||
yield return ("IColorFormat.Quantize", GenerateColorFormatInterfaceQuantize());
|
||||
}
|
||||
|
||||
private static string GenerateColorFormatQuantize(ColorFormatData colorFormat)
|
||||
{
|
||||
return $$"""
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace HPPH;
|
||||
|
||||
public sealed partial class ColorFormat{{colorFormat.Format}}
|
||||
{
|
||||
#region Methods
|
||||
|
||||
unsafe IColor[] IColorFormat.CreateColorPalette(ReadOnlySpan<byte> data, int paletteSize)
|
||||
{
|
||||
Color{{colorFormat.Format}}[] colors = PixelHelper.CreateColorPalette<Color{{colorFormat.Format}}>(MemoryMarshal.Cast<byte, Color{{colorFormat.Format}}>(data), paletteSize);
|
||||
|
||||
IColor[] result = new IColor[colors.Length];
|
||||
for(int i = 0; i < colors.Length; i++)
|
||||
result[i] = colors[i];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
""";
|
||||
}
|
||||
|
||||
private static string GenerateColorFormatInterfaceQuantize()
|
||||
{
|
||||
return """
|
||||
namespace HPPH;
|
||||
|
||||
public partial interface IColorFormat
|
||||
{
|
||||
internal IColor[] CreateColorPalette(ReadOnlySpan<byte> data, int paletteSize);
|
||||
}
|
||||
""";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace HPPH.Generators;
|
||||
|
||||
internal class Sum : IGeneratorFeature
|
||||
{
|
||||
public IEnumerable<(string name, string source)> GenerateFor(ColorFormatData colorFormat)
|
||||
{
|
||||
yield return ($"Sum{colorFormat.Format}", GenerateSumStruct(colorFormat));
|
||||
yield return ($"ColorFormat{colorFormat.Format}.Sum", GenerateColorFormatSum(colorFormat));
|
||||
}
|
||||
|
||||
public IEnumerable<(string name, string source)> GenerateFor(ImmutableArray<ColorFormatData> colorFormats)
|
||||
{
|
||||
yield return ("IColorFormat.Sum", GenerateColorFormatInterfaceSum());
|
||||
}
|
||||
|
||||
private static string GenerateSumStruct(ColorFormatData colorFormat)
|
||||
=> colorFormat.Bpp switch
|
||||
{
|
||||
3 => $$"""
|
||||
// ReSharper disable ConvertToAutoProperty
|
||||
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace HPPH;
|
||||
|
||||
[DebuggerDisplay("[A: {A}, R: {R}, G: {G}, B: {B}]")]
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public readonly partial struct Sum{{colorFormat.Format}}(long {{colorFormat.FirstEntry}}, long {{colorFormat.SecondEntry}}, long {{colorFormat.ThirdEntry}}, long a) : ISum
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly long _{{colorFormat.FirstEntry}} = {{colorFormat.FirstEntry}};
|
||||
private readonly long _{{colorFormat.SecondEntry}} = {{colorFormat.SecondEntry}};
|
||||
private readonly long _{{colorFormat.ThirdEntry}} = {{colorFormat.ThirdEntry}};
|
||||
private readonly long _a = a;
|
||||
|
||||
public long A => _a;
|
||||
public long R => _r;
|
||||
public long G => _g;
|
||||
public long B => _b;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString() => $"[A: {A}, R: {R}, G: {G}, B: {B}]";
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
""",
|
||||
|
||||
4 => $$"""
|
||||
// ReSharper disable ConvertToAutoProperty
|
||||
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace HPPH;
|
||||
|
||||
[DebuggerDisplay("[A: {A}, R: {R}, G: {G}, B: {B}]")]
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public readonly partial struct Sum{{colorFormat.Format}}(long {{colorFormat.FirstEntry}}, long {{colorFormat.SecondEntry}}, long {{colorFormat.ThirdEntry}}, long {{colorFormat.FourthEntry}}) : ISum
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly long _{{colorFormat.FirstEntry}} = {{colorFormat.FirstEntry}};
|
||||
private readonly long _{{colorFormat.SecondEntry}} = {{colorFormat.SecondEntry}};
|
||||
private readonly long _{{colorFormat.ThirdEntry}} = {{colorFormat.ThirdEntry}};
|
||||
private readonly long _{{colorFormat.FourthEntry}} = {{colorFormat.FourthEntry}};
|
||||
|
||||
public long R => _r;
|
||||
public long G => _g;
|
||||
public long B => _b;
|
||||
public long A => _a;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString() => $"[A: {A}, R: {R}, G: {G}, B: {B}]";
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
""",
|
||||
_ => null
|
||||
};
|
||||
|
||||
private static string GenerateColorFormatSum(ColorFormatData colorFormat)
|
||||
{
|
||||
return $$"""
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace HPPH;
|
||||
|
||||
public sealed partial class ColorFormat{{colorFormat.Format}}
|
||||
{
|
||||
#region Methods
|
||||
|
||||
unsafe ISum IColorFormat.Sum(ReadOnlySpan<byte> data) => PixelHelper.Sum<Color{{colorFormat.Format}}, Sum{{colorFormat.Format}}>(MemoryMarshal.Cast<byte, Color{{colorFormat.Format}}>(data));
|
||||
|
||||
#endregion
|
||||
}
|
||||
""";
|
||||
}
|
||||
|
||||
private static string GenerateColorFormatInterfaceSum()
|
||||
{
|
||||
return """
|
||||
namespace HPPH;
|
||||
|
||||
public partial interface IColorFormat
|
||||
{
|
||||
internal ISum Sum(ReadOnlySpan<byte> data);
|
||||
}
|
||||
""";
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user