public static TextureLoadInfo LoadToArgbImage(string file) { var loadInfo = LoadFirstLayer(file); if (loadInfo == null) { return(null); } if (loadInfo.Format == SharpDX.DXGI.Format.R8G8B8A8_UNorm) { return(loadInfo); } loadInfo.Layers[0] = DxtHelper.Decompress(loadInfo.Width, loadInfo.Height, loadInfo.Layers[0], loadInfo.Format); loadInfo.Format = SharpDX.DXGI.Format.R8G8B8A8_UNorm; return(loadInfo); }
public static unsafe TextureLoadInfo LoadToBestMatchingImage(Stream file, int targetWidth, int targetHeight) { if (file == null) { return(null); } var reader = new BinaryReader(file); var header = reader.Read <BlpHeader>(); var layer = 0; if (header.MipLevels != 0) { for (; layer < 16; ++layer) { var w = Math.Max(header.Width >> layer, 1); var h = Math.Max(header.Height >> layer, 1); var lw = Math.Max(header.Width >> (layer + 1), 1); var lh = Math.Max(header.Height >> (layer + 1), 1); if (w == h && lw == lh && lw == w && w == 1) { break; } if (w >= targetWidth && lw <= targetWidth && h >= targetHeight && lh <= targetHeight) { break; } } } if (layer != 0 && (header.Sizes[layer] == 0 || header.Offsets[layer] == 0)) { for (; layer > 0; --layer) { if (header.Sizes[layer] != 0 && header.Offsets[layer] != 0) { break; } } } file.Position = 0; var loadInfo = LoadLayer(file, layer); if (loadInfo == null) { return(null); } loadInfo.Width = Math.Max(loadInfo.Width >> layer, 1); loadInfo.Height = Math.Max(loadInfo.Height >> layer, 1); if (loadInfo.Format == SharpDX.DXGI.Format.R8G8B8A8_UNorm) { return(loadInfo); } loadInfo.Layers[0] = DxtHelper.Decompress(loadInfo.Width, loadInfo.Height, loadInfo.Layers[0], loadInfo.Format); loadInfo.Format = SharpDX.DXGI.Format.R8G8B8A8_UNorm; return(loadInfo); }
private void DecompressData() { mLoadInfo.Layers[0] = DxtHelper.Decompress(mLoadInfo.Width, mLoadInfo.Height, mLoadInfo.Layers[0], mLoadInfo.Format); mLoadInfo.Format = Format.R8G8B8A8_UNorm; }