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.
This commit is contained in:
RoosterDragon
2024-04-01 14:43:11 +01:00
committed by Gustas
parent 2481bddf58
commit 7859b913bc

View File

@@ -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);