mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2026-11-11 13:06:24 +00:00
Optimized Textures and Sampler
This commit is contained in:
1 parent
34a2acc6c4
commit
c9634f3913
11 files changed
+325
-52
No files matched your search
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Presets.Textures.Sampler
|
||||
{
|
||||
public class AverageByteSampler : ISampler<byte>
|
||||
{
|
||||
#region Methods
|
||||
|
||||
public Color SampleColor(SamplerInfo<byte> info)
|
||||
{
|
||||
int count = info.Width * info.Height;
|
||||
if (count == 0) return Color.Transparent;
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
float divisor = count * byte.MaxValue;
|
||||
return new Color(r / divisor, g / divisor, b / divisor);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Presets.Textures.Sampler
|
||||
{
|
||||
public class AverageFloatSampler : ISampler<float>
|
||||
{
|
||||
#region Methods
|
||||
|
||||
public Color SampleColor(SamplerInfo<float> info)
|
||||
{
|
||||
int count = info.Width * info.Height;
|
||||
if (count == 0) return Color.Transparent;
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
return new Color(r / count, g / count, b / count);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user