Compare commits

..

No commits in common. "723649053ce77f3bbc4cebce80beaa66bcb8348f" and "32664a29715582bdf0ebf0f580a40cb50299f369" have entirely different histories.

2 changed files with 21 additions and 16 deletions

View File

@ -249,41 +249,49 @@ public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
/// <inheritdoc />
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
//TODO DarthAffe 20.07.2024: All of those equals can be optimized
/// <inheritdoc />
public bool Equals(IImage? other)
{
if (other == null) return false;
if (other.ColorFormat != ColorFormat) return false;
if (other.Width != Width) return false;
if (other.Height != Height) return false;
return Equals(other.AsRefImage<T>());
for (int y = 0; y < Height; y++)
for (int x = 0; x < Width; x++)
if (!this[x, y].Equals(other[x, y]))
return false;
return true;
}
/// <inheritdoc />
public bool Equals(IImage<T>? other)
{
if (other == null) return false;
if (other.Width != Width) return false;
if (other.Height != Height) return false;
return Equals(other.AsRefImage());
for (int y = 0; y < Height; y++)
for (int x = 0; x < Width; x++)
if (!this[x, y].Equals(other[x, y]))
return false;
return true;
}
/// <inheritdoc />
public bool Equals(Image<T>? other)
{
if (other == null) return false;
return Equals(other.AsRefImage());
}
public bool Equals(RefImage<T> other)
{
if (other.Width != Width) return false;
if (other.Height != Height) return false;
RefImage<T> thisRef = AsRefImage();
for (int y = 0; y < Height; y++)
if (!thisRef.Rows[y].AsByteSpan().SequenceEqual(other.Rows[y].AsByteSpan()))
return false;
for (int x = 0; x < Width; x++)
if (!this[x, y].Equals(other[x, y]))
return false;
return true;
}

View File

@ -47,9 +47,6 @@ public readonly ref struct ImageRow<T>
#region Methods
public ReadOnlySpan<T> AsSpan() => MemoryMarshal.Cast<byte, T>(AsByteSpan());
public ReadOnlySpan<byte> AsByteSpan() => _buffer.Slice(_start, SizeInBytes);
public void CopyTo(Span<T> destination) => CopyTo(MemoryMarshal.AsBytes(destination));
public void CopyTo(Span<byte> destination)
@ -57,7 +54,7 @@ public readonly ref struct ImageRow<T>
if (destination == null) throw new ArgumentNullException(nameof(destination));
if (destination.Length < SizeInBytes) throw new ArgumentException("The destination is too small to fit this image.", nameof(destination));
AsByteSpan().CopyTo(destination);
_buffer.Slice(_start, SizeInBytes).CopyTo(destination);
}
public T[] ToArray()