mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2026-11-11 13:06:24 +00:00
Fixed code issues
This commit is contained in:
1 parent
7b0e9152fd
commit
59e11e5b82
120 files changed
+1348
-342
No files matched your search
@@ -3,12 +3,17 @@ using RGB.NET.Presets.Textures.Gradients;
|
||||
|
||||
namespace RGB.NET.Presets.Textures
|
||||
{
|
||||
/// <inheritdoc cref="AbstractBindable" />
|
||||
/// <inheritdoc cref="ITexture" />
|
||||
/// <summary>
|
||||
/// Represents a abstract texture containing a color-gradient.
|
||||
/// </summary>
|
||||
public abstract class AbstractGradientTexture : AbstractBindable, ITexture
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Gets the gradient drawn by the brush.
|
||||
/// Gets the gradient used to generate this texture.
|
||||
/// </summary>
|
||||
public IGradient Gradient { get; }
|
||||
|
||||
@@ -25,6 +30,11 @@ namespace RGB.NET.Presets.Textures
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AbstractGradientTexture" /> class.
|
||||
/// </summary>
|
||||
/// <param name="size">The size of the texture.</param>
|
||||
/// <param name="gradient">The gradient used to generate this texture.</param>
|
||||
protected AbstractGradientTexture(Size size, IGradient gradient)
|
||||
{
|
||||
this.Size = size;
|
||||
@@ -35,6 +45,11 @@ namespace RGB.NET.Presets.Textures
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets the color at the specified location of the texture.
|
||||
/// </summary>
|
||||
/// <param name="point">The location to get the color from.</param>
|
||||
/// <returns>The color at the specified location.</returns>
|
||||
protected abstract Color GetColor(in Point point);
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -4,42 +4,69 @@ using RGB.NET.Presets.Textures.Sampler;
|
||||
|
||||
namespace RGB.NET.Presets.Textures
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a texture of byte-data pixels.
|
||||
/// </summary>
|
||||
public sealed class BytePixelTexture : PixelTexture<byte>
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly byte[] _data;
|
||||
/// <inheritdoc />
|
||||
protected override ReadOnlySpan<byte> Data => _data;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the color format the data is in.
|
||||
/// </summary>
|
||||
public ColorFormat ColorFormat { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BytePixelTexture" /> class.
|
||||
/// A <see cref="AverageColorSampler"/> is used.
|
||||
/// </summary>
|
||||
/// <param name="with">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="data">The pixel-data of the texture.</param>
|
||||
/// <param name="colorFormat">The color format the data is in. (default: RGB)</param>
|
||||
public BytePixelTexture(int with, int height, byte[] data, ColorFormat colorFormat = ColorFormat.RGB)
|
||||
: this(with, height, data, new AverageByteSampler(), colorFormat)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BytePixelTexture" /> class.
|
||||
/// </summary>
|
||||
/// <param name="with">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="data">The pixel-data of the texture.</param>
|
||||
/// <param name="sampler">The sampler used to get the color of a region.</param>
|
||||
/// <param name="colorFormat">The color format the data is in. (default: RGB)</param>
|
||||
public BytePixelTexture(int with, int height, byte[] data, ISampler<byte> sampler, ColorFormat colorFormat = ColorFormat.RGB)
|
||||
: base(with, height, 3, sampler)
|
||||
{
|
||||
this._data = data;
|
||||
this.ColorFormat = colorFormat;
|
||||
|
||||
if (Data.Length != ((with * height) * 3)) throw new ArgumentException($"Data-Length {Data.Length} differs from the given size {with}x{height} * 3 bytes ({with * height * 3}).");
|
||||
if (Data.Length != ((with * height) * 3)) throw new ArgumentException($"Data-Length {Data.Length} differs from the specified size {with}x{height} * 3 bytes ({with * height * 3}).");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Color GetColor(in ReadOnlySpan<byte> pixel)
|
||||
{
|
||||
if (ColorFormat == ColorFormat.BGR)
|
||||
return new Color(pixel[2], pixel[1], pixel[0]);
|
||||
|
||||
return new Color(pixel[0], pixel[1], pixel[2]);
|
||||
return ColorFormat switch
|
||||
{
|
||||
ColorFormat.RGB => new Color(pixel[0], pixel[1], pixel[2]),
|
||||
ColorFormat.BGR => new Color(pixel[2], pixel[1], pixel[0]),
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace RGB.NET.Presets.Textures
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a brush drawing a conical gradient.
|
||||
/// Represents a texture drawing a conical gradient.
|
||||
/// </summary>
|
||||
public sealed class ConicalGradientTexture : AbstractGradientTexture
|
||||
{
|
||||
@@ -51,6 +51,7 @@ namespace RGB.NET.Presets.Textures
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Presets.Textures.ConicalGradientTexture" /> class.
|
||||
/// </summary>
|
||||
/// <param name="size">The size of the texture.</param>
|
||||
/// <param name="gradient">The <see cref="T:RGB.NET.Presets.Gradients.IGradient" /> drawn by this <see cref="T:RGB.NET.Presets.Textures.ConicalGradientTexture" />.</param>
|
||||
public ConicalGradientTexture(Size size, IGradient gradient)
|
||||
: base(size, gradient)
|
||||
@@ -59,8 +60,9 @@ namespace RGB.NET.Presets.Textures
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Presets.Textures.ConicalGradientTexture" /> class.
|
||||
/// </summary>
|
||||
/// <param name="center">The center <see cref="T:RGB.NET.Core.Point" /> (as percentage in the range [0..1]).</param>
|
||||
/// <param name="size">The size of the texture.</param>
|
||||
/// <param name="gradient">The <see cref="T:RGB.NET.Presets.Gradients.IGradient" /> drawn by this <see cref="T:RGB.NET.Presets.Textures.ConicalGradientTexture" />.</param>
|
||||
/// <param name="center">The center <see cref="T:RGB.NET.Core.Point" /> (as percentage in the range [0..1]).</param>
|
||||
public ConicalGradientTexture(Size size, IGradient gradient, Point center)
|
||||
: base(size, gradient)
|
||||
{
|
||||
@@ -70,9 +72,10 @@ namespace RGB.NET.Presets.Textures
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Presets.Textures.ConicalGradientTexture" /> class.
|
||||
/// </summary>
|
||||
/// <param name="center">The center <see cref="T:RGB.NET.Core.Point" /> (as percentage in the range [0..1]).</param>
|
||||
/// <param name="origin">The origin (radian-angle) the <see cref="T:RGB.NET.Core.IBrush" /> is drawn to.</param>
|
||||
/// <param name="size">The size of the texture.</param>
|
||||
/// <param name="gradient">The <see cref="T:RGB.NET.Presets.Gradients.IGradient" /> drawn by this <see cref="T:RGB.NET.Presets.Textures.ConicalGradientTexture" />.</param>
|
||||
/// <param name="center">The center <see cref="T:RGB.NET.Core.Point" /> (as percentage in the range [0..1]).</param>
|
||||
/// <param name="origin">The origin (radian-angle) the gradient is drawn to.</param>
|
||||
public ConicalGradientTexture(Size size, IGradient gradient, Point center, float origin)
|
||||
: base(size, gradient)
|
||||
{
|
||||
@@ -84,6 +87,7 @@ namespace RGB.NET.Presets.Textures
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Color GetColor(in Point point)
|
||||
{
|
||||
float angle = MathF.Atan2(point.Y - Center.Y, point.X - Center.X) - Origin;
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
namespace RGB.NET.Presets.Textures
|
||||
#pragma warning disable 1591
|
||||
|
||||
namespace RGB.NET.Presets.Textures
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains a list of possible color formats.
|
||||
/// </summary>
|
||||
public enum ColorFormat
|
||||
{
|
||||
RGB,
|
||||
|
||||
@@ -4,42 +4,69 @@ using RGB.NET.Presets.Textures.Sampler;
|
||||
|
||||
namespace RGB.NET.Presets.Textures
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a texture of float-data pixels.
|
||||
/// </summary>
|
||||
public sealed class FloatPixelTexture : PixelTexture<float>
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly float[] _data;
|
||||
/// <inheritdoc />
|
||||
protected override ReadOnlySpan<float> Data => _data;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the color format the data is in.
|
||||
/// </summary>
|
||||
public ColorFormat ColorFormat { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FloatPixelTexture" /> class.
|
||||
/// A <see cref="AverageColorSampler"/> is used.
|
||||
/// </summary>
|
||||
/// <param name="with">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="data">The pixel-data of the texture.</param>
|
||||
/// <param name="colorFormat">The color format the data is in. (default: RGB)</param>
|
||||
public FloatPixelTexture(int with, int height, float[] data, ColorFormat colorFormat = ColorFormat.RGB)
|
||||
: this(with, height, data, new AverageFloatSampler(), colorFormat)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FloatPixelTexture" /> class.
|
||||
/// </summary>
|
||||
/// <param name="with">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="data">The pixel-data of the texture.</param>
|
||||
/// <param name="sampler">The sampler used to get the color of a region.</param>
|
||||
/// <param name="colorFormat">The color format the data is in. (default: RGB)</param>
|
||||
public FloatPixelTexture(int with, int height, float[] data, ISampler<float> sampler, ColorFormat colorFormat = ColorFormat.RGB)
|
||||
: base(with, height, 3, sampler)
|
||||
{
|
||||
this._data = data;
|
||||
this.ColorFormat = colorFormat;
|
||||
|
||||
if (Data.Length != ((with * height) * 3)) throw new ArgumentException($"Data-Length {Data.Length} differs from the given size {with}x{height} * 3 bytes ({with * height * 3}).");
|
||||
if (Data.Length != ((with * height) * 3)) throw new ArgumentException($"Data-Length {Data.Length} differs from the specified size {with}x{height} * 3 bytes ({with * height * 3}).");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Color GetColor(in ReadOnlySpan<float> pixel)
|
||||
{
|
||||
if (ColorFormat == ColorFormat.BGR)
|
||||
return new Color(pixel[2], pixel[1], pixel[0]);
|
||||
|
||||
return new Color(pixel[0], pixel[1], pixel[2]);
|
||||
return ColorFormat switch
|
||||
{
|
||||
ColorFormat.RGB => new Color(pixel[0], pixel[1], pixel[2]),
|
||||
ColorFormat.BGR => new Color(pixel[2], pixel[1], pixel[0]),
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace RGB.NET.Presets.Textures.Gradients
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Gets the linear interpolated <see cref="T:RGB.NET.Core.Color" /> at the given offset.
|
||||
/// Gets the linear interpolated <see cref="T:RGB.NET.Core.Color" /> at the specified offset.
|
||||
/// </summary>
|
||||
/// <param name="offset">The percentage offset to take the color from.</param>
|
||||
/// <returns>The <see cref="T:RGB.NET.Core.Color" /> at the specific offset.</returns>
|
||||
@@ -106,7 +106,7 @@ namespace RGB.NET.Presets.Textures.Gradients
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the two <see cref="GradientStop"/>s encapsulating the given offset.
|
||||
/// Get the two <see cref="GradientStop"/>s encapsulating the specified offset.
|
||||
/// </summary>
|
||||
/// <param name="offset">The reference offset.</param>
|
||||
/// <param name="orderedStops">The ordered list of <see cref="GradientStop"/> to choose from.</param>
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace RGB.NET.Presets.Textures.Gradients
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Gets the color on the rainbow at the given offset.
|
||||
/// Gets the color on the rainbow at the specified offset.
|
||||
/// </summary>
|
||||
/// <param name="offset">The percentage offset to take the color from.</param>
|
||||
/// <returns>The color at the specific offset.</returns>
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace RGB.NET.Presets.Textures
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a brush drawing a linear gradient.
|
||||
/// Represents a texture drawing a linear gradient.
|
||||
/// </summary>
|
||||
public sealed class LinearGradientTexture : AbstractGradientTexture
|
||||
{
|
||||
@@ -46,6 +46,7 @@ namespace RGB.NET.Presets.Textures
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Presets.Textures.LinearGradientTexture" /> class.
|
||||
/// </summary>
|
||||
/// <param name="size">The size of the texture.</param>
|
||||
/// <param name="gradient">The <see cref="T:RGB.NET.Presets.Gradients.IGradient" /> drawn by this <see cref="T:RGB.NET.Presets.Textures.LinearGradientTexture" />.</param>
|
||||
public LinearGradientTexture(Size size, IGradient gradient)
|
||||
: base(size, gradient)
|
||||
@@ -54,9 +55,10 @@ namespace RGB.NET.Presets.Textures
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Presets.Textures.LinearGradientTexture" /> class.
|
||||
/// </summary>
|
||||
/// <param name="size">The size of the texture.</param>
|
||||
/// <param name="gradient">The <see cref="T:RGB.NET.Presets.Gradients.IGradient" /> drawn by this <see cref="T:RGB.NET.Presets.Textures.LinearGradientTexture" />.</param>
|
||||
/// <param name="startPoint">The start <see cref="T:RGB.NET.Core.Point" /> (as percentage in the range [0..1]).</param>
|
||||
/// <param name="endPoint">The end <see cref="T:RGB.NET.Core.Point" /> (as percentage in the range [0..1]).</param>
|
||||
/// <param name="gradient">The <see cref="T:RGB.NET.Presets.Gradients.IGradient" /> drawn by this <see cref="T:RGB.NET.Presets.Textures.LinearGradientTexture" />.</param>
|
||||
public LinearGradientTexture(Size size, IGradient gradient, Point startPoint, Point endPoint)
|
||||
: base(size, gradient)
|
||||
{
|
||||
@@ -68,6 +70,7 @@ namespace RGB.NET.Presets.Textures
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Color GetColor(in Point point)
|
||||
{
|
||||
float offset = GradientHelper.CalculateLinearGradientOffset(StartPoint, EndPoint, point);
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace RGB.NET.Presets.Textures
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a brush drawing a radial gradient around a center point.
|
||||
/// Represents a texture drawing a radial gradient around a center point.
|
||||
/// </summary>
|
||||
public sealed class RadialGradientTexture : AbstractGradientTexture
|
||||
{
|
||||
@@ -39,6 +39,7 @@ namespace RGB.NET.Presets.Textures
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Presets.Textures.RadialGradientTexture" /> class.
|
||||
/// </summary>
|
||||
/// <param name="size">The size of the texture.</param>
|
||||
/// <param name="gradient">The gradient drawn by the brush.</param>
|
||||
public RadialGradientTexture(Size size, IGradient gradient)
|
||||
: base(size, gradient)
|
||||
@@ -47,8 +48,9 @@ namespace RGB.NET.Presets.Textures
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Presets.Textures.RadialGradientTexture" /> class.
|
||||
/// </summary>
|
||||
/// <param name="center">The center point (as percentage in the range [0..1]).</param>
|
||||
/// <param name="size">The size of the texture.</param>
|
||||
/// <param name="gradient">The gradient drawn by the brush.</param>
|
||||
/// <param name="center">The center point (as percentage in the range [0..1]).</param>
|
||||
public RadialGradientTexture(Size size, IGradient gradient, Point center)
|
||||
: base(size, gradient)
|
||||
{
|
||||
@@ -66,6 +68,7 @@ namespace RGB.NET.Presets.Textures
|
||||
_referenceDistance = GradientHelper.CalculateDistance(new Point(referenceX, referenceY), Center);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Color GetColor(in Point point)
|
||||
{
|
||||
float distance = GradientHelper.CalculateDistance(point, Center);
|
||||
|
||||
@@ -3,11 +3,15 @@ using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Presets.Textures.Sampler
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a sampled that averages multiple byte-data entries.
|
||||
/// </summary>
|
||||
public class AverageByteSampler : ISampler<byte>
|
||||
{
|
||||
#region Methods
|
||||
|
||||
public void SampleColor(in SamplerInfo<byte> info, in Span<byte> pixelData)
|
||||
/// <inheritdoc />
|
||||
public void Sample(in SamplerInfo<byte> info, in Span<byte> pixelData)
|
||||
{
|
||||
int count = info.Width * info.Height;
|
||||
if (count == 0) return;
|
||||
|
||||
@@ -3,11 +3,15 @@ using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Presets.Textures.Sampler
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a sampled that averages multiple float-data entries.
|
||||
/// </summary>
|
||||
public class AverageFloatSampler : ISampler<float>
|
||||
{
|
||||
#region Methods
|
||||
|
||||
public void SampleColor(in SamplerInfo<float> info, in Span<float> pixelData)
|
||||
/// <inheritdoc />
|
||||
public void Sample(in SamplerInfo<float> info, in Span<float> pixelData)
|
||||
{
|
||||
int count = info.Width * info.Height;
|
||||
if (count == 0) return;
|
||||
|
||||
Reference in new issue
Block a user