Made colors equatable; added more tests; small improvements; changed test-data to cover more edge-cases

This commit is contained in:
DarthAffe committed 2024-07-20 16:25:53 +02:00
1 parent 9999681574
commit 2a26c4404f
26 files changed
+378 -152

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@
/// <summary>
/// Represents a generic color made of 4 bytes (alpha, red, green and blue)
/// </summary>
public interface IColor
public interface IColor : IEquatable<IColor>
{
/// <summary>
/// Gets the red-component of this color.
-4
View File
@@ -13,8 +13,4 @@ internal readonly struct Generic3ByteMinMax(byte b1Min, byte b1Max, byte b2Min,
public readonly byte B3Min = b3Min;
public readonly byte B3Max = b3Max;
public byte B1Range => (byte)(B1Max - B1Min);
public byte B2Range => (byte)(B2Max - B2Min);
public byte B3Range => (byte)(B3Max - B3Min);
}
-5
View File
@@ -16,9 +16,4 @@ internal readonly struct Generic4ByteMinMax(byte b1Min, byte b1Max, byte b2Min,
public readonly byte B4Min = b4Min;
public readonly byte B4Max = b4Max;
public byte B1Range => (byte)(B1Max - B1Min);
public byte B2Range => (byte)(B2Max - B2Min);
public byte B3Range => (byte)(B3Max - B3Min);
public byte B4Range => (byte)(B4Max - B4Min);
}
@@ -49,6 +49,9 @@ public readonly partial struct ColorABGR(byte a, byte b, byte g, byte r) : IColo
#region Methods
/// <inheritdoc />
public bool Equals(IColor? other) => (other != null) && (R == other.R) && (G == other.G) && (B == other.B) && (A == other.A);
/// <inheritdoc />
public override string ToString() => $"[A: {A}, R: {R}, G: {G}, B: {B}]";
@@ -49,6 +49,9 @@ public readonly partial struct ColorARGB(byte a, byte r, byte g, byte b) : IColo
#region Methods
/// <inheritdoc />
public bool Equals(IColor? other) => (other != null) && (R == other.R) && (G == other.G) && (B == other.B) && (A == other.A);
/// <inheritdoc />
public override string ToString() => $"[A: {A}, R: {R}, G: {G}, B: {B}]";
@@ -47,6 +47,9 @@ public readonly partial struct ColorBGR(byte b, byte g, byte r): IColor
#region Methods
/// <inheritdoc />
public bool Equals(IColor? other) => (other != null) && (R == other.R) && (G == other.G) && (B == other.B) && (A == other.A);
/// <inheritdoc />
public override string ToString() => $"[A: {A}, R: {R}, G: {G}, B: {B}]";
@@ -49,6 +49,9 @@ public readonly partial struct ColorBGRA(byte b, byte g, byte r, byte a) : IColo
#region Methods
/// <inheritdoc />
public bool Equals(IColor? other) => (other != null) && (R == other.R) && (G == other.G) && (B == other.B) && (A == other.A);
/// <inheritdoc />
public override string ToString() => $"[A: {A}, R: {R}, G: {G}, B: {B}]";
@@ -47,6 +47,9 @@ public readonly partial struct ColorRGB(byte r, byte g, byte b): IColor
#region Methods
/// <inheritdoc />
public bool Equals(IColor? other) => (other != null) && (R == other.R) && (G == other.G) && (B == other.B) && (A == other.A);
/// <inheritdoc />
public override string ToString() => $"[A: {A}, R: {R}, G: {G}, B: {B}]";
@@ -49,6 +49,9 @@ public readonly partial struct ColorRGBA(byte r, byte g, byte b, byte a) : IColo
#region Methods
/// <inheritdoc />
public bool Equals(IColor? other) => (other != null) && (R == other.R) && (G == other.G) && (B == other.B) && (A == other.A);
/// <inheritdoc />
public override string ToString() => $"[A: {A}, R: {R}, G: {G}, B: {B}]";
+2
View File
@@ -22,6 +22,8 @@ public interface IImageRow : IEnumerable<IColor>
/// <returns>The <see cref="IColor"/> at the specified location.</returns>
IColor this[int x] { get; }
void CopyTo(Span<IColor> destination);
/// <summary>
/// Copies the contents of this <see cref="IImageRow"/> into a destination <see cref="Span{T}"/> instance.
/// </summary>
+3
View File
@@ -66,6 +66,9 @@ public static partial class PixelHelper
public static T[] CreateColorPalette<T>(this Span<T> colors, int paletteSize)
where T : unmanaged, IColor
{
if (paletteSize < 0) throw new ArgumentException("PaletteSize Can't be < 0", nameof(paletteSize));
if (paletteSize == 0) return [];
int splits = BitOperations.Log2((uint)paletteSize);
Span<ColorCube<T>> cubes = new ColorCube<T>[1 << splits];