2007-10-04 18:16:05 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Text;
|
2007-10-26 13:17:20 +00:00
|
|
|
using System.IO;
|
|
|
|
using CodeImp.DoomBuilder.IO;
|
2007-10-04 18:16:05 +00:00
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Data
|
|
|
|
{
|
2007-10-24 17:25:03 +00:00
|
|
|
public sealed class FlatImage : ImageData
|
2007-10-04 18:16:05 +00:00
|
|
|
{
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
2007-10-26 13:17:20 +00:00
|
|
|
public FlatImage(string name)
|
2007-10-04 18:16:05 +00:00
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
SetName(name);
|
|
|
|
|
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
// This loads the image
|
|
|
|
public override void LoadImage()
|
|
|
|
{
|
2007-10-26 13:17:20 +00:00
|
|
|
Stream lumpdata;
|
|
|
|
MemoryStream mem;
|
|
|
|
IImageReader reader;
|
|
|
|
byte[] membytes;
|
|
|
|
|
2007-10-04 18:16:05 +00:00
|
|
|
// Leave when already loaded
|
|
|
|
if(this.IsLoaded) return;
|
2007-10-26 13:17:20 +00:00
|
|
|
|
2007-10-26 15:28:32 +00:00
|
|
|
lock(this)
|
2007-10-26 13:17:20 +00:00
|
|
|
{
|
2007-10-26 15:28:32 +00:00
|
|
|
// Get the lump data stream
|
|
|
|
lumpdata = General.Map.Data.GetPatchData(Name);
|
|
|
|
if(lumpdata != null)
|
2007-10-26 13:17:20 +00:00
|
|
|
{
|
2007-10-26 15:28:32 +00:00
|
|
|
// Copy lump data to memory
|
|
|
|
lumpdata.Seek(0, SeekOrigin.Begin);
|
|
|
|
membytes = new byte[(int)lumpdata.Length];
|
|
|
|
lumpdata.Read(membytes, 0, (int)lumpdata.Length);
|
|
|
|
mem = new MemoryStream(membytes);
|
|
|
|
mem.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
|
|
|
// Get a reader for the data
|
|
|
|
reader = ImageDataFormat.GetImageReader(mem, ImageDataFormat.DOOMFLAT, General.Map.Data.Palette);
|
|
|
|
if(reader is UnknownImageReader)
|
|
|
|
{
|
|
|
|
// Data is in an unknown format!
|
|
|
|
General.WriteLogLine("WARNING: Flat lump '" + Name + "' data format could not be read!");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read data as bitmap
|
|
|
|
mem.Seek(0, SeekOrigin.Begin);
|
|
|
|
bitmap = reader.ReadAsBitmap(mem);
|
2007-11-10 19:24:52 +00:00
|
|
|
|
|
|
|
// Get width and height from image
|
|
|
|
width = bitmap.Size.Width;
|
|
|
|
height = bitmap.Size.Height;
|
2007-10-26 15:28:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Missing a patch lump!
|
|
|
|
General.WriteLogLine("WARNING: Missing flat lump '" + Name + "'!");
|
2007-10-26 13:17:20 +00:00
|
|
|
}
|
|
|
|
|
2007-10-26 15:28:32 +00:00
|
|
|
// Pass on to base
|
|
|
|
base.LoadImage();
|
2007-10-26 13:17:20 +00:00
|
|
|
}
|
2007-10-04 18:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|