2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
using System;
|
2019-12-29 02:54:12 +00:00
|
|
|
using System.Drawing;
|
2009-04-19 18:07:22 +00:00
|
|
|
using System.IO;
|
|
|
|
using CodeImp.DoomBuilder.IO;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Data
|
|
|
|
{
|
|
|
|
internal sealed class FlatImage : ImageData
|
|
|
|
{
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public FlatImage(string name)
|
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
SetName(name);
|
2015-03-22 20:43:05 +00:00
|
|
|
virtualname = "[Flats]/" + this.name; //mxd
|
2022-03-05 15:57:23 +00:00
|
|
|
texturenamespace = TextureNamespace.FLAT;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
// This loads the image
|
2019-12-29 02:54:12 +00:00
|
|
|
protected override LocalLoadResult LocalLoadImage()
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2019-12-29 02:54:12 +00:00
|
|
|
Bitmap bitmap = null;
|
|
|
|
string error = null;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2019-12-29 02:54:12 +00:00
|
|
|
// Get the lump data stream
|
|
|
|
string flatlocation = string.Empty; //mxd
|
|
|
|
Stream lumpdata = General.Map.Data.GetFlatData(Name, hasLongName, ref flatlocation);
|
|
|
|
if(lumpdata != null)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2019-12-29 02:54:12 +00:00
|
|
|
// Copy lump data to memory
|
|
|
|
byte[] membytes = new byte[(int)lumpdata.Length];
|
|
|
|
|
|
|
|
lock(lumpdata) //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2019-12-29 02:54:12 +00:00
|
|
|
lumpdata.Seek(0, SeekOrigin.Begin);
|
|
|
|
lumpdata.Read(membytes, 0, (int)lumpdata.Length);
|
|
|
|
}
|
2016-08-29 10:06:16 +00:00
|
|
|
|
2019-12-29 02:54:12 +00:00
|
|
|
MemoryStream mem = new MemoryStream(membytes);
|
|
|
|
mem.Seek(0, SeekOrigin.Begin);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2019-12-29 02:54:12 +00:00
|
|
|
// Get a reader for the data
|
2020-01-14 16:25:35 +00:00
|
|
|
bitmap = ImageDataFormat.TryLoadImage(mem, ImageDataFormat.DOOMFLAT, General.Map.Data.Palette);
|
|
|
|
if(bitmap == null)
|
2019-12-29 02:54:12 +00:00
|
|
|
{
|
|
|
|
// Data is in an unknown format!
|
|
|
|
error = "Flat lump \"" + Path.Combine(flatlocation, Name) + "\" data format could not be read. Does this lump contain valid picture data at all?";
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
2019-12-29 02:54:12 +00:00
|
|
|
// Done
|
|
|
|
mem.Dispose();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Missing a patch lump!
|
|
|
|
error = "Missing flat lump \"" + Name + "\". Did you forget to include required resources?";
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
2019-12-29 02:54:12 +00:00
|
|
|
return new LocalLoadResult(bitmap, error, () =>
|
|
|
|
{
|
|
|
|
scale.x = General.Map.Config.DefaultFlatScale;
|
|
|
|
scale.y = General.Map.Config.DefaultFlatScale;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|