mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48:31 +00:00
Small optimizations
This commit is contained in:
parent
cc7abb63f0
commit
105fdea2d7
@ -228,8 +228,8 @@ namespace RGB.NET.Core
|
||||
foreach ((RenderTarget renderTarget, Color c) in render)
|
||||
{
|
||||
Color color = c;
|
||||
foreach (IColorCorrection colorCorrection in renderTarget.Led.Device.ColorCorrections)
|
||||
colorCorrection.ApplyTo(ref color);
|
||||
for (int i = 0; i < renderTarget.Led.Device.ColorCorrections.Count; i++)
|
||||
renderTarget.Led.Device.ColorCorrections[i].ApplyTo(ref color);
|
||||
|
||||
renderTarget.Led.Color = color;
|
||||
}
|
||||
|
||||
@ -91,12 +91,12 @@ namespace RGB.NET.Core
|
||||
|
||||
#region Methods
|
||||
|
||||
protected abstract Color GetColor(ReadOnlySpan<T> pixel);
|
||||
protected abstract Color GetColor(in ReadOnlySpan<T> pixel);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected virtual ReadOnlySpan<T> GetPixelData(int x, int y) => Data.Slice((y * _stride) + x, _dataPerPixel);
|
||||
|
||||
protected virtual void GetRegionData(int x, int y, int width, int height, Span<T> buffer)
|
||||
protected virtual void GetRegionData(int x, int y, int width, int height, in Span<T> buffer)
|
||||
{
|
||||
int dataWidth = width * _dataPerPixel;
|
||||
ReadOnlySpan<T> data = Data;
|
||||
@ -139,7 +139,7 @@ namespace RGB.NET.Core
|
||||
|
||||
#region Methods
|
||||
|
||||
protected override Color GetColor(ReadOnlySpan<Color> pixel) => pixel[0];
|
||||
protected override Color GetColor(in ReadOnlySpan<Color> pixel) => pixel[0];
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ namespace RGB.NET.Core
|
||||
{
|
||||
#region Methods
|
||||
|
||||
public void SampleColor(in SamplerInfo<Color> info, Span<Color> pixelData)
|
||||
public void SampleColor(in SamplerInfo<Color> info, in Span<Color> pixelData)
|
||||
{
|
||||
int count = info.Width * info.Height;
|
||||
if (count == 0) return;
|
||||
|
||||
@ -4,6 +4,6 @@ namespace RGB.NET.Core
|
||||
{
|
||||
public interface ISampler<T>
|
||||
{
|
||||
void SampleColor(in SamplerInfo<T> info, Span<T> pixelData);
|
||||
void SampleColor(in SamplerInfo<T> info, in Span<T> pixelData);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user