mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 10:08:31 +00:00
Changed DataPerPixel and Stride to be protected in PixelTexture
This commit is contained in:
parent
928d5c2ef9
commit
9f8e64fbcb
@ -1,4 +1,6 @@
|
|||||||
using System;
|
// ReSharper disable MemberCanBePrivate.Global
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace RGB.NET.Core;
|
namespace RGB.NET.Core;
|
||||||
@ -13,8 +15,20 @@ public abstract class PixelTexture<T> : ITexture
|
|||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
private readonly int _dataPerPixel;
|
/// <summary>
|
||||||
private readonly int _stride;
|
/// Gets the underlying pixel data.
|
||||||
|
/// </summary>
|
||||||
|
protected abstract ReadOnlySpan<T> Data { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the amount of data-entries per pixel.
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int DataPerPixel;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the stride of the data.
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int Stride;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the sampler used to get the color of a region.
|
/// Gets or sets the sampler used to get the color of a region.
|
||||||
@ -24,11 +38,6 @@ public abstract class PixelTexture<T> : ITexture
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Size Size { get; }
|
public Size Size { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the underlying pixel data.
|
|
||||||
/// </summary>
|
|
||||||
protected abstract ReadOnlySpan<T> Data { get; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual Color this[in Point point]
|
public virtual Color this[in Point point]
|
||||||
{
|
{
|
||||||
@ -78,9 +87,9 @@ public abstract class PixelTexture<T> : ITexture
|
|||||||
if ((width == 0) || (height == 0)) return Color.Transparent;
|
if ((width == 0) || (height == 0)) return Color.Transparent;
|
||||||
if ((width == 1) && (height == 1)) return GetColor(GetPixelData(x, y));
|
if ((width == 1) && (height == 1)) return GetColor(GetPixelData(x, y));
|
||||||
|
|
||||||
SamplerInfo<T> samplerInfo = new(x, y, width, height, _stride, _dataPerPixel, Data);
|
SamplerInfo<T> samplerInfo = new(x, y, width, height, Stride, DataPerPixel, Data);
|
||||||
|
|
||||||
Span<T> pixelData = stackalloc T[_dataPerPixel];
|
Span<T> pixelData = stackalloc T[DataPerPixel];
|
||||||
Sampler.Sample(samplerInfo, pixelData);
|
Sampler.Sample(samplerInfo, pixelData);
|
||||||
|
|
||||||
return GetColor(pixelData);
|
return GetColor(pixelData);
|
||||||
@ -101,8 +110,8 @@ public abstract class PixelTexture<T> : ITexture
|
|||||||
/// <param name="stride">The stride of the data or -1 if the width should be used.</param>
|
/// <param name="stride">The stride of the data or -1 if the width should be used.</param>
|
||||||
public PixelTexture(int with, int height, int dataPerPixel, ISampler<T> sampler, int stride = -1)
|
public PixelTexture(int with, int height, int dataPerPixel, ISampler<T> sampler, int stride = -1)
|
||||||
{
|
{
|
||||||
this._stride = stride == -1 ? with : stride;
|
this.Stride = stride == -1 ? with : stride;
|
||||||
this._dataPerPixel = dataPerPixel;
|
this.DataPerPixel = dataPerPixel;
|
||||||
this.Sampler = sampler;
|
this.Sampler = sampler;
|
||||||
|
|
||||||
Size = new Size(with, height);
|
Size = new Size(with, height);
|
||||||
@ -126,7 +135,7 @@ public abstract class PixelTexture<T> : ITexture
|
|||||||
/// <param name="y">The y-location.</param>
|
/// <param name="y">The y-location.</param>
|
||||||
/// <returns>The pixel-data on the specified location.</returns>
|
/// <returns>The pixel-data on the specified location.</returns>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private ReadOnlySpan<T> GetPixelData(int x, int y) => Data.Slice((y * _stride) + x, _dataPerPixel);
|
private ReadOnlySpan<T> GetPixelData(int x, int y) => Data.Slice((y * Stride) + x, DataPerPixel);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user