Added color-based ToArray to Image

This commit is contained in:
Darth Affe 2024-07-06 17:12:01 +02:00
parent 1ec67c4d4b
commit 5242845a3e
2 changed files with 17 additions and 2 deletions

View File

@ -73,7 +73,9 @@ public interface IImage : IEnumerable<IColor>
/// Allocates a new array and copies this <see cref="IImage"/> into it.
/// </summary>
/// <returns>The new array containing the data of this <see cref="IImage"/>.</returns>
byte[] ToArray();
byte[] ToRawArray();
IColor[] ToArray();
/// <summary>
/// Represents a list of rows of an image.

View File

@ -109,13 +109,26 @@ public sealed class Image<TColor> : IImage
}
/// <inheritdoc />
public byte[] ToArray()
public byte[] ToRawArray()
{
byte[] array = new byte[SizeInBytes];
CopyTo(array);
return array;
}
//TODO DarthAffe 06.07.2024: This has some potential for optimization
public IColor[] ToArray()
{
IColor[] colors = new IColor[Width * Height];
int counter = 0;
foreach (IImage.IImageRow row in Rows)
foreach (IColor color in row)
colors[counter++] = color;
return colors;
}
/// <inheritdoc />
public RefImage<T> AsRefImage<T>()
where T : struct, IColor