From 5242845a3ea1e44c1a2eecd824c174a39977f85d Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 6 Jul 2024 17:12:01 +0200 Subject: [PATCH] Added color-based ToArray to Image --- HPPH/Images/IImage.cs | 4 +++- HPPH/Images/Image.cs | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/HPPH/Images/IImage.cs b/HPPH/Images/IImage.cs index bd5cac6..c1fcc61 100644 --- a/HPPH/Images/IImage.cs +++ b/HPPH/Images/IImage.cs @@ -73,7 +73,9 @@ public interface IImage : IEnumerable /// Allocates a new array and copies this into it. /// /// The new array containing the data of this . - byte[] ToArray(); + byte[] ToRawArray(); + + IColor[] ToArray(); /// /// Represents a list of rows of an image. diff --git a/HPPH/Images/Image.cs b/HPPH/Images/Image.cs index 3833d78..2bcb48a 100644 --- a/HPPH/Images/Image.cs +++ b/HPPH/Images/Image.cs @@ -109,13 +109,26 @@ public sealed class Image : IImage } /// - 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; + } + /// public RefImage AsRefImage() where T : struct, IColor