Move R8 sprite loading into Mods.D2k.
This commit is contained in:
@@ -1,80 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.FileFormats
|
||||
{
|
||||
public class R8Reader : ISpriteSource
|
||||
{
|
||||
class R8Image : ISpriteFrame
|
||||
{
|
||||
public Size Size { get; private set; }
|
||||
public Size FrameSize { get; private set; }
|
||||
public float2 Offset { get; private set; }
|
||||
public byte[] Data { get; set; }
|
||||
public bool DisableExportPadding { get { return true; } }
|
||||
|
||||
public R8Image(Stream s)
|
||||
{
|
||||
// Scan forward until we find some data
|
||||
var type = s.ReadUInt8();
|
||||
while (type == 0)
|
||||
type = s.ReadUInt8();
|
||||
|
||||
var width = s.ReadInt32();
|
||||
var height = s.ReadInt32();
|
||||
var x = s.ReadInt32();
|
||||
var y = s.ReadInt32();
|
||||
|
||||
Size = new Size(width, height);
|
||||
Offset = new int2(width / 2 - x, height / 2 - y);
|
||||
|
||||
/*var imageOffset = */
|
||||
s.ReadInt32();
|
||||
var paletteOffset = s.ReadInt32();
|
||||
var bpp = s.ReadUInt8();
|
||||
if (bpp != 8)
|
||||
throw new InvalidDataException("Error: {0} bits per pixel are not supported.".F(bpp));
|
||||
|
||||
var frameHeight = s.ReadUInt8();
|
||||
var frameWidth = s.ReadUInt8();
|
||||
FrameSize = new Size(frameWidth, frameHeight);
|
||||
|
||||
// Skip alignment byte
|
||||
s.ReadUInt8();
|
||||
|
||||
Data = s.ReadBytes(width * height);
|
||||
|
||||
// Ignore palette
|
||||
if (type == 1 && paletteOffset != 0)
|
||||
s.Seek(520, SeekOrigin.Current);
|
||||
}
|
||||
}
|
||||
|
||||
public IReadOnlyList<ISpriteFrame> Frames { get; private set; }
|
||||
|
||||
public readonly int ImageCount;
|
||||
public R8Reader(Stream stream)
|
||||
{
|
||||
var frames = new List<R8Image>();
|
||||
while (stream.Position < stream.Length)
|
||||
{
|
||||
frames.Add(new R8Image(stream));
|
||||
ImageCount++;
|
||||
}
|
||||
|
||||
Frames = frames.ToArray().AsReadOnly();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ using OpenRA.FileFormats;
|
||||
namespace OpenRA.Graphics
|
||||
{
|
||||
// TODO: Most of this should be moved into the format parsers themselves.
|
||||
public enum SpriteType { Unknown, ShpD2, TmpTD, TmpRA, TmpTS, R8 }
|
||||
public enum SpriteType { Unknown, ShpD2, TmpTD, TmpRA, TmpTS }
|
||||
public static class SpriteSource
|
||||
{
|
||||
static bool IsTmpRA(Stream s)
|
||||
@@ -104,30 +104,8 @@ namespace OpenRA.Graphics
|
||||
return b == 5 || b <= 3;
|
||||
}
|
||||
|
||||
static bool IsR8(Stream s)
|
||||
{
|
||||
var start = s.Position;
|
||||
|
||||
// First byte is nonzero
|
||||
if (s.ReadUInt8() == 0)
|
||||
{
|
||||
s.Position = start;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check the format of the first frame
|
||||
s.Position = start + 25;
|
||||
var d = s.ReadUInt8();
|
||||
|
||||
s.Position = start;
|
||||
return d == 8;
|
||||
}
|
||||
|
||||
public static SpriteType DetectSpriteType(Stream s)
|
||||
{
|
||||
if (IsR8(s))
|
||||
return SpriteType.R8;
|
||||
|
||||
if (IsTmpRA(s))
|
||||
return SpriteType.TmpRA;
|
||||
|
||||
@@ -148,8 +126,6 @@ namespace OpenRA.Graphics
|
||||
var type = DetectSpriteType(s);
|
||||
switch (type)
|
||||
{
|
||||
case SpriteType.R8:
|
||||
return new R8Reader(s);
|
||||
case SpriteType.TmpRA:
|
||||
return new TmpRAReader(s);
|
||||
case SpriteType.TmpTD:
|
||||
|
||||
@@ -277,7 +277,6 @@
|
||||
<Compile Include="FileFormats\XccLocalDatabase.cs" />
|
||||
<Compile Include="FileFormats\HvaReader.cs" />
|
||||
<Compile Include="FileFormats\PngLoader.cs" />
|
||||
<Compile Include="FileFormats\R8Reader.cs" />
|
||||
<Compile Include="FileFormats\ShpD2Reader.cs" />
|
||||
<Compile Include="FileFormats\TmpRAReader.cs" />
|
||||
<Compile Include="FileFormats\TmpTDReader.cs" />
|
||||
|
||||
Reference in New Issue
Block a user