From 06c53cd4a7122ddb727668b666fb924499988aa3 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Wed, 20 May 2020 13:24:55 -0400 Subject: [PATCH] add function to generate a list of colors used by the PictureObjectModel --- .../Multimedia/Picture/PictureObjectModel.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Plugins/UniversalEditor.Plugins.Multimedia/ObjectModels/Multimedia/Picture/PictureObjectModel.cs b/Plugins/UniversalEditor.Plugins.Multimedia/ObjectModels/Multimedia/Picture/PictureObjectModel.cs index c2640309..b28490b7 100644 --- a/Plugins/UniversalEditor.Plugins.Multimedia/ObjectModels/Multimedia/Picture/PictureObjectModel.cs +++ b/Plugins/UniversalEditor.Plugins.Multimedia/ObjectModels/Multimedia/Picture/PictureObjectModel.cs @@ -48,6 +48,27 @@ namespace UniversalEditor.ObjectModels.Multimedia.Picture public List ColorMap { get; } = new List(); + /// + /// Generates a color map as a of the s used in this . + /// + /// The color map of colors used in this . + public List GenerateColorMap() + { + List colorMap = new List(); + for (int index = 0; index < bitmapData.Length; index += 4) + { + byte a = bitmapData[index + 0]; + byte r = bitmapData[index + 1]; + byte g = bitmapData[index + 2]; + byte b = bitmapData[index + 3]; + + Color color = Color.FromRGBAByte(a, r, g, b); + if (!colorMap.Contains(color)) + colorMap.Add(color); + } + return colorMap; + } + public void SetPixel(Color color) { if (lastAddedLocation.X >= mvarWidth && lastAddedLocation.Y >= mvarHeight)