Simplified textures

This commit is contained in:
DarthAffe committed 2021-02-24 13:05:15 +01:00
1 parent 8ddf0bc734
commit cc7abb63f0
7 files changed
+85 -129

No files matched your search

@@ -7,23 +7,21 @@ namespace RGB.NET.Presets.Textures.Sampler
{
#region Methods
public Color SampleColor(SamplerInfo<byte> info)
public void SampleColor(in SamplerInfo<byte> info, Span<byte> pixelData)
{
int count = info.Width * info.Height;
if (count == 0) return Color.Transparent;
if (count == 0) return;
ReadOnlySpan<byte> data = info.Data;
uint r = 0, g = 0, b = 0;
for (int i = 0; i < data.Length; i += 3)
{
r += data[i];
g += data[i + 1];
b += data[i + 2];
}
int dataLength = pixelData.Length;
Span<uint> sums = stackalloc uint[dataLength];
for (int i = 0; i < data.Length; i += dataLength)
for (int j = 0; j < sums.Length; j++)
sums[j] += data[i + j];
float divisor = count * byte.MaxValue;
return new Color(r / divisor, g / divisor, b / divisor);
for (int i = 0; i < pixelData.Length; i++)
pixelData[i] = (byte)MathF.Round(sums[i] / (float)count);
}
#endregion
@@ -7,22 +7,21 @@ namespace RGB.NET.Presets.Textures.Sampler
{
#region Methods
public Color SampleColor(SamplerInfo<float> info)
public void SampleColor(in SamplerInfo<float> info, Span<float> pixelData)
{
int count = info.Width * info.Height;
if (count == 0) return Color.Transparent;
if (count == 0) return;
ReadOnlySpan<float> data = info.Data;
float r = 0, g = 0, b = 0;
for (int i = 0; i < data.Length; i += 3)
{
r += data[i];
g += data[i + 1];
b += data[i + 2];
}
int dataLength = pixelData.Length;
Span<float> sums = stackalloc float[dataLength];
for (int i = 0; i < data.Length; i += dataLength)
for (int j = 0; j < sums.Length; j++)
sums[j] += data[i + j];
return new Color(r / count, g / count, b / count);
for (int i = 0; i < pixelData.Length; i++)
pixelData[i] = sums[i] / count;
}
#endregion