/// <summary> /// The read h 2 bitmap raw. /// </summary> /// <param name="TagIndex">The TagIndex.</param> /// <param name="map">The map.</param> /// <param name="dontreadraw">The dontreadraw.</param> /// <remarks></remarks> public void ReadH2BitmapRaw(int TagIndex, Map map, bool dontreadraw) { // Offset 68 = Bitmap Data reflexive map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 68; int tempc = map.BR.ReadInt32(); int tempr = map.BR.ReadInt32() - map.SecondaryMagic; for (int x = 0; x < tempc; x++) { // Bitmap Data reflexive is 116 bytes large // Offset 4 in BD reflexive is (short) width map.BR.BaseStream.Position = tempr + (x * 116) + 4; int width = map.BR.ReadInt16(); // Offset 6 in BD reflexive is (short) width int height = map.BR.ReadInt16(); // Offset 8 in BD reflexive is (short) width int depth = map.BR.ReadInt16(); // Offset 10 in BD reflexive is (short) type int type = map.BR.ReadInt16(); // Offset 12 in BD reflexive is (short) format int format = map.BR.ReadInt16(); // Offset 20 in BD reflexive is (short) mipmap Count map.BR.BaseStream.Position = tempr + (x * 116) + 20; int mipmapCount = map.BR.ReadInt16(); for (int xx = 0; xx < 6; xx++) { BitmapRawDataChunk Raw = new BitmapRawDataChunk(); Raw.inchunk = x; Raw.num = xx; Raw.pointerMetaOffset = tempr + (x * 116) + 28 + (xx * 4) - map.MetaInfo.Offset[TagIndex]; Raw.rawDataType = RawDataType.bitm; map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + Raw.pointerMetaOffset; Raw.offset = map.BR.ReadInt32(); if (Raw.offset == -1) { break; } map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + Raw.pointerMetaOffset + 24; Raw.size = map.BR.ReadInt32(); map.Functions.ParsePointer(ref Raw.offset, ref Raw.rawLocation); if (dontreadraw == false) { map.OpenMap(Raw.rawLocation); map.BR.BaseStream.Position = Raw.offset; Raw.MS = new MemoryStream(Raw.size); Raw.MS.Write(map.BR.ReadBytes(Raw.size), 0, Raw.size); #region mipmap loading section int offset = 0; int Bpp = 4; // 32 bit switch (format) { case 0: case 1: case 2: case 17: Bpp = 1; // 8 bit break; case 3: case 6: case 8: case 9: case 22: Bpp = 2; // 16 bit break; } for (int xxx = xx; xxx < mipmapCount; xxx++) { mipmapDataChunk mipmapDC = new mipmapDataChunk(); mipmapDC.width = width >> xxx; mipmapDC.height = height >> xxx; mipmapDC.depth = depth >> xxx != 0 ? depth >> xxx : 1; mipmapDC.offset = offset; mipmapDC.size = mipmapDC.width * mipmapDC.height * mipmapDC.depth * Bpp; // if (type == 2) // Cubemap, 6 sides // mipmapDC.size *= 6; switch (format) { case 14: // DXT1 mipmapDC.size /= 8; break; case 15: // DXT3 case 16: // DXT5 mipmapDC.size /= 4; break; } offset += mipmapDC.size; Raw.mipmaps.Add(mipmapDC); } #endregion map.OpenMap(MapTypes.Internal); } this.rawChunks.Add(Raw); } } }
/// <summary> /// The read ce bitmap raw. /// </summary> /// <param name="TagIndex">The TagIndex.</param> /// <param name="map">The map.</param> /// <param name="dontreadraw">The dontreadraw.</param> /// <remarks></remarks> public void ReadCEBitmapRaw(int TagIndex, Map map, bool dontreadraw) { if (map.MetaInfo.external[TagIndex]) { map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 84; int rawcount = map.BR.ReadInt32(); map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 100; int translation = map.BR.ReadInt32(); for (int x = 0; x < rawcount; x++) { BitmapRawDataChunk Raw = new BitmapRawDataChunk(); Raw.inchunk = x; Raw.num = 0; Raw.rawDataType = RawDataType.bitm; Raw.pointerMetaOffset = (x * 48) + translation + 24; map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + Raw.pointerMetaOffset; Raw.offset = map.BR.ReadInt32(); Raw.size = map.BR.ReadInt32(); Raw.rawLocation = MapTypes.Bitmaps; try { if (dontreadraw == false) { // map.OpenMap(Raw.rawLocation); map.BR.BaseStream.Position = Raw.offset; Raw.MS = new MemoryStream(Raw.size); Raw.MS.Write(map.BR.ReadBytes(Raw.size), 0, Raw.size); // map.OpenMap(MapTypes.Internal); } this.rawChunks.Add(Raw); } catch { } } // m.CloseMap(); } else { map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 96; int tempc = map.BR.ReadInt32(); int tempr = map.BR.ReadInt32() - map.PrimaryMagic - map.MetaInfo.Offset[TagIndex]; for (int x = 0; x < tempc; x++) { BitmapRawDataChunk Raw = new BitmapRawDataChunk(); Raw.inchunk = x; Raw.num = 0; Raw.pointerMetaOffset = tempr + (x * 48) + 24; map.BR.BaseStream.Position = Raw.pointerMetaOffset + map.MetaInfo.Offset[TagIndex]; Raw.rawDataType = RawDataType.bitm; Raw.offset = map.BR.ReadInt32(); Raw.size = map.BR.ReadInt32(); Raw.rawLocation = MapTypes.Internal; if (dontreadraw == false) { // map.OpenMap(Raw.rawLocation); map.BR.BaseStream.Position = Raw.offset; Raw.MS = new MemoryStream(Raw.size); Raw.MS.Write(map.BR.ReadBytes(Raw.size), 0, Raw.size); // map.OpenMap(MapTypes.Internal); } this.rawChunks.Add(Raw); } } }