private static TextureLoadInfo ParseHeader(ref BlpHeader header) { var ret = new TextureLoadInfo { Height = header.Height, Width = header.Width }; if (header.Compression == 2) { switch (header.AlphaCompression) { case 0: ret.Format = SharpDX.DXGI.Format.BC1_UNorm; ret.BlockSize = 8; break; case 1: ret.Format = SharpDX.DXGI.Format.BC2_UNorm; ret.BlockSize = 16; break; case 7: ret.Format = SharpDX.DXGI.Format.BC3_UNorm; ret.BlockSize = 16; break; } } else { ret.Format = SharpDX.DXGI.Format.R8G8B8A8_UNorm; } return(ret); }
private async void Load(string file) { mLoadInfo = await Task<TextureLoadInfo>.Factory.StartNew(() => TextureLoader.LoadFirstLayer(file)); if (mLoadInfo.Format != Format.R8G8B8A8_UNorm) DecompressData(); if (OnBeforeLoad != null) OnBeforeLoad(this, mLoadInfo.Layers[0]); InterfaceManager.Instance.Dispatcher.Invoke(OnSyncLoad); }
private static void ParseUncompressedLayer(int layer, ref uint[] palette, BinaryReader baseReader, ref BlpHeader header, TextureLoadInfo loadInfo) { if (header.Compression == 3) { return; } if (palette.Length == 0) { baseReader.BaseStream.Position = SizeCache <BlpHeader> .Size; palette = baseReader.ReadArray <uint>(256); } var w = Math.Max(header.Width >> layer, 1); var h = Math.Max(header.Height >> layer, 1); var indices = loadInfo.Layers[layer]; var colors = new byte[w * h * 4]; if (header.AlphaDepth == 8) { DecompPaletteFastPath(ref palette, ref indices, ref colors); } else { DecompPaletteA8R8G8B8(header.AlphaDepth, ref palette, ref indices, ref colors); } loadInfo.Layers[layer] = colors; }
private static unsafe void ParseLayer(int layer, ref uint[] palette, BinaryReader reader, BlpHeader header, TextureLoadInfo loadInfo) { if (header.Sizes[layer] == 0) { return; } var w = Math.Max(1, header.Width >> layer); reader.BaseStream.Position = header.Offsets[layer]; loadInfo.Layers.Add(reader.ReadBytes(header.Sizes[layer])); if (loadInfo.Format != SharpDX.DXGI.Format.R8G8B8A8_UNorm) { loadInfo.RowPitchs.Add(((w + 3) / 4) * loadInfo.BlockSize); } else { ParseUncompressedLayer(layer, ref palette, reader, ref header, loadInfo); loadInfo.RowPitchs.Add(w * 4); } }
private static TextureLoadInfo ParseHeader(ref BlpHeader header) { var ret = new TextureLoadInfo { Height = header.Height, Width = header.Width }; if (header.Compression == 2) { switch (header.AlphaCompression) { case 0: ret.Format = SharpDX.DXGI.Format.BC1_UNorm; ret.BlockSize = 8; break; case 1: ret.Format = SharpDX.DXGI.Format.BC2_UNorm; ret.BlockSize = 16; break; case 7: ret.Format = SharpDX.DXGI.Format.BC3_UNorm; ret.BlockSize = 16; break; } } else ret.Format = SharpDX.DXGI.Format.R8G8B8A8_UNorm; return ret; }
private static void ParseUncompressedLayer(int layer, ref uint[] palette, BinaryReader baseReader, ref BlpHeader header, TextureLoadInfo loadInfo) { if (header.Compression == 3) return; if (palette.Length == 0) { baseReader.BaseStream.Position = SizeCache<BlpHeader>.Size; palette = baseReader.ReadArray<uint>(256); } var w = Math.Max(header.Width >> layer, 1); var h = Math.Max(header.Height >> layer, 1); var indices = loadInfo.Layers[layer]; var colors = new byte[w * h * 4]; if (header.AlphaDepth == 8) DecompPaletteFastPath(ref palette, ref indices, ref colors); else DecompPaletteA8R8G8B8(header.AlphaDepth, ref palette, ref indices, ref colors); loadInfo.Layers[layer] = colors; }
private static unsafe void ParseLayer(int layer, ref uint[] palette, BinaryReader reader, BlpHeader header, TextureLoadInfo loadInfo) { if (header.Sizes[layer] == 0) return; var w = Math.Max(1, header.Width >> layer); reader.BaseStream.Position = header.Offsets[layer]; loadInfo.Layers.Add(reader.ReadBytes(header.Sizes[layer])); if (loadInfo.Format != SharpDX.DXGI.Format.R8G8B8A8_UNorm) loadInfo.RowPitchs.Add(((w + 3) / 4) * loadInfo.BlockSize); else { ParseUncompressedLayer(layer, ref palette, reader, ref header, loadInfo); loadInfo.RowPitchs.Add(w * 4); } }