I'm gonna' download this: please dun' eat my maps dar' mister application.
BSP improvements are awesome. I would love to be able to use lowers LODs however ;p
Bitmap Display Code: do with as you will, this is old code, so forgive the layout and horrid syntax
Code: Select all
/// <summary>
/// Returns Decoded Byte Array Of Bitmap Raw
/// </summary>
/// <param name="_width">Width Of Image</param>
/// <param name="_height">Height Of Image</param>
/// <param name="_offset">Image Raw Offset</param>
/// <returns></returns>
internal byte[] DecodeBitmapRaw(ref short _Width_, ref short _Height_, int _Offset, long _Pointer, out PixelFormat _pixelFormat, out int _lengthMiltiplier)
{
#region Decode
FileStream fs = Map.GetResourceStream(_Pointer);
BinaryReader _Map = new BinaryReader(fs);
_Map.BaseStream.Position = _Offset;
byte[] RecodedLOD;
byte[] DecodedLOD;
_pixelFormat = PixelFormat.Format32bppArgb;
_lengthMiltiplier = 4;
DecodedLOD = _Map.ReadBytes(LOD1Size);
if (DecodedLOD.Length == 0) return null;
switch (Type)
{
case TypeEnum.Texture_2D:
{
switch (Format)
{
case FormatEnum.DXT1://Working
DecodedLOD = Soffish.BitmapSection_old.DecodeDXT1(_Width_, _Height_, DecodedLOD);
break;
case FormatEnum.DXT2And3://Working
_Width_ = BitmapMethods.CalculateTrueDimensions(_Height_, _Width_, Format, LOD1Size, 8);
DecodedLOD = Soffish.BitmapSection_old.DecodeDXT23(_Width_, _Height_, DecodedLOD);
break;
case FormatEnum.DXT4And5://Working
DecodedLOD = Soffish.BitmapSection_old.DecodeDXT45(_Width_, _Height_, DecodedLOD);
break;
case FormatEnum.A8R8G8B8://Working?
if (Swizzle == true)
DecodedLOD = BitmapSection_old.Swizzle(DecodedLOD, _Width_, _Height_, Depth, 32, true);
_Width_ = BitmapMethods.CalculateTrueDimensions(_Height_, _Width_, Format, LOD1Size, 32);
break;
case FormatEnum.X8R8G8B8://Working
if (Swizzle == true)
DecodedLOD = BitmapSection_old.Swizzle(DecodedLOD, _Width_, _Height_, Depth, 32, true);
_pixelFormat = PixelFormat.Format32bppRgb;
break;
case FormatEnum.A4R4G4B4://Working
if (Swizzle == true)
DecodedLOD = BitmapSection_old.Swizzle(DecodedLOD, PixelOffset, _Width_, _Height_, Depth, 16, true);
_Width_ = BitmapMethods.CalculateTrueDimensions(_Height_, _Width_, Format, LOD1Size, 32);
int QuarterSourceDataLength = DecodedLOD.Length;
RecodedLOD = new byte[DecodedLOD.Length * 2];
for (int i = 0; i < QuarterSourceDataLength; i += 2)
{
RecodedLOD[(i * 2) + 3] = (byte)(DecodedLOD[i] & 0XF0);
RecodedLOD[(i * 2) + 2] = (byte)(DecodedLOD[i] & 0X0F);
RecodedLOD[(i * 2) + 1] = (byte)(DecodedLOD[i + 1] & 0XF0);
RecodedLOD[(i * 2)] = (byte)(DecodedLOD[i + 1] & 0X0F);
}
DecodedLOD = RecodedLOD;
break;
case FormatEnum.U8V8://Working
if (Swizzle == true)
DecodedLOD = BitmapSection_old.Swizzle(DecodedLOD, PixelOffset, _Width_, _Height_, Depth, 16, true);
_pixelFormat = PixelFormat.Format32bppRgb;
DecodedLOD = Soffish.BitmapSection_old.DecodeU8V8((float)_Width_, (float)_Height_, DecodedLOD, MipMapCount, 16F);
RecodedLOD = new byte[DecodedLOD.Length * 2];
for (int i = 0; i < DecodedLOD.Length; i += 2)
{
int a = i * 2;
RecodedLOD[a + 3] = 0;//unused
RecodedLOD[a + 2] = BitmapMethods.CalculateU8V8Color(DecodedLOD[i]);// > 127 ? (byte)(256 - DecodedLOD[i]) : (byte)DecodedLOD[i];//red
RecodedLOD[a + 1] = BitmapMethods.CalculateU8V8Color(DecodedLOD[i + 1]);// > 127 ? (byte)(256 - DecodedLOD[i + 1]) : (byte)DecodedLOD[i + 1]; ;//green
RecodedLOD[a] = 255;//CalculateUVW(DecodedLOD[i + 1], DecodedLOD[i]);
}
DecodedLOD = RecodedLOD;
break;
case FormatEnum.A1R5G5B5://Working
if (Swizzle == true)
DecodedLOD = BitmapSection_old.Swizzle(DecodedLOD, PixelOffset, _Width_, _Height_, Depth, 16, true);
_lengthMiltiplier = 2;
_pixelFormat = PixelFormat.Format16bppArgb1555;
break;
case FormatEnum.R5G6B5://Working
if (Swizzle == true)
DecodedLOD = BitmapSection_old.Swizzle(DecodedLOD, PixelOffset, _Width_, _Height_, Depth, 16, true);
_lengthMiltiplier = 2;
_pixelFormat = PixelFormat.Format16bppRgb565;
break;
case FormatEnum.A8Y8://Working
if (Swizzle == true)
DecodedLOD = BitmapSection_old.Swizzle(DecodedLOD, PixelOffset, _Width_, _Height_, Depth, 16, true);
_Width_ = BitmapMethods.CalculateTrueDimensions(_Height_, _Width_, Format, LOD1Size, 16);
RecodedLOD = new byte[DecodedLOD.Length * 2];
for (int i = 0; i < DecodedLOD.Length; i += 2)
{
RecodedLOD[i * 2] = DecodedLOD[i + 1];
RecodedLOD[(i * 2) + 1] = DecodedLOD[i + 1];
RecodedLOD[(i * 2) + 2] = DecodedLOD[i + 1];
RecodedLOD[(i * 2) + 3] = DecodedLOD[i];
}
DecodedLOD = RecodedLOD;
break;
case FormatEnum.P8://Working
if (Swizzle == true)
DecodedLOD = BitmapSection_old.Swizzle(DecodedLOD, PixelOffset, _Width_, _Height_, Depth, 8, true);
if (!BitmapSection_old.H2PaletteLoaded) BitmapSection_old.LoadHalo2Palette();
RecodedLOD = new byte[DecodedLOD.Length * 4];
for (int i = 0; i < DecodedLOD.Length; i++)
{
int a = i * 4;
RecodedLOD[a] = BitmapSection_old.H2Palette[DecodedLOD[i]].R;
RecodedLOD[a + 1] = BitmapSection_old.H2Palette[DecodedLOD[i]].G;
RecodedLOD[a + 2] = BitmapSection_old.H2Palette[DecodedLOD[i]].B;
RecodedLOD[a + 3] = BitmapSection_old.H2Palette[DecodedLOD[i]].A;
}
DecodedLOD = RecodedLOD;
break;
case FormatEnum.Y8://Working
if (Swizzle == true)
DecodedLOD = BitmapSection_old.Swizzle(DecodedLOD, PixelOffset, _Width_, _Height_, Depth, 8, true);
RecodedLOD = new byte[DecodedLOD.Length * 4];
for (int i = 0; i < DecodedLOD.Length; i++)
{
int a = i * 4;
RecodedLOD[a] = DecodedLOD[i];
RecodedLOD[a + 1] = DecodedLOD[i];
RecodedLOD[a + 2] = DecodedLOD[i];
RecodedLOD[a + 3] = 255;
}
DecodedLOD = RecodedLOD;
break;
case FormatEnum.Lightmap://Not Working?
//if (Swizzle)
// DecodedLOD = BitmapFunctions.Swizzle(DecodedLOD, PixelOffset, _Width_, _Height_, Depth, 8, true);
//RecodedLOD = new byte[DecodedLOD.Length * 4];
//LightMap.Palette Palette = Map.Sbsp[SBSPIndex, Tags.SearchType.Index].LightMap.Palettes[PaletteIndex];
//for (int i = 0; i < DecodedLOD.Length; i++)
//{
// int a = i * 4;
// RecodedLOD[a + 0] = Palette.Colors[DecodedLOD[i]].R;
// RecodedLOD[a + 1] = Palette.Colors[DecodedLOD[i]].G;
// RecodedLOD[a + 2] = Palette.Colors[DecodedLOD[i]].B;
// RecodedLOD[a + 3] = Palette.Colors[DecodedLOD[i]].A;
//}
//DecodedLOD = RecodedLOD;
break;
case FormatEnum.AY8:
if (Swizzle == true)
DecodedLOD = BitmapSection_old.Swizzle(DecodedLOD, PixelOffset, _Width_, _Height_, Depth, 8, true);
_Width_ = BitmapMethods.CalculateTrueDimensions(_Height_, _Width_, Format, LOD1Size, 8);
RecodedLOD = new byte[DecodedLOD.Length * 4];
for (int i = 0; i < DecodedLOD.Length; i++)
{
int a = i * 4;
RecodedLOD[a] = (byte)(DecodedLOD[i]);
RecodedLOD[a + 1] = (byte)(DecodedLOD[i]);
RecodedLOD[a + 2] = (byte)(DecodedLOD[i]);
RecodedLOD[a + 3] = (byte)(DecodedLOD[i]);
}
DecodedLOD = RecodedLOD;
break;
case FormatEnum.A8://Working
if (Swizzle == true)
DecodedLOD = BitmapSection_old.Swizzle(DecodedLOD, PixelOffset, _Width_, _Height_, Depth, 8, true);
_Width_ = BitmapMethods.CalculateTrueDimensions(_Height_, _Width_, Format, LOD1Size, 8);
RecodedLOD = new byte[DecodedLOD.Length * 4];
for (int i = 0; i < DecodedLOD.Length; i++)
{
int a = i * 4;
RecodedLOD[a] = 255;
RecodedLOD[a + 1] = 255;
RecodedLOD[a + 2] = 255;
RecodedLOD[a + 3] = DecodedLOD[i];
}
DecodedLOD = RecodedLOD;
break;
default:
return null;
}
break;
}
case TypeEnum.Texture_3D:
{
switch (Format)
{
case FormatEnum.A8Y8://Working
if (Swizzle == true)
DecodedLOD = BitmapSection_old.Swizzle(DecodedLOD, PixelOffset, _Width_, _Height_, Depth, 16, true);
_Width_ = BitmapMethods.CalculateTrueDimensions(_Height_, _Width_, Format, LOD1Size, 16);
RecodedLOD = new byte[DecodedLOD.Length * 2];
for (int i = 0; i < DecodedLOD.Length; i += 2)
{
RecodedLOD[i * 2] = DecodedLOD[i + 1];
RecodedLOD[(i * 2) + 1] = DecodedLOD[i + 1];
RecodedLOD[(i * 2) + 2] = DecodedLOD[i + 1];
RecodedLOD[(i * 2) + 3] = DecodedLOD[i];
}
_Width_ *= Depth;
DecodedLOD = RecodedLOD;
break;
case FormatEnum.AY8:
if (Swizzle == true)
DecodedLOD = BitmapSection_old.Swizzle(DecodedLOD, PixelOffset, _Width_, _Height_, Depth, 8, true);
_Width_ = BitmapMethods.CalculateTrueDimensions(_Height_, _Width_, Format, LOD1Size, 16);
RecodedLOD = new byte[DecodedLOD.Length * 4];
for (int i = 0; i < DecodedLOD.Length; i++)
{
int a = i * 4;
RecodedLOD[a] = DecodedLOD[i] == 0 ? (byte)255 : (byte)0;
RecodedLOD[a + 1] = (byte)255;
RecodedLOD[a + 2] = (byte)255;
RecodedLOD[a + 3] = (byte)255;
}
_Width_ *= Depth;
DecodedLOD = RecodedLOD;
break;
}
break;
}
case TypeEnum.Cubemap:
{
switch (Format)
{
case FormatEnum.DXT1://Working
DecodedLOD = Soffish.BitmapSection_old.DecodeCubemap(_Height_, DecodedLOD, 4, MipMapCount, 86);
DecodedLOD = Soffish.BitmapSection_old.DecodeDXT1(_Width_, _Height_ * 6, DecodedLOD);
_Height_ *= 6;
break;
case FormatEnum.X8R8G8B8://Working
int Padding = BitmapMethods.CalculateCubemapPadding(Width, Height, MipMapCount, 32, LOD1Size);
DecodedLOD = Soffish.BitmapSection_old.DecodeCubemap(_Height_, DecodedLOD, 32, MipMapCount, Padding);
_Height_ *= 6;
if (Swizzle == true)
DecodedLOD = BitmapSection_old.Swizzle(DecodedLOD, _Width_, _Height_, Depth, 32, true);
break;
}
break;
}
case TypeEnum.Sprite:
{
break;
}
}
return DecodedLOD;
#endregion
}
public enum TypeEnum : short
{
Texture_2D = 0,
Texture_3D = 1,
Cubemap = 2,
Sprite = 3
}
public enum FormatEnum
{
A8 = 0,
Y8 = 1,
AY8 = 2,
A8Y8 = 3,
R5G6B5 = 6,
A1R5G5B5 = 8,
A4R4G4B4 = 9,
X8R8G8B8 = 10,
A8R8G8B8 = 11,
DXT1 = 14,
DXT2And3 = 15,
DXT4And5 = 16,
P8 = 17,
Lightmap = 18,
U8V8 = 22
}