public override void Read(BinaryReader br, RenderWareSection p) { base.Read(br, p); DataString = BinaryReaderUtilities.ReadNullStartingString(br, Size); }
private void ReadGta3VCFormat(BinaryReader br) { FilterMode = (TextureFilterMode)br.ReadByte(); AddressMode = (TextureAdressMode)br.ReadByte(); Pad = br.ReadInt16(); DiffuseTextureName = BinaryReaderUtilities.ReadNullTerminatedString(br, 32); AlphaTextureName = BinaryReaderUtilities.ReadNullTerminatedString(br, 32); RasterFormat = (RasterFormat)br.ReadInt32(); UseAlpha = br.ReadInt32() == 1 ? true : false; TextureWidth = br.ReadInt16(); TextureHeight = br.ReadInt16(); BitDepth = br.ReadByte(); MipMapCount = br.ReadByte(); RasterType = (RasterFormat)br.ReadByte(); Compression = br.ReadByte() == 1 ? true : false; int paletteSize = BitDepth == 8 ? 256 : 0; //gotta fix this if (paletteSize != 0) { UsePalette = true; //would like to create the bit map in GetImage(); Palette = ReadPalette(br); PaletteBitmap = new Bitmap(TextureWidth, TextureHeight); for (int i = 0; i < TextureWidth; i++) { for (int j = 0; j < TextureHeight; j++) { var idx = br.ReadByte(); PaletteBitmap.SetPixel(i, j, Palette[idx]); } } PaletteBitmap.RotateFlip(RotateFlipType.Rotate90FlipNone); PaletteDataSize = br.ReadInt32(); } else { MipMaps = new List <Color[]>(); for (int i = 0; i < MipMapCount; i++) { var size = br.ReadInt32(); var data = br.ReadBytes(size); List <byte[]> dataclrs = new List <byte[]>(); for (int j = 4; j < data.Length; j++) { if (j % 4 == 0) { dataclrs.Add(new byte[] { data[j - 4], data[j - 3], data[j - 2], data[j - 1] }); } } //add last color dataclrs.Add(new byte[] { data[data.Length - 4], data[data.Length - 3], data[data.Length - 2], data[data.Length - 1] }); var palette = new Color[size / 4]; for (int j = 0; j < size / 4; j++) { var byteA = dataclrs[j]; //if (UseAlpha) { palette[j] = Color.FromArgb(byteA[3], byteA[0], byteA[1], byteA[2]); } //else { palette[j] = Color.FromArgb(255, byteA[0], byteA[1], byteA[2]); } palette[j] = Color.FromArgb(255, byteA[0], byteA[1], byteA[2]); } MipMaps.Add(palette); } } }
public void Read(BinaryReader br) { Offset = br.ReadUInt32(); Size = br.ReadUInt32(); Name = BinaryReaderUtilities.ReadNullTerminatedString(br, 24); }