mirror of
https://github.com/DarthAffe/HPPH.git
synced 2025-12-12 13:28:37 +00:00
Added ConvertTo-method to IImage
This commit is contained in:
parent
0731472c24
commit
19c9143fa1
@ -58,7 +58,7 @@ public sealed class Image<T> : IImage<T>
|
||||
get
|
||||
{
|
||||
if ((x < 0) || (y < 0) || (width <= 0) || (height <= 0) || ((x + width) > Width) || ((y + height) > Height)) throw new IndexOutOfRangeException();
|
||||
|
||||
|
||||
return new Image<T>(_buffer, _x + x, _y + y, width, height, _stride);
|
||||
}
|
||||
}
|
||||
@ -123,6 +123,13 @@ public sealed class Image<T> : IImage<T>
|
||||
return new Image<T>(data, 0, 0, width, height, stride);
|
||||
}
|
||||
|
||||
public void ConvertTo<TColor>()
|
||||
where TColor : struct, IColor
|
||||
{
|
||||
for (int i = 0; i < Height; i++)
|
||||
MemoryMarshal.Cast<byte, T>(_buffer.AsSpan().Slice(((i + _y) * _stride) + _x, Width)).ConvertInPlace<T, TColor>();
|
||||
}
|
||||
|
||||
public void CopyTo(Span<T> destination) => CopyTo(MemoryMarshal.AsBytes(destination));
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@ -60,6 +60,8 @@ public interface IImage : IEnumerable<IColor>
|
||||
/// <returns>The <inheritdoc cref="RefImage{TColor}"/>.</returns>
|
||||
RefImage<TColor> AsRefImage<TColor>() where TColor : struct, IColor;
|
||||
|
||||
void ConvertTo<T>() where T : struct, IColor;
|
||||
|
||||
/// <summary>
|
||||
/// Copies the contents of this <see cref="IImage"/> into a destination <see cref="Span{T}"/> instance.
|
||||
/// </summary>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user