mirror of
https://github.com/DarthAffe/HPPH.git
synced 2025-12-13 05:48:57 +00:00
Compare commits
8 Commits
bd7a2bca48
...
817b4bcb28
| Author | SHA1 | Date | |
|---|---|---|---|
| 817b4bcb28 | |||
| 6c9c7ef832 | |||
| fed16da8ce | |||
| 1b929ac886 | |||
| 16b54650f7 | |||
| b955958df8 | |||
| cc8de89481 | |||
| cd4ad4de78 |
20
.github/workflows/release.yml
vendored
20
.github/workflows/release.yml
vendored
@ -24,32 +24,34 @@ jobs:
|
|||||||
dotnet-version: 8.0.x
|
dotnet-version: 8.0.x
|
||||||
|
|
||||||
- name: Restore dependencies
|
- name: Restore dependencies
|
||||||
run: dotnet restore HPPH
|
run: dotnet restore
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: dotnet build HPPH --no-restore --configuration Release /p:Version=${{ github.event.inputs.version }}
|
run: dotnet build --no-restore --configuration Release /p:Version=${{ github.event.inputs.version }}
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: dotnet test HPPH --no-build --verbosity normal --configuration Release
|
run: dotnet test --no-build --verbosity normal --configuration Release
|
||||||
|
|
||||||
|
- name: List files
|
||||||
|
run: tree
|
||||||
|
|
||||||
- name: Upload Nuget Build Artifact
|
- name: Upload Nuget Build Artifact
|
||||||
uses: actions/upload-artifact@v4.3.1
|
uses: actions/upload-artifact@v4.3.1
|
||||||
with:
|
with:
|
||||||
name: HPPH-Nuget
|
name: HPPH-Nuget
|
||||||
path: HPPH\bin\Release\*.nupkg
|
path: bin\*.nupkg
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
|
|
||||||
- name: List files
|
|
||||||
run: tree
|
|
||||||
|
|
||||||
- name: Release
|
- name: Release
|
||||||
uses: softprops/action-gh-release@v2.0.4
|
uses: softprops/action-gh-release@v2.0.4
|
||||||
with:
|
with:
|
||||||
tag_name: ${{ github.event.inputs.version }}
|
tag_name: ${{ github.event.inputs.version }}
|
||||||
generate_release_notes: true
|
generate_release_notes: true
|
||||||
files: HPPH/bin/Release/net8.0/*.dll
|
files: bin/net8.0/*.dll
|
||||||
|
|
||||||
- name: Nuget Push
|
- name: Nuget Push
|
||||||
id: nuget_push
|
|
||||||
run: dotnet nuget push **\*.nupkg --skip-duplicate --api-key ${{ secrets.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json
|
run: dotnet nuget push **\*.nupkg --skip-duplicate --api-key ${{ secrets.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json
|
||||||
|
|
||||||
|
- name: Symbols Push
|
||||||
|
run: dotnet nuget push **\*.snupkg --skip-duplicate --api-key ${{ secrets.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json
|
||||||
|
|
||||||
|
|||||||
72
HPPH.Benchmark/AverageBenchmarks.cs
Normal file
72
HPPH.Benchmark/AverageBenchmarks.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using BenchmarkDotNet.Attributes;
|
||||||
|
using BenchmarkDotNet.Jobs;
|
||||||
|
using HPPH.Reference;
|
||||||
|
|
||||||
|
namespace HPPH.Benchmark;
|
||||||
|
|
||||||
|
[SimpleJob(RuntimeMoniker.Net80)]
|
||||||
|
[HtmlExporter]
|
||||||
|
[MemoryDiagnoser]
|
||||||
|
public class AverageBenchmarks
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
private readonly List<ColorRGB[]> _colors3bpp;
|
||||||
|
private readonly List<ColorRGBA[]> _colors4bpp;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
public AverageBenchmarks()
|
||||||
|
{
|
||||||
|
_colors3bpp = BenchmarkHelper.GetSampleData<ColorRGB>();
|
||||||
|
_colors4bpp = BenchmarkHelper.GetSampleData<ColorRGBA>();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public ColorRGB[] PixelHelper_3BPP()
|
||||||
|
{
|
||||||
|
ColorRGB[] averages = new ColorRGB[_colors3bpp.Count];
|
||||||
|
for (int i = 0; i < _colors3bpp.Count; i++)
|
||||||
|
averages[i] = new ReadOnlySpan<ColorRGB>(_colors3bpp[i]).Average();
|
||||||
|
|
||||||
|
return averages;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public ColorRGBA[] PixelHelper_4BPP()
|
||||||
|
{
|
||||||
|
ColorRGBA[] averages = new ColorRGBA[_colors4bpp.Count];
|
||||||
|
for (int i = 0; i < _colors4bpp.Count; i++)
|
||||||
|
averages[i] = new ReadOnlySpan<ColorRGBA>(_colors4bpp[i]).Average();
|
||||||
|
|
||||||
|
return averages;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public ColorRGB[] Reference_3BPP()
|
||||||
|
{
|
||||||
|
ColorRGB[] averages = new ColorRGB[_colors3bpp.Count];
|
||||||
|
for (int i = 0; i < _colors3bpp.Count; i++)
|
||||||
|
averages[i] = ReferencePixelHelper.Average(new ReadOnlySpan<ColorRGB>(_colors3bpp[i]));
|
||||||
|
|
||||||
|
return averages;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public ColorRGBA[] Reference_4BPP()
|
||||||
|
{
|
||||||
|
ColorRGBA[] averages = new ColorRGBA[_colors4bpp.Count];
|
||||||
|
for (int i = 0; i < _colors4bpp.Count; i++)
|
||||||
|
averages[i] = ReferencePixelHelper.Average(new ReadOnlySpan<ColorRGBA>(_colors4bpp[i]));
|
||||||
|
|
||||||
|
return averages;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
22
HPPH.Benchmark/BenchmarkHelper.cs
Normal file
22
HPPH.Benchmark/BenchmarkHelper.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using HPPH.System.Drawing;
|
||||||
|
|
||||||
|
namespace HPPH.Benchmark;
|
||||||
|
|
||||||
|
internal static class BenchmarkHelper
|
||||||
|
{
|
||||||
|
private const string SAMPLE_DATA_DIR = @"..\..\..\..\..\..\..\..\sample_data";
|
||||||
|
|
||||||
|
public static List<T[]> GetSampleData<T>()
|
||||||
|
where T : struct, IColor
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(SAMPLE_DATA_DIR)) throw new Exception("sample data not found!");
|
||||||
|
|
||||||
|
List<T[]> colors = [];
|
||||||
|
|
||||||
|
IEnumerable<string> files = Directory.EnumerateFiles(SAMPLE_DATA_DIR, "*.png", SearchOption.AllDirectories);
|
||||||
|
foreach (string file in files)
|
||||||
|
colors.Add(ImageHelper.LoadImage(file).ConvertTo<T>().ToArray());
|
||||||
|
|
||||||
|
return colors;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,5 @@
|
|||||||
using BenchmarkDotNet.Attributes;
|
using BenchmarkDotNet.Attributes;
|
||||||
using BenchmarkDotNet.Jobs;
|
using BenchmarkDotNet.Jobs;
|
||||||
using HPPH.System.Drawing;
|
|
||||||
|
|
||||||
namespace HPPH.Benchmark;
|
namespace HPPH.Benchmark;
|
||||||
|
|
||||||
@ -11,7 +10,8 @@ public class ConvertBenchmarks
|
|||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
private readonly List<ColorRGB[]> _colors = [];
|
private readonly List<ColorRGB[]> _colors3bpp;
|
||||||
|
private readonly List<ColorRGBA[]> _colors4bpp;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -19,13 +19,8 @@ public class ConvertBenchmarks
|
|||||||
|
|
||||||
public ConvertBenchmarks()
|
public ConvertBenchmarks()
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(@"..\..\..\..\sample_data")) return;
|
_colors3bpp = BenchmarkHelper.GetSampleData<ColorRGB>();
|
||||||
|
_colors4bpp = BenchmarkHelper.GetSampleData<ColorRGBA>();
|
||||||
_colors = [];
|
|
||||||
|
|
||||||
IEnumerable<string> files = Directory.EnumerateFiles(@"..\..\..\..\sample_data", "*.png", SearchOption.AllDirectories);
|
|
||||||
foreach (string file in files)
|
|
||||||
_colors.Add(ImageHelper.LoadImage(file).AsRefImage<ColorRGB>().ToArray());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -36,10 +31,8 @@ public class ConvertBenchmarks
|
|||||||
public ColorBGR[] RGBToBGR()
|
public ColorBGR[] RGBToBGR()
|
||||||
{
|
{
|
||||||
ColorBGR[] result = [];
|
ColorBGR[] result = [];
|
||||||
foreach (ColorRGB[] color in _colors)
|
foreach (ColorRGB[] color in _colors3bpp)
|
||||||
{
|
|
||||||
result = new ReadOnlySpan<ColorRGB>(color).Convert<ColorRGB, ColorBGR>();
|
result = new ReadOnlySpan<ColorRGB>(color).Convert<ColorRGB, ColorBGR>();
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -48,11 +41,45 @@ public class ConvertBenchmarks
|
|||||||
public ColorBGRA[] RGBToBGRA()
|
public ColorBGRA[] RGBToBGRA()
|
||||||
{
|
{
|
||||||
ColorBGRA[] result = [];
|
ColorBGRA[] result = [];
|
||||||
foreach (ColorRGB[] color in _colors)
|
foreach (ColorRGB[] color in _colors3bpp)
|
||||||
result = new ReadOnlySpan<ColorRGB>(color).Convert<ColorRGB, ColorBGRA>();
|
result = new ReadOnlySpan<ColorRGB>(color).Convert<ColorRGB, ColorBGRA>();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public ColorABGR[] RGBAToABGR()
|
||||||
|
{
|
||||||
|
ColorABGR[] result = [];
|
||||||
|
foreach (ColorRGBA[] color in _colors4bpp)
|
||||||
|
result = new ReadOnlySpan<ColorRGBA>(color).Convert<ColorRGBA, ColorABGR>();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public ColorBGR[] ARGBToBGR()
|
||||||
|
{
|
||||||
|
ColorBGR[] result = [];
|
||||||
|
foreach (ColorRGBA[] color in _colors4bpp)
|
||||||
|
result = new ReadOnlySpan<ColorRGBA>(color).Convert<ColorRGBA, ColorBGR>();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public void RGBToBGR_InPlace()
|
||||||
|
{
|
||||||
|
foreach (ColorRGB[] color in _colors3bpp)
|
||||||
|
new Span<ColorRGB>(color).ConvertInPlace<ColorRGB, ColorBGR>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public void RGBAToABGR_InPlace()
|
||||||
|
{
|
||||||
|
foreach (ColorRGBA[] color in _colors4bpp)
|
||||||
|
new Span<ColorRGBA>(color).ConvertInPlace<ColorRGBA, ColorABGR>();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
72
HPPH.Benchmark/MinMaxBenchmarks.cs
Normal file
72
HPPH.Benchmark/MinMaxBenchmarks.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using BenchmarkDotNet.Attributes;
|
||||||
|
using BenchmarkDotNet.Jobs;
|
||||||
|
using HPPH.Reference;
|
||||||
|
|
||||||
|
namespace HPPH.Benchmark;
|
||||||
|
|
||||||
|
[SimpleJob(RuntimeMoniker.Net80)]
|
||||||
|
[HtmlExporter]
|
||||||
|
[MemoryDiagnoser]
|
||||||
|
public class MinMaxBenchmarks
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
private readonly List<ColorRGB[]> _colors3bpp;
|
||||||
|
private readonly List<ColorRGBA[]> _colors4bpp;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
public MinMaxBenchmarks()
|
||||||
|
{
|
||||||
|
_colors3bpp = BenchmarkHelper.GetSampleData<ColorRGB>();
|
||||||
|
_colors4bpp = BenchmarkHelper.GetSampleData<ColorRGBA>();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public IMinMax[] PixelHelper_3BPP()
|
||||||
|
{
|
||||||
|
IMinMax[] minMax = new IMinMax[_colors3bpp.Count];
|
||||||
|
for (int i = 0; i < _colors3bpp.Count; i++)
|
||||||
|
minMax[i] = new ReadOnlySpan<ColorRGB>(_colors3bpp[i]).MinMax();
|
||||||
|
|
||||||
|
return minMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public IMinMax[] PixelHelper_4BPP()
|
||||||
|
{
|
||||||
|
IMinMax[] minMax = new IMinMax[_colors4bpp.Count];
|
||||||
|
for (int i = 0; i < _colors4bpp.Count; i++)
|
||||||
|
minMax[i] = new ReadOnlySpan<ColorRGBA>(_colors4bpp[i]).MinMax();
|
||||||
|
|
||||||
|
return minMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public IMinMax[] Reference_3BPP()
|
||||||
|
{
|
||||||
|
IMinMax[] minMax = new IMinMax[_colors3bpp.Count];
|
||||||
|
for (int i = 0; i < _colors3bpp.Count; i++)
|
||||||
|
minMax[i] = ReferencePixelHelper.MinMax(new ReadOnlySpan<ColorRGB>(_colors3bpp[i]));
|
||||||
|
|
||||||
|
return minMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public IMinMax[] Reference_4BPP()
|
||||||
|
{
|
||||||
|
IMinMax[] minMax = new IMinMax[_colors4bpp.Count];
|
||||||
|
for (int i = 0; i < _colors4bpp.Count; i++)
|
||||||
|
minMax[i] = ReferencePixelHelper.MinMax(new ReadOnlySpan<ColorRGBA>(_colors4bpp[i]));
|
||||||
|
|
||||||
|
return minMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
using BenchmarkDotNet.Running;
|
using BenchmarkDotNet.Running;
|
||||||
using HPPH.Benchmark;
|
using HPPH.Benchmark;
|
||||||
|
|
||||||
BenchmarkRunner.Run<ConvertBenchmarks>();
|
BenchmarkRunner.Run(typeof(Program).Assembly);
|
||||||
60
HPPH.Benchmark/SortBenchmarks.cs
Normal file
60
HPPH.Benchmark/SortBenchmarks.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
using BenchmarkDotNet.Attributes;
|
||||||
|
using BenchmarkDotNet.Jobs;
|
||||||
|
using HPPH.Reference;
|
||||||
|
|
||||||
|
namespace HPPH.Benchmark;
|
||||||
|
|
||||||
|
[SimpleJob(RuntimeMoniker.Net80)]
|
||||||
|
[HtmlExporter]
|
||||||
|
[MemoryDiagnoser]
|
||||||
|
public class SortBenchmarks
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
private readonly List<ColorRGB[]> _colors3bpp;
|
||||||
|
private readonly List<ColorRGBA[]> _colors4bpp;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
public SortBenchmarks()
|
||||||
|
{
|
||||||
|
_colors3bpp = BenchmarkHelper.GetSampleData<ColorRGB>();
|
||||||
|
_colors4bpp = BenchmarkHelper.GetSampleData<ColorRGBA>();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public void PixelHelper_3BPP()
|
||||||
|
{
|
||||||
|
foreach (ColorRGB[] colors in _colors3bpp)
|
||||||
|
new Span<ColorRGB>(colors).SortByRed();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public void PixelHelper_4BPP()
|
||||||
|
{
|
||||||
|
foreach (ColorRGBA[] colors in _colors4bpp)
|
||||||
|
new Span<ColorRGBA>(colors).SortByRed();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public void Reference_3BPP()
|
||||||
|
{
|
||||||
|
foreach (ColorRGB[] colors in _colors3bpp)
|
||||||
|
ReferencePixelHelper.SortByRed(new Span<ColorRGB>(colors));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public void Reference_4BPP()
|
||||||
|
{
|
||||||
|
foreach (ColorRGBA[] colors in _colors4bpp)
|
||||||
|
ReferencePixelHelper.SortByRed(new Span<ColorRGBA>(colors));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
72
HPPH.Benchmark/SumBenchmarks.cs
Normal file
72
HPPH.Benchmark/SumBenchmarks.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using BenchmarkDotNet.Attributes;
|
||||||
|
using BenchmarkDotNet.Jobs;
|
||||||
|
using HPPH.Reference;
|
||||||
|
|
||||||
|
namespace HPPH.Benchmark;
|
||||||
|
|
||||||
|
[SimpleJob(RuntimeMoniker.Net80)]
|
||||||
|
[HtmlExporter]
|
||||||
|
[MemoryDiagnoser]
|
||||||
|
public class SumBenchmarks
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
private readonly List<ColorRGB[]> _colors3bpp;
|
||||||
|
private readonly List<ColorRGBA[]> _colors4bpp;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
public SumBenchmarks()
|
||||||
|
{
|
||||||
|
_colors3bpp = BenchmarkHelper.GetSampleData<ColorRGB>();
|
||||||
|
_colors4bpp = BenchmarkHelper.GetSampleData<ColorRGBA>();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public ISum[] PixelHelper_3BPP()
|
||||||
|
{
|
||||||
|
ISum[] sums = new ISum[_colors3bpp.Count];
|
||||||
|
for (int i = 0; i < _colors3bpp.Count; i++)
|
||||||
|
sums[i] = new ReadOnlySpan<ColorRGB>(_colors3bpp[i]).Sum();
|
||||||
|
|
||||||
|
return sums;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public ISum[] PixelHelper_4BPP()
|
||||||
|
{
|
||||||
|
ISum[] sums = new ISum[_colors4bpp.Count];
|
||||||
|
for (int i = 0; i < _colors4bpp.Count; i++)
|
||||||
|
sums[i] = new ReadOnlySpan<ColorRGBA>(_colors4bpp[i]).Sum();
|
||||||
|
|
||||||
|
return sums;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public ISum[] Reference_3BPP()
|
||||||
|
{
|
||||||
|
ISum[] sums = new ISum[_colors3bpp.Count];
|
||||||
|
for (int i = 0; i < _colors3bpp.Count; i++)
|
||||||
|
sums[i] = ReferencePixelHelper.Sum(new ReadOnlySpan<ColorRGB>(_colors3bpp[i]));
|
||||||
|
|
||||||
|
return sums;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public ISum[] Reference_4BPP()
|
||||||
|
{
|
||||||
|
ISum[] sums = new ISum[_colors4bpp.Count];
|
||||||
|
for (int i = 0; i < _colors4bpp.Count; i++)
|
||||||
|
sums[i] = ReferencePixelHelper.Sum(new ReadOnlySpan<ColorRGBA>(_colors4bpp[i]));
|
||||||
|
|
||||||
|
return sums;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@ -15,6 +15,8 @@ public class ColorSortSourceGenerator : IIncrementalGenerator
|
|||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
private const string SORT_GENERATOR_ATTRIBUTE_SOURCE = """
|
private const string SORT_GENERATOR_ATTRIBUTE_SOURCE = """
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Method)]
|
[AttributeUsage(AttributeTargets.Method)]
|
||||||
@ -79,6 +81,8 @@ public class ColorSortSourceGenerator : IIncrementalGenerator
|
|||||||
foreach (KeyValuePair<(string @namespace, string @class, string classModifier), string> data in sourceMapping)
|
foreach (KeyValuePair<(string @namespace, string @class, string classModifier), string> data in sourceMapping)
|
||||||
{
|
{
|
||||||
context.AddSource($"{data.Key.@class}.g.cs", SourceText.From($$"""
|
context.AddSource($"{data.Key.@class}.g.cs", SourceText.From($$"""
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
using System.Buffers;
|
using System.Buffers;
|
||||||
|
|
||||||
namespace {{data.Key.@namespace}};
|
namespace {{data.Key.@namespace}};
|
||||||
|
|||||||
@ -18,6 +18,8 @@ internal class Average : IGeneratorFeature
|
|||||||
private static string GenerateColorFormatAverage(ColorFormatData colorFormat)
|
private static string GenerateColorFormatAverage(ColorFormatData colorFormat)
|
||||||
{
|
{
|
||||||
return $$"""
|
return $$"""
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
@ -36,6 +38,8 @@ internal class Average : IGeneratorFeature
|
|||||||
private static string GenerateColorFormatInterfaceAverage()
|
private static string GenerateColorFormatInterfaceAverage()
|
||||||
{
|
{
|
||||||
return """
|
return """
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
public partial interface IColorFormat
|
public partial interface IColorFormat
|
||||||
|
|||||||
@ -25,6 +25,8 @@ internal class Colors : IGeneratorFeature
|
|||||||
=> colorFormat.Bpp switch
|
=> colorFormat.Bpp switch
|
||||||
{
|
{
|
||||||
3 => $$"""
|
3 => $$"""
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
// ReSharper disable ConvertToAutoProperty
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
@ -89,6 +91,8 @@ internal class Colors : IGeneratorFeature
|
|||||||
""",
|
""",
|
||||||
|
|
||||||
4 => $$"""
|
4 => $$"""
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
// ReSharper disable ConvertToAutoProperty
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
@ -159,6 +163,8 @@ internal class Colors : IGeneratorFeature
|
|||||||
private static string GenerateColorFormatCode(ColorFormatData colorFormat)
|
private static string GenerateColorFormatCode(ColorFormatData colorFormat)
|
||||||
{
|
{
|
||||||
return $$"""
|
return $$"""
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
public sealed partial class ColorFormat{{colorFormat.Format}} : IColorFormat
|
public sealed partial class ColorFormat{{colorFormat.Format}} : IColorFormat
|
||||||
@ -188,6 +194,8 @@ internal class Colors : IGeneratorFeature
|
|||||||
{
|
{
|
||||||
StringBuilder sb = new();
|
StringBuilder sb = new();
|
||||||
sb.AppendLine("""
|
sb.AppendLine("""
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
public partial interface IColorFormat
|
public partial interface IColorFormat
|
||||||
|
|||||||
@ -20,6 +20,8 @@ internal class MinMax : IGeneratorFeature
|
|||||||
=> colorFormat.Bpp switch
|
=> colorFormat.Bpp switch
|
||||||
{
|
{
|
||||||
3 => $$"""
|
3 => $$"""
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
// ReSharper disable ConvertToAutoProperty
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
|
|
||||||
@ -73,6 +75,8 @@ internal class MinMax : IGeneratorFeature
|
|||||||
""",
|
""",
|
||||||
|
|
||||||
4 => $$"""
|
4 => $$"""
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
// ReSharper disable ConvertToAutoProperty
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
|
|
||||||
@ -133,6 +137,8 @@ internal class MinMax : IGeneratorFeature
|
|||||||
private static string GenerateColorFormatMinMax(ColorFormatData colorFormat)
|
private static string GenerateColorFormatMinMax(ColorFormatData colorFormat)
|
||||||
{
|
{
|
||||||
return $$"""
|
return $$"""
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
@ -151,6 +157,8 @@ internal class MinMax : IGeneratorFeature
|
|||||||
private static string GenerateColorFormatInterfaceMinMax()
|
private static string GenerateColorFormatInterfaceMinMax()
|
||||||
{
|
{
|
||||||
return """
|
return """
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
public partial interface IColorFormat
|
public partial interface IColorFormat
|
||||||
|
|||||||
@ -18,6 +18,8 @@ internal class Quantize : IGeneratorFeature
|
|||||||
private static string GenerateColorFormatQuantize(ColorFormatData colorFormat)
|
private static string GenerateColorFormatQuantize(ColorFormatData colorFormat)
|
||||||
{
|
{
|
||||||
return $$"""
|
return $$"""
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
@ -56,6 +58,8 @@ internal class Quantize : IGeneratorFeature
|
|||||||
private static string GenerateColorFormatInterfaceQuantize()
|
private static string GenerateColorFormatInterfaceQuantize()
|
||||||
{
|
{
|
||||||
return """
|
return """
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
public partial interface IColorFormat
|
public partial interface IColorFormat
|
||||||
|
|||||||
@ -20,6 +20,8 @@ internal class Sum : IGeneratorFeature
|
|||||||
=> colorFormat.Bpp switch
|
=> colorFormat.Bpp switch
|
||||||
{
|
{
|
||||||
3 => $$"""
|
3 => $$"""
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
// ReSharper disable ConvertToAutoProperty
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
@ -58,6 +60,8 @@ internal class Sum : IGeneratorFeature
|
|||||||
""",
|
""",
|
||||||
|
|
||||||
4 => $$"""
|
4 => $$"""
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
// ReSharper disable ConvertToAutoProperty
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
@ -100,6 +104,8 @@ internal class Sum : IGeneratorFeature
|
|||||||
private static string GenerateColorFormatSum(ColorFormatData colorFormat)
|
private static string GenerateColorFormatSum(ColorFormatData colorFormat)
|
||||||
{
|
{
|
||||||
return $$"""
|
return $$"""
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
@ -118,6 +124,8 @@ internal class Sum : IGeneratorFeature
|
|||||||
private static string GenerateColorFormatInterfaceSum()
|
private static string GenerateColorFormatInterfaceSum()
|
||||||
{
|
{
|
||||||
return """
|
return """
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
public partial interface IColorFormat
|
public partial interface IColorFormat
|
||||||
|
|||||||
@ -97,10 +97,10 @@ internal class ColorCube
|
|||||||
int b = _colors.Sum(x => x.B);
|
int b = _colors.Sum(x => x.B);
|
||||||
int a = _colors.Sum(x => x.A);
|
int a = _colors.Sum(x => x.A);
|
||||||
|
|
||||||
return T.Create((byte)(r / _colors.Count),
|
return T.Create((byte)MathF.Round(r / (float)_colors.Count),
|
||||||
(byte)(g / _colors.Count),
|
(byte)MathF.Round(g / (float)_colors.Count),
|
||||||
(byte)(b / _colors.Count),
|
(byte)MathF.Round(b / (float)_colors.Count),
|
||||||
(byte)(a / _colors.Count));
|
(byte)MathF.Round(a / (float)_colors.Count));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
namespace HPPH;
|
#nullable enable
|
||||||
|
|
||||||
|
namespace HPPH;
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Method)]
|
[AttributeUsage(AttributeTargets.Method)]
|
||||||
internal class ColorSortGeneratorAttribute(string dataTypeName, string sortValueName) : Attribute
|
internal class ColorSortGeneratorAttribute(string dataTypeName, string sortValueName) : Attribute
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Buffers;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Buffers;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
// ReSharper disable ConvertToAutoProperty
|
#nullable enable
|
||||||
|
|
||||||
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
// ReSharper disable ConvertToAutoProperty
|
#nullable enable
|
||||||
|
|
||||||
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
// ReSharper disable ConvertToAutoProperty
|
#nullable enable
|
||||||
|
|
||||||
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
// ReSharper disable ConvertToAutoProperty
|
#nullable enable
|
||||||
|
|
||||||
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
namespace HPPH;
|
#nullable enable
|
||||||
|
|
||||||
|
namespace HPPH;
|
||||||
|
|
||||||
public sealed partial class ColorFormatABGR : IColorFormat
|
public sealed partial class ColorFormatABGR : IColorFormat
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
namespace HPPH;
|
#nullable enable
|
||||||
|
|
||||||
|
namespace HPPH;
|
||||||
|
|
||||||
public sealed partial class ColorFormatARGB : IColorFormat
|
public sealed partial class ColorFormatARGB : IColorFormat
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
namespace HPPH;
|
#nullable enable
|
||||||
|
|
||||||
|
namespace HPPH;
|
||||||
|
|
||||||
public sealed partial class ColorFormatBGR : IColorFormat
|
public sealed partial class ColorFormatBGR : IColorFormat
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
namespace HPPH;
|
#nullable enable
|
||||||
|
|
||||||
|
namespace HPPH;
|
||||||
|
|
||||||
public sealed partial class ColorFormatBGRA : IColorFormat
|
public sealed partial class ColorFormatBGRA : IColorFormat
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
namespace HPPH;
|
#nullable enable
|
||||||
|
|
||||||
|
namespace HPPH;
|
||||||
|
|
||||||
public sealed partial class ColorFormatRGB : IColorFormat
|
public sealed partial class ColorFormatRGB : IColorFormat
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Runtime.InteropServices;
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace HPPH;
|
namespace HPPH;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
namespace HPPH;
|
#nullable enable
|
||||||
|
|
||||||
|
namespace HPPH;
|
||||||
|
|
||||||
public sealed partial class ColorFormatRGBA : IColorFormat
|
public sealed partial class ColorFormatRGBA : IColorFormat
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
// ReSharper disable ConvertToAutoProperty
|
#nullable enable
|
||||||
|
|
||||||
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
// ReSharper disable ConvertToAutoProperty
|
#nullable enable
|
||||||
|
|
||||||
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
namespace HPPH;
|
#nullable enable
|
||||||
|
|
||||||
|
namespace HPPH;
|
||||||
|
|
||||||
public partial interface IColorFormat
|
public partial interface IColorFormat
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
namespace HPPH;
|
#nullable enable
|
||||||
|
|
||||||
|
namespace HPPH;
|
||||||
|
|
||||||
public partial interface IColorFormat
|
public partial interface IColorFormat
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
namespace HPPH;
|
#nullable enable
|
||||||
|
|
||||||
|
namespace HPPH;
|
||||||
|
|
||||||
public partial interface IColorFormat
|
public partial interface IColorFormat
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
namespace HPPH;
|
#nullable enable
|
||||||
|
|
||||||
|
namespace HPPH;
|
||||||
|
|
||||||
public partial interface IColorFormat
|
public partial interface IColorFormat
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
namespace HPPH;
|
#nullable enable
|
||||||
|
|
||||||
|
namespace HPPH;
|
||||||
|
|
||||||
public partial interface IColorFormat
|
public partial interface IColorFormat
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
// ReSharper disable ConvertToAutoProperty
|
#nullable enable
|
||||||
|
|
||||||
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
// ReSharper disable ConvertToAutoProperty
|
#nullable enable
|
||||||
|
|
||||||
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
// ReSharper disable ConvertToAutoProperty
|
#nullable enable
|
||||||
|
|
||||||
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
// ReSharper disable ConvertToAutoProperty
|
#nullable enable
|
||||||
|
|
||||||
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
// ReSharper disable ConvertToAutoProperty
|
#nullable enable
|
||||||
|
|
||||||
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
// ReSharper disable ConvertToAutoProperty
|
#nullable enable
|
||||||
|
|
||||||
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
// ReSharper disable ConvertToAutoProperty
|
#nullable enable
|
||||||
|
|
||||||
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
// ReSharper disable ConvertToAutoProperty
|
#nullable enable
|
||||||
|
|
||||||
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
// ReSharper disable ConvertToAutoProperty
|
#nullable enable
|
||||||
|
|
||||||
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
// ReSharper disable ConvertToAutoProperty
|
#nullable enable
|
||||||
|
|
||||||
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
// ReSharper disable ConvertToAutoProperty
|
#nullable enable
|
||||||
|
|
||||||
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
// ReSharper disable ConvertToAutoProperty
|
#nullable enable
|
||||||
|
|
||||||
|
// ReSharper disable ConvertToAutoProperty
|
||||||
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
// ReSharper disable ConvertToAutoPropertyWhenPossible
|
||||||
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
// ReSharper disable ReplaceWithPrimaryConstructorParameter
|
||||||
|
|
||||||
|
|||||||
106
README.md
106
README.md
@ -1,3 +1,105 @@
|
|||||||
# HPPH
|
# HPPH
|
||||||
|
|
||||||
**WIP**
|
C# High Performance Pixel Handling
|
||||||
|
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
This library contains helpers to work with color data (currently only 24 and 32 bit byte data) in a somewhat performance-optimized fully in C#.
|
||||||
|
|
||||||
|
It consists of the following packages:
|
||||||
|
|
||||||
|
| Package | Description |
|
||||||
|
|---------------------------------------------------------------------------|--------------------------------------------------------------------------------|
|
||||||
|
| [HPPH](https://www.nuget.org/packages/HPPH) | Core-package, containg all the features described below |
|
||||||
|
| [HPPH.System.Drawing](https://www.nuget.org/packages/HPPH.System.Drawing) | Contains extensions to convert Images from and to System.Drawing.Bitmaps |
|
||||||
|
| [HPPH.SkiaSharp](https://www.nuget.org/packages/HPPH.SkiaSharp) | Contains extensions to convert Images from and to SkiaSharp images and bitmaps |
|
||||||
|
|
||||||
|
## Supported Operations
|
||||||
|
|
||||||
|
All of the currently supported operations are briefly described below. More are to come.
|
||||||
|
|
||||||
|
Benchmarks are all run on an Ryzen 9 5900X. Reference is always a simple approach like looping over the data performing the operation.
|
||||||
|
The data used is always the full set of sample_data to cover a variaty of images.
|
||||||
|
|
||||||
|
|
||||||
|
### Image
|
||||||
|
An abstraction layer for handling pixel-grids.
|
||||||
|
|
||||||
|
Supports all of the operations below and things like allocation-free region selection, iteration and copying of rows, colums or whole images/regions.
|
||||||
|
|
||||||
|
|
||||||
|
### Sum
|
||||||
|
|
||||||
|
Optimized summarization of colors into 4 longs (one for each channel).
|
||||||
|
|
||||||
|
| Method | Mean | Error | StdDev | Allocated |
|
||||||
|
|----------------- |-----------:|---------:|---------:|----------:|
|
||||||
|
| PixelHelper_3BPP | 107.3 μs | 0.21 μs | 0.20 μs | 528 B |
|
||||||
|
| PixelHelper_4BPP | 167.7 μs | 0.85 μs | 0.71 μs | 528 B |
|
||||||
|
| Reference_3BPP | 1,683.3 μs | 18.87 μs | 17.65 μs | 529 B |
|
||||||
|
| Reference_4BPP | 1,619.5 μs | 9.08 μs | 7.58 μs | 529 B |
|
||||||
|
|
||||||
|
|
||||||
|
### Average
|
||||||
|
|
||||||
|
Averages some colors into a single color of the same format.
|
||||||
|
|
||||||
|
| Method | Mean | Error | StdDev | Allocated |
|
||||||
|
|----------------- |-----------:|---------:|---------:|----------:|
|
||||||
|
| PixelHelper_3BPP | 108.2 μs | 0.41 μs | 0.34 μs | 56 B |
|
||||||
|
| PixelHelper_4BPP | 169.0 μs | 2.29 μs | 2.14 μs | 64 B |
|
||||||
|
| Reference_3BPP | 1,654.9 μs | 12.06 μs | 11.28 μs | 705 B |
|
||||||
|
| Reference_4BPP | 1,613.4 μs | 21.11 μs | 18.71 μs | 713 B |
|
||||||
|
|
||||||
|
|
||||||
|
### Min-Max
|
||||||
|
|
||||||
|
Gets the minimum and maximum value for each channel of the given color data.
|
||||||
|
|
||||||
|
| Method | Mean | Error | StdDev | Allocated |
|
||||||
|
|----------------- |-----------:|---------:|---------:|----------:|
|
||||||
|
| PixelHelper_3BPP | 106.2 μs | 0.38 μs | 0.35 μs | 312 B |
|
||||||
|
| PixelHelper_4BPP | 139.2 μs | 1.94 μs | 1.82 μs | 312 B |
|
||||||
|
| Reference_3BPP | 3,838.1 μs | 35.40 μs | 31.38 μs | 314 B |
|
||||||
|
| Reference_4BPP | 4,456.9 μs | 21.06 μs | 19.70 μs | 315 B |
|
||||||
|
|
||||||
|
|
||||||
|
### Sort
|
||||||
|
|
||||||
|
Sorts color data by a single channel (Red, Green, Blue or Alpha).
|
||||||
|
The algorithm is stable.
|
||||||
|
|
||||||
|
> This benchmark is somewhat flawed as it's effectivly running on pre-sorted data, which does not affect the PixelHelper, but might affect the Reference.
|
||||||
|
>
|
||||||
|
> It's also using Linq.OrderBy which is not ideal performance-wise and requires some unneccessary allocations to fit the API, but Array/Span.Sort is not stable, which the PixelHelper is so that wouldn't be a fair comparison.)
|
||||||
|
|
||||||
|
| Method | Mean | Error | StdDev | Allocated |
|
||||||
|
|----------------- |----------:|----------:|----------:|-----------:|
|
||||||
|
| PixelHelper_3BPP | 4.084 ms | 0.0084 ms | 0.0075 ms | 6 B |
|
||||||
|
| PixelHelper_4BPP | 2.687 ms | 0.0102 ms | 0.0091 ms | 3 B |
|
||||||
|
| Reference_3BPP | 59.883 ms | 0.5693 ms | 0.5325 ms | 43118222 B |
|
||||||
|
| Reference_4BPP | 59.599 ms | 0.4866 ms | 0.4551 ms | 52355952 B |
|
||||||
|
|
||||||
|
|
||||||
|
### Quantization
|
||||||
|
|
||||||
|
Creates a color-palette of a given size for some color-data.
|
||||||
|
Currently only a simple but fast variation using the median-cut algorithm is implemented. It's also limited to sizes being a power of 2.
|
||||||
|
|
||||||
|
A more quality focused implementation without the size limitation is planned.
|
||||||
|
|
||||||
|
|
||||||
|
### Conversion
|
||||||
|
|
||||||
|
Converts from one color format to another.
|
||||||
|
All of the included formats can freely be converted between each other.
|
||||||
|
|
||||||
|
Allocation-free in-place conversion is only supported for formats of same size (both 24 or 32 bit).
|
||||||
|
|
||||||
|
| Method | Mean | Error | StdDev | Allocated |
|
||||||
|
|----------- |---------:|----------:|----------:|----------:|
|
||||||
|
| RGBToBGR | 6.272 ms | 0.0288 ms | 0.0240 ms | 8.81 MB |
|
||||||
|
| RGBToBGRA | 8.534 ms | 0.0684 ms | 0.0640 ms | 11.75 MB |
|
||||||
|
| RGBAToABGR | 8.128 ms | 0.0927 ms | 0.0867 ms | 11.75 MB |
|
||||||
|
| ARGBToBGR | 8.004 ms | 0.0353 ms | 0.0313 ms | 8.81 MB |
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user