UltimateZoneBuilder/Source/Core/Data/FlatImage.cs
MaxED 6b765f5a27 Added long texture names support (enabled when "longtexturenames" game configuration property is set to true and "Use long texture names" check box is checked in Map Options).
Open Map in Current WAD: resources are now reloaded when current and target map's resources don't match.
Added some boilerplate to UniversalParser and PK3FileImage.
Internal: ImageSelectorControl now has "UsePreviews" property.
Internal: added ConfigurablePictureBox.
Updated ZDoom_DECORATE.cfg.
2014-11-25 11:52:01 +00:00

111 lines
2.8 KiB
C#

#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;
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);
isFlat = true; //mxd
// We have no destructor
GC.SuppressFinalize(this);
}
#endregion
#region ================== Methods
// This loads the image
protected override void LocalLoadImage()
{
// Leave when already loaded
if(this.IsImageLoaded) return;
lock(this)
{
// Get the lump data stream
Stream lumpdata = General.Map.Data.GetFlatData(Name, hasLongName);
if(lumpdata != null)
{
// Copy lump data to memory
lumpdata.Seek(0, SeekOrigin.Begin);
byte[] membytes = new byte[(int)lumpdata.Length];
lumpdata.Read(membytes, 0, (int)lumpdata.Length);
MemoryStream mem = new MemoryStream(membytes);
mem.Seek(0, SeekOrigin.Begin);
// Get a reader for the data
IImageReader reader = ImageDataFormat.GetImageReader(mem, ImageDataFormat.DOOMFLAT, General.Map.Data.Palette);
if(reader is UnknownImageReader)
{
// Data is in an unknown format!
General.ErrorLogger.Add(ErrorType.Error, "Flat lump '" + Name + "' data format could not be read. Does this lump contain valid picture data at all?");
bitmap = null;
}
else
{
// Read data as bitmap
mem.Seek(0, SeekOrigin.Begin);
if(bitmap != null) bitmap.Dispose();
bitmap = reader.ReadAsBitmap(mem);
}
// Done
mem.Dispose();
if(bitmap != null)
{
// Get width and height from image and set the scale
width = bitmap.Size.Width;
height = bitmap.Size.Height;
scale.x = General.Map.Config.DefaultFlatScale;
scale.y = General.Map.Config.DefaultFlatScale;
}
else
{
loadfailed = true;
}
}
else
{
// Missing a patch lump!
General.ErrorLogger.Add(ErrorType.Error, "Missing flat lump '" + Name + "'. Did you forget to include required resources?");
loadfailed = true;
}
// Pass on to base
base.LocalLoadImage();
}
}
#endregion
}
}