Use EmbeddedSpritePalette in D2k.

This commit is contained in:
Paul Chote
2018-10-07 17:39:07 +00:00
parent eb61c45e14
commit 6b7f1c6458
7 changed files with 100 additions and 150 deletions

View File

@@ -12,7 +12,9 @@
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Primitives;
namespace OpenRA.Mods.D2k.SpriteLoaders
@@ -27,6 +29,8 @@ namespace OpenRA.Mods.D2k.SpriteLoaders
public byte[] Data { get; set; }
public bool DisableExportPadding { get { return true; } }
public readonly uint[] Palette = null;
public R8Frame(Stream s)
{
// Scan forward until we find some data
@@ -58,9 +62,20 @@ namespace OpenRA.Mods.D2k.SpriteLoaders
Data = s.ReadBytes(width * height);
// Ignore palette
// Read palette
if (type == 1 && paletteOffset != 0)
s.Seek(520, SeekOrigin.Current);
{
// Skip header
s.ReadUInt32();
s.ReadUInt32();
Palette = new uint[256];
for (var i = 0; i < 256; i++)
{
var packed = s.ReadUInt16();
Palette[i] = (uint)((255 << 24) | ((packed & 0xF800) << 8) | ((packed & 0x7E0) << 5) | ((packed & 0x1f) << 3));
}
}
}
}
@@ -94,11 +109,21 @@ namespace OpenRA.Mods.D2k.SpriteLoaders
var start = s.Position;
var tmp = new List<R8Frame>();
var palettes = new Dictionary<int, uint[]>();
while (s.Position < s.Length)
tmp.Add(new R8Frame(s));
{
var f = new R8Frame(s);
if (f.Palette != null)
palettes.Add(tmp.Count, f.Palette);
tmp.Add(f);
}
s.Position = start;
frames = tmp.ToArray();
if (palettes.Any())
metadata = new TypeDictionary { new EmbeddedSpritePalette(framePalettes: palettes) };
return true;
}
}