public void CreateTexture(BinaryReader BReader)
{
byte[] Bytes = FullImageBytes(BReader);
if (Bytes == null) return;
LastAccess = Main.Time;
ImageTexture = new Texture(DXManager.Device, Size.Width, Size.Height, 0, Usage.None, Format.A8R8G8B8, Pool.Managed);
GraphicsStream GS = ImageTexture.LockRectangle(0, LockFlags.Discard);
GS.Write(Bytes);
GS.Dispose();
ImageTexture.UnlockRectangle(0);
}
private byte[] FullImageBytes(BinaryReader BReader)
{
byte[] Pixels = new byte[Size.Width * Size.Height * 4];
byte[] FileBytes = BReader.ReadBytes(Length * 2);
int End = 0, OffSet = 0, Count;
for (int Y = 0; Y < Size.Height; Y++)
{
OffSet = End;
End += (FileBytes[OffSet + 1] << 8 | FileBytes[OffSet]) * 2 + 2;
OffSet += 2; //New line
for (int X = 0; X < Size.Width; )
switch (FileBytes[OffSet])
{
case 192: //No Colour
X += FileBytes[OffSet + 3] << 8 | FileBytes[OffSet + 2];
OffSet += 4;
break;
case 193: //Solid Colour
case 194: //Overlay Colour
case 195: // ??
Count = FileBytes[OffSet + 3] << 8 | FileBytes[OffSet + 2];
OffSet += 4;
for (int I = 0; I < Count; I++)
{
int ColIndex = FileBytes[OffSet + 1] << 8 | FileBytes[OffSet];
OffSet += 2;
if (X >= Size.Width) continue;
Pixels[(Y * Size.Width + X) * 4 + 3] = 255;
Pixels[(Y * Size.Width + X) * 4 + 2] = (byte)((ColIndex / 2048) * 8 + 7);
Pixels[(Y * Size.Width + X) * 4 + 1] = (byte)(((ColIndex %= 2048) / 32) * 4);
Pixels[(Y * Size.Width + X) * 4] = (byte)((ColIndex % 32) * 8 + 7);
X++;
}
break;
default:
return null;
}
}
return Pixels;
}