mirror of
https://github.com/DarthAffe/HPPH.git
synced 2025-12-12 13:28:37 +00:00
Added some of the missing doc-comments
This commit is contained in:
parent
9f3fbc7473
commit
db218e0e8d
@ -4,7 +4,7 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace HPPH;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <inheritdoc cref="IImage{T}" />
|
||||
[SkipLocalsInit]
|
||||
public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
|
||||
where T : struct, IColor
|
||||
@ -37,6 +37,7 @@ public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
|
||||
|
||||
#region Indexer
|
||||
|
||||
/// <inheritdoc />
|
||||
IColor IImage.this[int x, int y] => this[x, y];
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -51,6 +52,7 @@ public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
IImage IImage.this[int x, int y, int width, int height]
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@ -74,6 +76,7 @@ public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
IImageRows IImage.Rows => new IColorImageRows<T>(_buffer, _x, _y, Width, Height, _stride);
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -122,6 +125,7 @@ public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
|
||||
return new Image<T>(data, 0, 0, width, height, stride);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IImage<TColor> ConvertTo<TColor>()
|
||||
where TColor : struct, IColor
|
||||
{
|
||||
@ -141,6 +145,7 @@ public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void CopyTo(Span<T> destination) => CopyTo(MemoryMarshal.AsBytes(destination));
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -167,6 +172,7 @@ public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
|
||||
return array;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public T[] ToArray()
|
||||
{
|
||||
T[] colors = new T[Width * Height];
|
||||
@ -175,6 +181,7 @@ public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
|
||||
}
|
||||
|
||||
//TODO DarthAffe 11.07.2024: This has some potential for optimization
|
||||
/// <inheritdoc />
|
||||
IColor[] IImage.ToArray()
|
||||
{
|
||||
IColor[] colors = new IColor[Width * Height];
|
||||
@ -187,8 +194,10 @@ public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
|
||||
return colors;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public RefImage<T> AsRefImage() => new(_buffer, _x, _y, Width, Height, _stride);
|
||||
|
||||
/// <inheritdoc />
|
||||
public RefImage<TColor> AsRefImage<TColor>()
|
||||
where TColor : struct, IColor
|
||||
{
|
||||
@ -208,6 +217,7 @@ public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
|
||||
return ref Unsafe.Add(ref MemoryMarshal.GetReference(_buffer.AsSpan()), (_y * _stride) + (_x * ColorFormat.BytesPerPixel));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
for (int y = 0; y < Height; y++)
|
||||
@ -215,6 +225,7 @@ public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
|
||||
yield return this[x, y];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
IEnumerator<IColor> IEnumerable<IColor>.GetEnumerator()
|
||||
{
|
||||
for (int y = 0; y < Height; y++)
|
||||
@ -222,9 +233,11 @@ public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
|
||||
yield return this[x, y];
|
||||
}
|
||||
|
||||
/// <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;
|
||||
@ -240,6 +253,7 @@ public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Equals(IImage<T>? other)
|
||||
{
|
||||
if (other == null) return false;
|
||||
@ -254,6 +268,7 @@ public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Equals(Image<T>? other)
|
||||
{
|
||||
if (other == null) return false;
|
||||
@ -268,5 +283,11 @@ public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool Equals(object? obj) => Equals(obj as Image<T>);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int GetHashCode() => HashCode.Combine(ColorFormat, Width, Height, _buffer.GetHashCode());
|
||||
|
||||
#endregion
|
||||
}
|
||||
@ -124,14 +124,17 @@ internal class IColorImageColumn<T> : IImageColumn
|
||||
private readonly int _length;
|
||||
private readonly int _step;
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Length => _length;
|
||||
|
||||
/// <inheritdoc />
|
||||
public int SizeInBytes => Length * T.ColorFormat.BytesPerPixel;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Indexer
|
||||
|
||||
/// <inheritdoc />
|
||||
public IColor this[int y]
|
||||
{
|
||||
get
|
||||
@ -158,6 +161,7 @@ internal class IColorImageColumn<T> : IImageColumn
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public void CopyTo(Span<IColor> destination)
|
||||
{
|
||||
if (destination == null) throw new ArgumentNullException(nameof(destination));
|
||||
@ -167,6 +171,7 @@ internal class IColorImageColumn<T> : IImageColumn
|
||||
destination[i] = this[i];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void CopyTo(Span<byte> destination)
|
||||
{
|
||||
if (destination == null) throw new ArgumentNullException(nameof(destination));
|
||||
@ -178,6 +183,7 @@ internal class IColorImageColumn<T> : IImageColumn
|
||||
target[i] = Unsafe.As<byte, T>(ref Unsafe.Add(ref dataRef, i * _step));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IColor[] ToArray()
|
||||
{
|
||||
IColor[] array = new IColor[Length];
|
||||
@ -185,12 +191,14 @@ internal class IColorImageColumn<T> : IImageColumn
|
||||
return array;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerator<IColor> GetEnumerator()
|
||||
{
|
||||
for (int i = 0; i < Length; i++)
|
||||
yield return this[i];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
#endregion
|
||||
|
||||
@ -113,12 +113,14 @@ internal class IColorImageColumns<T> : IImageColumns
|
||||
private readonly int _stride;
|
||||
private readonly int _bpp;
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Count => _width;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Indexer
|
||||
|
||||
/// <inheritdoc />
|
||||
public IImageColumn this[int column]
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@ -151,12 +153,14 @@ internal class IColorImageColumns<T> : IImageColumns
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerator<IImageColumn> GetEnumerator()
|
||||
{
|
||||
for (int i = 0; i < _width; i++)
|
||||
yield return this[i];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
#endregion
|
||||
|
||||
@ -117,14 +117,17 @@ internal class IColorImageRow<T> : IImageRow
|
||||
private readonly int _start;
|
||||
private readonly int _length;
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Length => _length;
|
||||
|
||||
/// <inheritdoc />
|
||||
public int SizeInBytes => Length * T.ColorFormat.BytesPerPixel;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Indexer
|
||||
|
||||
/// <inheritdoc />
|
||||
public IColor this[int x]
|
||||
{
|
||||
get
|
||||
@ -150,6 +153,7 @@ internal class IColorImageRow<T> : IImageRow
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public void CopyTo(Span<IColor> destination)
|
||||
{
|
||||
if (destination == null) throw new ArgumentNullException(nameof(destination));
|
||||
@ -159,6 +163,7 @@ internal class IColorImageRow<T> : IImageRow
|
||||
destination[i] = this[i];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void CopyTo(Span<byte> destination)
|
||||
{
|
||||
if (destination == null) throw new ArgumentNullException(nameof(destination));
|
||||
@ -167,6 +172,7 @@ internal class IColorImageRow<T> : IImageRow
|
||||
_buffer.AsSpan().Slice(_start, SizeInBytes).CopyTo(destination);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IColor[] ToArray()
|
||||
{
|
||||
IColor[] array = new IColor[Length];
|
||||
@ -174,12 +180,14 @@ internal class IColorImageRow<T> : IImageRow
|
||||
return array;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerator<IColor> GetEnumerator()
|
||||
{
|
||||
for (int i = 0; i < _length; i++)
|
||||
yield return this[i];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
#endregion
|
||||
|
||||
@ -111,12 +111,14 @@ internal class IColorImageRows<T> : IImageRows
|
||||
private readonly int _height;
|
||||
private readonly int _stride;
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Count => _height;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Indexer
|
||||
|
||||
/// <inheritdoc />
|
||||
public IImageRow this[int row]
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@ -147,12 +149,14 @@ internal class IColorImageRows<T> : IImageRows
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerator<IImageRow> GetEnumerator()
|
||||
{
|
||||
for (int i = 0; i < _height; i++)
|
||||
yield return this[i];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
#endregion
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user