public static FtexFile ReadFtexFile(Stream inputStream) { FtexFile result = new FtexFile(); result.Read(inputStream); return(result); }
public static FtexFile ConvertToFtex(DdsFile file, FtexTextureType textureType) { FtexFile result = new FtexFile(); if (file.Header.PixelFormat.Equals(DdsPixelFormat.DdsPfA8R8G8B8())) result.PixelFormatType = 0; else if (file.Header.PixelFormat.Equals(DdsPixelFormat.DdsLuminance())) result.PixelFormatType = 1; else if (file.Header.PixelFormat.Equals(DdsPixelFormat.DdsPfDxt1())) result.PixelFormatType = 2; else if (file.Header.PixelFormat.Equals(DdsPixelFormat.DdsPfDxt3())) result.PixelFormatType = 3; // HACK: This is just a guess. The value isn't used in the Ground Zeroes files. else if (file.Header.PixelFormat.Equals(DdsPixelFormat.DdsPfDxt5())) result.PixelFormatType = 4; else throw new NotImplementedException(String.Format("Unknown PixelFormatType {0}", file.Header.PixelFormat)); result.Height = Convert.ToInt16(file.Header.Height); result.Width = Convert.ToInt16(file.Header.Width); result.Depth = Convert.ToInt16(file.Header.Depth); var mipMapData = GetMipMapData(file); var mipMaps = GetMipMapInfos(mipMapData); var ftexsFiles = GetFtexsFiles(mipMaps, mipMapData); result.MipMapCount = Convert.ToByte(mipMaps.Count()); result.NrtFlag = 2; result.AddMipMapInfos(mipMaps); result.AddFtexsFiles(ftexsFiles); result.FtexsFileCount = Convert.ToByte(ftexsFiles.Count()); result.AdditionalFtexsFileCount = Convert.ToByte(ftexsFiles.Count() - 1); result.TextureType = textureType; // TODO: Handle the DDS depth flag. return result; }
public static DdsFile ConvertToDds(FtexFile file, bool deswizzle) { DdsFile result = new DdsFile { Header = new DdsFileHeader { Size = DdsFileHeader.DefaultHeaderSize, Flags = DdsFileHeaderFlags.Texture | DdsFileHeaderFlags.MipMap, Height = file.Height, Width = file.Width, Depth = file.Depth, MipMapCount = file.MipMapCount, Caps = DdsSurfaceFlags.Texture | DdsSurfaceFlags.MipMap } }; result.Data = file.Data; switch (file.PixelFormatType) { case 0: result.Header.PixelFormat = DdsPixelFormat.DdsPfA8R8G8B8(); result.Header.Flags = result.Header.Flags | DdsFileHeaderFlags.Volume; if (deswizzle) result.Data = ByteSwap16(Deswizzle(result.Data, result.Header.Width, result.Header.Height, result.Header.MipMapCount, "RGBA8")); break; case 1: result.Header.PixelFormat = DdsPixelFormat.DdsLuminance(); break; case 2: result.Header.PixelFormat = DdsPixelFormat.DdsPfDxt1(); if (deswizzle) result.Data = ByteSwap16(Deswizzle(result.Data, result.Header.Width, result.Header.Height, result.Header.MipMapCount, "DXT1")); break; case 3: result.Header.PixelFormat = DdsPixelFormat.DdsPfDxt3(); // HACK: This is just a guess. The value isn't used in the Ground Zeroes files. if (deswizzle) result.Data = ByteSwap16(Deswizzle(result.Data, result.Header.Width, result.Header.Height, result.Header.MipMapCount, "DXT3")); break; case 4: result.Header.PixelFormat = DdsPixelFormat.DdsPfDxt5(); if (deswizzle) result.Data = ByteSwap16(Deswizzle(result.Data, result.Header.Width, result.Header.Height, result.Header.MipMapCount, "DXT5")); break; default: throw new NotImplementedException(String.Format("Unknown PixelFormatType {0}", file.PixelFormatType)); } return result; }
public static FtexFile ReadFtexFile(Stream inputStream) { FtexFile result = new FtexFile(); result.Read(inputStream); return result; }