From b41d4f5cee673f4ae874096c4c10d175617fda7a Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 12 Feb 2019 12:14:48 +0000 Subject: [PATCH] Allow Pngs to be created from pixel data. --- OpenRA.Game/FileFormats/Png.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/OpenRA.Game/FileFormats/Png.cs b/OpenRA.Game/FileFormats/Png.cs index 508236fead..1b73567dce 100644 --- a/OpenRA.Game/FileFormats/Png.cs +++ b/OpenRA.Game/FileFormats/Png.cs @@ -161,6 +161,25 @@ namespace OpenRA.FileFormats } } + public Png(byte[] data, int width, int height, Color[] palette = null, + Dictionary embeddedData = null) + { + var expectLength = width * height; + if (palette == null) + expectLength *= 4; + + if (data.Length != expectLength) + throw new InvalidDataException("Input data does not match expected length"); + Width = width; + Height = height; + + Palette = palette; + Data = data; + + if (embeddedData != null) + EmbeddedData = embeddedData; + } + public static bool Verify(Stream s) { var pos = s.Position;