图像格式有两个文件,WIX索引文件,WIL数据文件
1、WIX这里有一个条件判断,即第26字节开始取一个Word是否是0xB13A,这是个版本判断,如果不是则文件重定位到第24字节处,否则文件流读了这个Word后位置应该在第28字节处
然后就是依次取图像在数据文件中的位置索引,4个字节一取,DWORD类型,直到WIX文件结束。
2、WIL文件信息:根据WIX得到的索引列表在WIL中定位,然后依次取得相应的图像信息
short Width, Height, OffsetX, OffsetY;//图像宽高以及偏移
byte HasShadow;//为1表示有阴影
short ShadowX, ShadowY;//阴影偏移
int Size;//数据包含多少个Word,所以取到的数据要*2
//以上结构共17个字节
3、WIL文件图像:描述很难说清楚,还是用代码来说明吧,网上有现成的代码,原版的问题是图像缺行或无法退出,以下是关键过程的修改结果
private byte[][] DecompressWemadeMir3(BinaryReader BReader, short OutputWidth, short OutputHeight, int InputLength)
{
byte[][] Pixels = new byte[2][];
Pixels[0] = new byte[OutputWidth * OutputHeight * 2];
Pixels[1] = new byte[OutputWidth * OutputHeight * 2];
int n = BReader.ReadInt32();//读取4个字节,并判断是否为0,很关键,没这判断会导致有些图像缺行
if (n != 0) BReader.BaseStream.Seek(-4, SeekOrigin.Current);
byte[] FileBytes = BReader.ReadBytes(InputLength * 2);
int End = 0, OffSet = 0, Start = 0, Count;
int nX, x = 0;
for (int Y = OutputHeight - 1; Y >= 0; Y--)
{
OffSet = Start * 2;
End += FileBytes[OffSet+1] << 8 | FileBytes[OffSet];//读取一个Word(原版这里有问题)
Start++;
nX = Start;
OffSet = nX * 2;
while (nX < End)
{
switch (FileBytes[OffSet])
{
case 0xC0: //0xC0 No Colour
nX += 2;
x += FileBytes[OffSet + 3] << 8 | FileBytes[OffSet + 2];
OffSet += 4;
break;
case 0xC1: //Solid Colour
nX += 2;
Count = FileBytes[OffSet + 3] << 8 | FileBytes[OffSet + 2];
OffSet += 4;
for (int i = 0; i < Count; i++)
{
if (x > OutputWidth - 1) continue;
Pixels[0][(Y * OutputWidth + x) * 2] = FileBytes[OffSet];
Pixels[0][(Y * OutputWidth + x) * 2 + 1] = FileBytes[OffSet + 1];
OffSet += 2;
x++;
}
nX += Count;
break;
case 0xC2: //0xC2 Overlay Colour
case 0xC3:
HasMask = true;
nX += 2;
Count = FileBytes[OffSet + 3] << 8 | FileBytes[OffSet + 2];
OffSet += 4;
for (int i = 0; i < Count; i++)
{
if (x > OutputWidth - 1) continue;
for (int j = 0; j < 2; j++)
{
Pixels[j][(Y * OutputWidth + x) * 2] = FileBytes[OffSet];
Pixels[j][(Y * OutputWidth + x) * 2 + 1] = FileBytes[OffSet + 1];
}
OffSet += 2;
x++;
}
nX += Count;
break;
default:
//防止文件格式有误无法退出(正常情况下不会进到这个分支)
Y = -2;
nX = End;
break;
}
}
End++;
Start = End;
x = 0;
}
return Pixels;
}