diff --git a/HPPH/Images/Image.cs b/HPPH/Images/Image.cs index e1deeeb..6f9e79d 100644 --- a/HPPH/Images/Image.cs +++ b/HPPH/Images/Image.cs @@ -4,7 +4,7 @@ using System.Runtime.InteropServices; namespace HPPH; -/// +/// [SkipLocalsInit] public sealed class Image : IImage, IEquatable> where T : struct, IColor @@ -37,6 +37,7 @@ public sealed class Image : IImage, IEquatable> #region Indexer + /// IColor IImage.this[int x, int y] => this[x, y]; /// @@ -51,6 +52,7 @@ public sealed class Image : IImage, IEquatable> } } + /// IImage IImage.this[int x, int y, int width, int height] { [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -74,6 +76,7 @@ public sealed class Image : IImage, IEquatable> } } + /// IImageRows IImage.Rows => new IColorImageRows(_buffer, _x, _y, Width, Height, _stride); /// @@ -122,6 +125,7 @@ public sealed class Image : IImage, IEquatable> return new Image(data, 0, 0, width, height, stride); } + /// public IImage ConvertTo() where TColor : struct, IColor { @@ -141,6 +145,7 @@ public sealed class Image : IImage, IEquatable> } } + /// public void CopyTo(Span destination) => CopyTo(MemoryMarshal.AsBytes(destination)); /// @@ -167,6 +172,7 @@ public sealed class Image : IImage, IEquatable> return array; } + /// public T[] ToArray() { T[] colors = new T[Width * Height]; @@ -175,6 +181,7 @@ public sealed class Image : IImage, IEquatable> } //TODO DarthAffe 11.07.2024: This has some potential for optimization + /// IColor[] IImage.ToArray() { IColor[] colors = new IColor[Width * Height]; @@ -187,8 +194,10 @@ public sealed class Image : IImage, IEquatable> return colors; } + /// public RefImage AsRefImage() => new(_buffer, _x, _y, Width, Height, _stride); + /// public RefImage AsRefImage() where TColor : struct, IColor { @@ -208,6 +217,7 @@ public sealed class Image : IImage, IEquatable> return ref Unsafe.Add(ref MemoryMarshal.GetReference(_buffer.AsSpan()), (_y * _stride) + (_x * ColorFormat.BytesPerPixel)); } + /// public IEnumerator GetEnumerator() { for (int y = 0; y < Height; y++) @@ -215,6 +225,7 @@ public sealed class Image : IImage, IEquatable> yield return this[x, y]; } + /// IEnumerator IEnumerable.GetEnumerator() { for (int y = 0; y < Height; y++) @@ -222,9 +233,11 @@ public sealed class Image : IImage, IEquatable> yield return this[x, y]; } + /// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); //TODO DarthAffe 20.07.2024: All of those equals can be optimized + /// public bool Equals(IImage? other) { if (other == null) return false; @@ -240,6 +253,7 @@ public sealed class Image : IImage, IEquatable> return true; } + /// public bool Equals(IImage? other) { if (other == null) return false; @@ -254,6 +268,7 @@ public sealed class Image : IImage, IEquatable> return true; } + /// public bool Equals(Image? other) { if (other == null) return false; @@ -268,5 +283,11 @@ public sealed class Image : IImage, IEquatable> return true; } + /// + public override bool Equals(object? obj) => Equals(obj as Image); + + /// + public override int GetHashCode() => HashCode.Combine(ColorFormat, Width, Height, _buffer.GetHashCode()); + #endregion } \ No newline at end of file diff --git a/HPPH/Images/ImageColumn.cs b/HPPH/Images/ImageColumn.cs index 4f06e22..aaf76d2 100644 --- a/HPPH/Images/ImageColumn.cs +++ b/HPPH/Images/ImageColumn.cs @@ -124,14 +124,17 @@ internal class IColorImageColumn : IImageColumn private readonly int _length; private readonly int _step; + /// public int Length => _length; + /// public int SizeInBytes => Length * T.ColorFormat.BytesPerPixel; #endregion #region Indexer + /// public IColor this[int y] { get @@ -158,6 +161,7 @@ internal class IColorImageColumn : IImageColumn #region Methods + /// public void CopyTo(Span destination) { if (destination == null) throw new ArgumentNullException(nameof(destination)); @@ -167,6 +171,7 @@ internal class IColorImageColumn : IImageColumn destination[i] = this[i]; } + /// public void CopyTo(Span destination) { if (destination == null) throw new ArgumentNullException(nameof(destination)); @@ -178,6 +183,7 @@ internal class IColorImageColumn : IImageColumn target[i] = Unsafe.As(ref Unsafe.Add(ref dataRef, i * _step)); } + /// public IColor[] ToArray() { IColor[] array = new IColor[Length]; @@ -185,12 +191,14 @@ internal class IColorImageColumn : IImageColumn return array; } + /// public IEnumerator GetEnumerator() { for (int i = 0; i < Length; i++) yield return this[i]; } + /// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); #endregion diff --git a/HPPH/Images/ImageColumns.cs b/HPPH/Images/ImageColumns.cs index 59a5eb2..2514707 100644 --- a/HPPH/Images/ImageColumns.cs +++ b/HPPH/Images/ImageColumns.cs @@ -113,12 +113,14 @@ internal class IColorImageColumns : IImageColumns private readonly int _stride; private readonly int _bpp; + /// public int Count => _width; #endregion #region Indexer + /// public IImageColumn this[int column] { [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -151,12 +153,14 @@ internal class IColorImageColumns : IImageColumns #region Methods + /// public IEnumerator GetEnumerator() { for (int i = 0; i < _width; i++) yield return this[i]; } + /// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); #endregion diff --git a/HPPH/Images/ImageRow.cs b/HPPH/Images/ImageRow.cs index 184ad9a..ded5f2b 100644 --- a/HPPH/Images/ImageRow.cs +++ b/HPPH/Images/ImageRow.cs @@ -117,14 +117,17 @@ internal class IColorImageRow : IImageRow private readonly int _start; private readonly int _length; + /// public int Length => _length; + /// public int SizeInBytes => Length * T.ColorFormat.BytesPerPixel; #endregion #region Indexer + /// public IColor this[int x] { get @@ -150,6 +153,7 @@ internal class IColorImageRow : IImageRow #region Methods + /// public void CopyTo(Span destination) { if (destination == null) throw new ArgumentNullException(nameof(destination)); @@ -159,6 +163,7 @@ internal class IColorImageRow : IImageRow destination[i] = this[i]; } + /// public void CopyTo(Span destination) { if (destination == null) throw new ArgumentNullException(nameof(destination)); @@ -167,6 +172,7 @@ internal class IColorImageRow : IImageRow _buffer.AsSpan().Slice(_start, SizeInBytes).CopyTo(destination); } + /// public IColor[] ToArray() { IColor[] array = new IColor[Length]; @@ -174,12 +180,14 @@ internal class IColorImageRow : IImageRow return array; } + /// public IEnumerator GetEnumerator() { for (int i = 0; i < _length; i++) yield return this[i]; } + /// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); #endregion diff --git a/HPPH/Images/ImageRows.cs b/HPPH/Images/ImageRows.cs index 3a20c74..dfc1436 100644 --- a/HPPH/Images/ImageRows.cs +++ b/HPPH/Images/ImageRows.cs @@ -111,12 +111,14 @@ internal class IColorImageRows : IImageRows private readonly int _height; private readonly int _stride; + /// public int Count => _height; #endregion #region Indexer + /// public IImageRow this[int row] { [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -147,12 +149,14 @@ internal class IColorImageRows : IImageRows #region Methods + /// public IEnumerator GetEnumerator() { for (int i = 0; i < _height; i++) yield return this[i]; } + /// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); #endregion