/// <summary> /// 获取某个索引的图片 /// </summary> /// <param name="index">图片索引,从0开始</param> /// <returns>对应图片数据</returns> internal U3d.Texture2D this[uint index] { get { M2ImageInfo ii = ImageInfos[index]; U3d.Texture2D result = new U3d.Texture2D(ii.Width, ii.Height); if (ii.Width == 0 && ii.Height == 0) { return(result); } byte[] pixels = null; lock (wzl_locker) { FS_wzl.Position = OffsetList[index] + 16; using (BinaryReader rwzl = new BinaryReader(FS_wzl)) { pixels = unzip(rwzl.ReadBytes(LengthList[index])); } } int p_index = 0; for (int h = 0; h < ii.Height; ++h) { for (int w = 0; w < ii.Width; ++w) { // 跳过填充字节 if (w == 0) { p_index += Delphi.SkipBytes(8, ii.Width); } float[] pallete = Delphi.PALLETE[pixels[p_index++] & 0xff]; result.SetPixel(w, ii.Height - h, new U3d.Color(pallete[1], pallete[2], pallete[3], pallete[0])); } } result.Apply(); return(result); } }
/// <summary> /// 获取某个索引的图片 /// </summary> /// <param name="index">图片索引,从0开始</param> /// <returns>对应图片数据</returns> internal U3d.Texture2D this[uint index] { get { M2ImageInfo ii = ImageInfos[index]; U3d.Texture2D result = new U3d.Texture2D(ii.Width, ii.Height); byte[] pixels = null; lock (wil_locker) { FS_wil.Position = OffsetList[index] + 8; int pixelLength = OffsetList[index + 1] - OffsetList[index]; if (pixelLength < 13) { return(result); } pixels = BR_wil.ReadBytes(pixelLength); } if (ColorCount == 8) { int p_index = 0; for (int h = ii.Height - 1; h >= 0; --h) { for (int w = 0; w < ii.Width; ++w) { // 跳过填充字节 if (w == 0) { p_index += Delphi.SkipBytes(8, ii.Width); } float[] pallete = Delphi.PALLETE[pixels[p_index++] & 0xff]; result.SetPixel(w, ii.Height - h, new U3d.Color(pallete[1], pallete[2], pallete[3], pallete[0])); } } } else if (ColorCount == 16) { using (MemoryStream mspixels = new MemoryStream(pixels)) { using (BinaryReader rpixels = new BinaryReader(mspixels)) { int p_index = 0; for (int h = ii.Height - 1; h >= 0; --h) { for (int w = 0; w < ii.Width; ++w, p_index += 2) { // 跳过填充字节 if (w == 0) { p_index += Delphi.SkipBytes(16, ii.Width); } short pdata = rpixels.ReadInt16(); float br = (((pdata & 0xF800) >> 8) / 255f); //byte br = (byte) ((data & 0b1111_1000_0000_0000) >> 8);// 由于是与16位做与操作,所以多出了后面8位 float bg = (((pdata & 0x7E0) >> 3) / 255f); //byte bg = (byte) ((data & 0b0000_0111_1110_0000) >> 3);// 多出了3位,在强转时前8位会自动丢失 float bb = (((pdata & 0x1F) << 3) / 255f); //byte bb = (byte) ((data & 0b0000_0000_0001_1111) << 3);// 少了3位 result.SetPixel(w, ii.Height - h, new U3d.Color(br, bg, bb)); } } } } } result.Apply(); return(result); } }