mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-07-16 02:56:44 -04:00
Added FSO.Files for use with the API server
Don't ask me. FreeSO is the prime example of dependency hell.
This commit is contained in:
parent
4b5e584eeb
commit
8fec258215
104 changed files with 14653 additions and 163 deletions
79
server/tso.files/Formats/IFF/Chunks/PALT.cs
Executable file
79
server/tso.files/Formats/IFF/Chunks/PALT.cs
Executable file
|
@ -0,0 +1,79 @@
|
|||
using System.IO;
|
||||
using FSO.Files.Utils;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace FSO.Files.Formats.IFF.Chunks
|
||||
{
|
||||
/// <summary>
|
||||
/// This chunk type holds a color palette.
|
||||
/// </summary>
|
||||
public class PALT : IffChunk
|
||||
{
|
||||
public PALT()
|
||||
{
|
||||
}
|
||||
|
||||
public PALT(Color color)
|
||||
{
|
||||
Colors = new Color[256];
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
Colors[i] = color;
|
||||
}
|
||||
}
|
||||
|
||||
public Color[] Colors;
|
||||
public int References = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Reads a PALT chunk from a stream.
|
||||
/// </summary>
|
||||
/// <param name="iff">An Iff instance.</param>
|
||||
/// <param name="stream">A Stream object holding a PALT chunk.</param>
|
||||
public override void Read(IffFile iff, Stream stream)
|
||||
{
|
||||
using (var io = IoBuffer.FromStream(stream, ByteOrder.LITTLE_ENDIAN))
|
||||
{
|
||||
var version = io.ReadUInt32();
|
||||
var numEntries = io.ReadUInt32();
|
||||
var reserved = io.ReadBytes(8);
|
||||
|
||||
Colors = new Color[numEntries];
|
||||
for (var i = 0; i < numEntries; i++)
|
||||
{
|
||||
var r = io.ReadByte();
|
||||
var g = io.ReadByte();
|
||||
var b = io.ReadByte();
|
||||
Colors[i] = new Color(r, g, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Write(IffFile iff, Stream stream)
|
||||
{
|
||||
using (var io = IoWriter.FromStream(stream, ByteOrder.LITTLE_ENDIAN))
|
||||
{
|
||||
io.WriteUInt32(0);
|
||||
io.WriteUInt32((uint)Colors.Length);
|
||||
io.WriteBytes(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 });
|
||||
foreach (var col in Colors)
|
||||
{
|
||||
io.WriteByte(col.R);
|
||||
io.WriteByte(col.G);
|
||||
io.WriteByte(col.B);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool PalMatch(Color[] data)
|
||||
{
|
||||
for (var i=0; i<Colors.Length; i++)
|
||||
{
|
||||
if (i >= data.Length) return true;
|
||||
if (data[i].A != 0 && data[i] != Colors[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue