2007-10-01 20:57:41 +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.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Text;
|
2007-10-08 14:29:31 +00:00
|
|
|
using System.Drawing;
|
|
|
|
using System.Drawing.Imaging;
|
|
|
|
using CodeImp.DoomBuilder.Rendering;
|
|
|
|
using CodeImp.DoomBuilder.IO;
|
|
|
|
using System.IO;
|
2007-10-01 20:57:41 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Data
|
|
|
|
{
|
2007-10-08 14:29:31 +00:00
|
|
|
internal sealed unsafe class TextureImage : ImageData
|
2007-10-01 20:57:41 +00:00
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
2007-10-04 18:16:05 +00:00
|
|
|
private List<TexturePatch> patches;
|
2007-10-07 22:21:47 +00:00
|
|
|
private float scalex;
|
|
|
|
private float scaley;
|
|
|
|
|
2007-10-01 20:57:41 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
2007-10-07 22:21:47 +00:00
|
|
|
public TextureImage(string name, int width, int height, float scalex, float scaley)
|
2007-10-01 20:57:41 +00:00
|
|
|
{
|
|
|
|
// Initialize
|
2007-10-07 22:21:47 +00:00
|
|
|
this.width = width;
|
|
|
|
this.height = height;
|
|
|
|
this.scalex = scalex;
|
|
|
|
this.scaley = scaley;
|
2007-10-08 14:29:31 +00:00
|
|
|
this.scaledwidth = (float)width * scalex;
|
|
|
|
this.scaledheight = (float)height * scaley;
|
2007-10-04 18:16:05 +00:00
|
|
|
this.patches = new List<TexturePatch>();
|
|
|
|
SetName(name);
|
|
|
|
|
2007-10-01 20:57:41 +00:00
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Diposer
|
|
|
|
public override void Dispose()
|
|
|
|
{
|
|
|
|
// Not already disposed?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
|
|
|
// Clean up
|
|
|
|
|
|
|
|
// Done
|
|
|
|
base.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
2007-10-04 18:16:05 +00:00
|
|
|
// This adds a patch to the texture
|
|
|
|
public void AddPatch(TexturePatch patch)
|
|
|
|
{
|
|
|
|
// Add it
|
|
|
|
patches.Add(patch);
|
|
|
|
}
|
|
|
|
|
2007-10-01 20:57:41 +00:00
|
|
|
// This loads the image
|
|
|
|
public override void LoadImage()
|
|
|
|
{
|
2007-10-08 14:29:31 +00:00
|
|
|
uint datalength = (uint)(width * height * sizeof(PixelColor));
|
|
|
|
DoomPictureReader reader = new DoomPictureReader(General.Map.Data.Palette);
|
|
|
|
BitmapData bitmapdata;
|
|
|
|
PixelColor* pixels;
|
|
|
|
Stream patchdata;
|
|
|
|
|
2007-10-01 20:57:41 +00:00
|
|
|
// Leave when already loaded
|
|
|
|
if(this.IsLoaded) return;
|
|
|
|
|
2007-10-08 14:29:31 +00:00
|
|
|
// Create texture bitmap
|
|
|
|
bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
|
|
|
|
bitmapdata = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
|
|
|
|
pixels = (PixelColor*)bitmapdata.Scan0.ToPointer();
|
|
|
|
General.ZeroMemory(new IntPtr(pixels), width * height * sizeof(PixelColor));
|
|
|
|
|
|
|
|
// Go for all patches
|
|
|
|
foreach(TexturePatch p in patches)
|
|
|
|
{
|
|
|
|
// Get the patch data stream
|
|
|
|
patchdata = General.Map.Data.GetPatchData(p.lumpname);
|
|
|
|
if(patchdata != null)
|
|
|
|
{
|
|
|
|
// Read the patch and draw it onto the memory
|
|
|
|
patchdata.Seek(0, SeekOrigin.Begin);
|
|
|
|
reader.DrawToPixelData(patchdata, pixels, width, height, p.x, p.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Done
|
|
|
|
bitmap.UnlockBits(bitmapdata);
|
2007-10-01 20:57:41 +00:00
|
|
|
|
|
|
|
// Pass on to base
|
|
|
|
base.LoadImage();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|