Small optimizations

This commit is contained in:
DarthAffe committed 2021-02-25 00:30:09 +01:00
1 parent cc7abb63f0
commit 105fdea2d7
8 files changed
+13 -12

No files matched your search

+1 -1
View File
@@ -34,7 +34,7 @@ namespace RGB.NET.Presets.Textures
#region Methods
protected override Color GetColor(ReadOnlySpan<byte> pixel)
protected override Color GetColor(in ReadOnlySpan<byte> pixel)
{
if (ColorFormat == ColorFormat.BGR)
return new Color(pixel[2], pixel[1], pixel[0]);
@@ -34,7 +34,7 @@ namespace RGB.NET.Presets.Textures
#region Methods
protected override Color GetColor(ReadOnlySpan<float> pixel)
protected override Color GetColor(in ReadOnlySpan<float> pixel)
{
if (ColorFormat == ColorFormat.BGR)
return new Color(pixel[2], pixel[1], pixel[0]);
@@ -7,7 +7,7 @@ namespace RGB.NET.Presets.Textures.Sampler
{
#region Methods
public void SampleColor(in SamplerInfo<byte> info, Span<byte> pixelData)
public void SampleColor(in SamplerInfo<byte> info, in Span<byte> pixelData)
{
int count = info.Width * info.Height;
if (count == 0) return;
@@ -20,8 +20,9 @@ namespace RGB.NET.Presets.Textures.Sampler
for (int j = 0; j < sums.Length; j++)
sums[j] += data[i + j];
float divisor = count * byte.MaxValue;
for (int i = 0; i < pixelData.Length; i++)
pixelData[i] = (byte)MathF.Round(sums[i] / (float)count);
pixelData[i] = (sums[i] / divisor).GetByteValueFromPercentage();
}
#endregion
@@ -7,7 +7,7 @@ namespace RGB.NET.Presets.Textures.Sampler
{
#region Methods
public void SampleColor(in SamplerInfo<float> info, Span<float> pixelData)
public void SampleColor(in SamplerInfo<float> info, in Span<float> pixelData)
{
int count = info.Width * info.Height;
if (count == 0) return;