Skip to content

Commit

Permalink
Trim memory usage of Png.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
RoosterDragon committed Apr 1, 2024
1 parent 281035e commit 1c6bb4a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions OpenRA.Game/FileFormats/Png.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public Png(Stream s)

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);
Expand Down

0 comments on commit 1c6bb4a

Please sign in to comment.