From 7859b913bcf4aed0c72c2d21fa133454082132b0 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Mon, 1 Apr 2024 14:43:11 +0100 Subject: [PATCH] Trim memory usage of Png. For indexed PNGs, we only need to allocate a palette large enough to accommodate the number of indexed colours in the image. For images that don't use all 256 colours, this slightly reduces the memory usage for these images. --- OpenRA.Game/FileFormats/Png.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OpenRA.Game/FileFormats/Png.cs b/OpenRA.Game/FileFormats/Png.cs index 2e1463af7c..f4b603fba0 100644 --- a/OpenRA.Game/FileFormats/Png.cs +++ b/OpenRA.Game/FileFormats/Png.cs @@ -94,8 +94,8 @@ namespace OpenRA.FileFormats case "PLTE": { - Palette = new Color[256]; - for (var i = 0; i < length / 3; i++) + Palette = new Color[length / 3]; + for (var i = 0; i < Palette.Length; i++) { var r = ms.ReadUInt8(); var g = ms.ReadUInt8(); var b = ms.ReadUInt8(); Palette[i] = Color.FromArgb(r, g, b);