mirror of
https://github.com/DarthAffe/HPPH.git
synced 2025-12-12 13:28:37 +00:00
Added Wrap-Methods to Image and RefImage for allocation free creation
This commit is contained in:
parent
536a462540
commit
cfdd95f079
@ -125,6 +125,14 @@ public sealed class Image<T> : IImage<T>, IEquatable<Image<T>>
|
||||
return new Image<T>(data, 0, 0, width, height, stride);
|
||||
}
|
||||
|
||||
public static Image<T> Wrap(byte[] buffer, int width, int height, int stride)
|
||||
{
|
||||
if (stride < width) throw new ArgumentException("Stride can't be smaller than width.");
|
||||
if (buffer.Length < (height * stride)) throw new ArgumentException("Not enough data in the buffer.");
|
||||
|
||||
return new Image<T>(buffer, 0, 0, width, height, stride);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IImage<TColor> ConvertTo<TColor>()
|
||||
where TColor : struct, IColor
|
||||
|
||||
@ -86,6 +86,17 @@ public readonly ref struct RefImage<T>
|
||||
|
||||
#region Methods
|
||||
|
||||
public static RefImage<T> Wrap(ReadOnlySpan<T> buffer, int width, int height)
|
||||
=> Wrap(MemoryMarshal.AsBytes(buffer), width, height, width * T.ColorFormat.BytesPerPixel);
|
||||
|
||||
public static RefImage<T> Wrap(ReadOnlySpan<byte> buffer, int width, int height, int stride)
|
||||
{
|
||||
if (stride < width) throw new ArgumentException("Stride can't be smaller than width.");
|
||||
if (buffer.Length < (height * stride)) throw new ArgumentException("Not enough data in the buffer.");
|
||||
|
||||
return new RefImage<T>(buffer, 0, 0, width, height, stride);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies the contents of this <see cref="RefImage{T}"/> into a destination <see cref="Span{T}"/> instance.
|
||||
/// </summary>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user