/// <summary> /// Create a new PC Texture with the specified information; Cubemap and Mipmaps are determined based on bytes. /// </summary> public Texture(string name, byte format, byte flags1, int flags2, byte[] bytes) { Name = name; Format = format; Flags1 = flags1; Flags2 = flags2; Bytes = bytes; Header = null; DDS dds = new DDS(bytes); if (dds.dwCaps2.HasFlag(DDS.DDSCAPS2.CUBEMAP)) { Type = TexType.Cubemap; } else if (dds.dwCaps2.HasFlag(DDS.DDSCAPS2.VOLUME)) { Type = TexType.Volume; } else { Type = TexType.Texture; } Mipmaps = (byte)dds.dwMipMapCount; }
public ITexHeader ReadFrom(BinaryReader reader) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } var header = new TexHeader { Format = (TexFormat)reader.ReadInt32(), Flags = (TexFlags)reader.ReadInt32(), TextureWidth = reader.ReadInt32(), TextureHeight = reader.ReadInt32(), ImageWidth = reader.ReadInt32(), ImageHeight = reader.ReadInt32(), UnkInt0 = reader.ReadUInt32() }; if (!header.Format.IsValid()) { throw new EnumNotValidException <TexFormat>(header.Format); } return(header); }
internal Texture(BinaryReaderEx br, TPFPlatform platform, byte encoding) { int fileOffset = br.ReadInt32(); int fileSize = br.ReadInt32(); Format = br.ReadByte(); Cubemap = br.ReadBoolean(); Mipmaps = br.ReadByte(); Flags1 = br.AssertByte(0, 1, 2, 3); int nameOffset = 0; if (platform == TPFPlatform.PC) { Header = null; nameOffset = br.ReadInt32(); Flags2 = br.AssertInt32(0, 1); } else if (platform == TPFPlatform.PS3) { Header = new TexHeader(); Header.Width = br.ReadInt16(); Header.Height = br.ReadInt16(); Header.Unk1 = br.ReadInt32(); Header.Unk2 = br.AssertInt32(0, 0xAAE4); nameOffset = br.ReadInt32(); Flags2 = br.AssertInt32(0, 1); } else if (platform == TPFPlatform.PS4 || platform == TPFPlatform.Xbone) { Header = new TexHeader(); Header.Width = br.ReadInt16(); Header.Height = br.ReadInt16(); Header.TextureCount = br.AssertByte(1, 6); br.AssertByte(0); br.AssertByte(0); br.AssertByte(0); Header.Unk2 = br.AssertInt32(0xD); nameOffset = br.ReadInt32(); Flags2 = br.AssertInt32(0, 1); Header.DXGIFormat = br.ReadInt32(); } Bytes = br.GetBytes(fileOffset, fileSize); if (Flags1 == 2 || Flags1 == 3) { Bytes = DCX.Decompress(Bytes); } if (encoding == 1) { Name = br.GetUTF16(nameOffset); } else if (encoding == 0 || encoding == 2) { Name = br.GetShiftJIS(nameOffset); } }
public override void LoadFile() { Reader.BaseStream.Position = 0; Header = Reader.ReadStructure <TexHeader>(); // todo: this isn't correct and reads out the whole data portion as 1 image instead of accounting for lod levels // probably a breaking change to fix this ImageData = Convert(DataSpan.Slice(HeaderLength), Header.Width, Header.Height); }
/// <summary> /// Create a new PC Texture with the specified information; Cubemap and Mipmaps are determined based on bytes. /// </summary> public Texture(string name, byte format, byte flags1, int flags2, byte[] bytes) { Name = name; Format = format; Flags1 = flags1; Flags2 = flags2; Bytes = bytes; Header = null; DDS dds = new DDS(bytes); Cubemap = dds.dwCaps2.HasFlag(DDS.DDSCAPS2.CUBEMAP); Mipmaps = (byte)dds.dwMipMapCount; }
/// <summary> /// Create a new PC Texture with the specified information; Cubemap and Mipmaps are determined based on bytes. /// </summary> public Texture(string name, byte format, byte flags1, int flags2, byte[] bytes) { Name = name; Format = format; Flags1 = flags1; Flags2 = flags2; Bytes = bytes; Header = null; DDS dds = new DDS(bytes); // DDSCAPS2_CUBEMAP Cubemap = (dds.dwCaps2 & 0x200) != 0; Mipmaps = (byte)dds.dwMipMapCount; }
public TexHeader ReadFromStream(Stream stream) { using (var reader = new BinaryReader(stream, Encoding.UTF8, true)) { var header = new TexHeader { Format = (TexFormat)reader.ReadInt32(), Flags = (TexFlags)reader.ReadInt32(), TextureWidth = reader.ReadInt32(), TextureHeight = reader.ReadInt32(), ImageWidth = reader.ReadInt32(), ImageHeight = reader.ReadInt32(), UnkInt0 = reader.ReadUInt32() }; header.Format.AssertValid(); return(header); } }
internal Texture(BinaryReaderEx br, TPFPlatform platform, byte flag2, byte encoding) { uint fileOffset = br.ReadUInt32(); int fileSize = br.ReadInt32(); Format = br.ReadByte(); Type = br.ReadEnum8 <TexType>(); Mipmaps = br.ReadByte(); Flags1 = br.AssertByte(0, 1, 2, 3); if (platform != TPFPlatform.PC) { Header = new TexHeader(); Header.Width = br.ReadInt16(); Header.Height = br.ReadInt16(); if (platform == TPFPlatform.Xbox360) { br.AssertInt32(0); } else if (platform == TPFPlatform.PS3) { Header.Unk1 = br.ReadInt32(); if (flag2 != 0) { Header.Unk2 = br.AssertInt32(0, 0x69E0, 0xAAE4); } } else if (platform == TPFPlatform.PS4 || platform == TPFPlatform.Xbone) { Header.TextureCount = br.AssertInt32(1, 6); Header.Unk2 = br.AssertInt32(0xD); } } uint nameOffset = br.ReadUInt32(); bool hasFloatStruct = br.AssertInt32(0, 1) == 1; if (platform == TPFPlatform.PS4 || platform == TPFPlatform.Xbone) { Header.DXGIFormat = br.ReadInt32(); } if (hasFloatStruct) { FloatStruct = new FloatStruct(br); } Bytes = br.GetBytes(fileOffset, fileSize); if (Flags1 == 2 || Flags1 == 3) { Bytes = DCX.Decompress(Bytes, out DCX.Type type); if (type != DCX.Type.DCP_EDGE) { throw new NotImplementedException($"TPF compression is expected to be DCP_EDGE, but it was {type}"); } } if (encoding == 1) { Name = br.GetUTF16(nameOffset); } else if (encoding == 0 || encoding == 2) { Name = br.GetShiftJIS(nameOffset); } }
internal Texture(BinaryReaderEx br, TPFPlatform platform, byte flag2, byte encoding) { uint fileOffset = br.ReadUInt32(); int fileSize = br.ReadInt32(); Format = br.ReadByte(); Type = br.ReadEnum8 <TexType>(); Mipmaps = br.ReadByte(); Flags1 = br.AssertByte(0, 1, 2, 3); uint nameOffset = uint.MaxValue; if (platform == TPFPlatform.PC) { Header = null; nameOffset = br.ReadUInt32(); Flags2 = br.AssertInt32(0, 1); } else { Header = new TexHeader(); Header.Width = br.ReadInt16(); Header.Height = br.ReadInt16(); if (platform == TPFPlatform.Xbox360) { br.AssertInt32(0); nameOffset = br.ReadUInt32(); br.AssertInt32(0); } else if (platform == TPFPlatform.PS3) { Header.Unk1 = br.ReadInt32(); if (flag2 != 0) { Header.Unk2 = br.AssertInt32(0, 0xAAE4); } nameOffset = br.ReadUInt32(); Flags2 = br.AssertInt32(0, 1); if (Flags2 == 1) { Unk20 = br.ReadInt32(); Unk24 = br.ReadInt32(); Unk28 = br.ReadSingle(); } } else if (platform == TPFPlatform.PS4 || platform == TPFPlatform.Xbone) { Header.TextureCount = br.AssertInt32(1, 6); Header.Unk2 = br.AssertInt32(0xD); nameOffset = br.ReadUInt32(); Flags2 = br.AssertInt32(0, 1); Header.DXGIFormat = br.ReadInt32(); } } Bytes = br.GetBytes(fileOffset, fileSize); if (Flags1 == 2 || Flags1 == 3) { Bytes = DCX.Decompress(Bytes); } if (encoding == 1) { Name = br.GetUTF16(nameOffset); } else if (encoding == 0 || encoding == 2) { Name = br.GetShiftJIS(nameOffset); } }