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 ;
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
2014-11-25 11:52:01 +00:00
isFlat = true ; //mxd
2009-04-19 18:07:22 +00:00
// 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
2016-03-14 21:53:53 +00:00
string flatlocation = string . Empty ; //mxd
Stream lumpdata = General . Map . Data . GetFlatData ( Name , hasLongName , ref flatlocation ) ;
2009-04-19 18:07:22 +00:00
if ( lumpdata ! = null )
{
// Copy lump data to memory
2014-10-07 08:56:21 +00:00
byte [ ] membytes = new byte [ ( int ) lumpdata . Length ] ;
2016-08-29 10:06:16 +00:00
lock ( lumpdata ) //mxd
{
lumpdata . Seek ( 0 , SeekOrigin . Begin ) ;
lumpdata . Read ( membytes , 0 , ( int ) lumpdata . Length ) ;
}
2014-10-07 08:56:21 +00:00
MemoryStream mem = new MemoryStream ( membytes ) ;
2009-04-19 18:07:22 +00:00
mem . Seek ( 0 , SeekOrigin . Begin ) ;
// Get a reader for the data
2014-10-07 08:56:21 +00:00
IImageReader reader = ImageDataFormat . GetImageReader ( mem , ImageDataFormat . DOOMFLAT , General . Map . Data . Palette ) ;
2009-04-19 18:07:22 +00:00
if ( reader is UnknownImageReader )
{
// Data is in an unknown format!
2016-03-14 21:53:53 +00:00
General . ErrorLogger . Add ( ErrorType . 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
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 )
{
2010-01-02 20:22:05 +00:00
// Get width and height from image and set the scale
2009-04-19 18:07:22 +00:00
width = bitmap . Size . Width ;
height = bitmap . Size . Height ;
2010-01-02 20:22:05 +00:00
scale . x = General . Map . Config . DefaultFlatScale ;
scale . y = General . Map . Config . DefaultFlatScale ;
2009-04-19 18:07:22 +00:00
}
else
{
loadfailed = true ;
}
}
else
{
// Missing a patch lump!
2016-02-22 08:04:06 +00:00
General . ErrorLogger . Add ( ErrorType . Error , "Missing flat lump \"" + Name + "\". Did you forget to include required resources?" ) ;
2009-04-19 18:07:22 +00:00
loadfailed = true ;
}
// Pass on to base
base . LocalLoadImage ( ) ;
}
}
#endregion
}
}