private void ExportDDS(IExportContainer container, Stream destination, Stream source, long length) { DDSConvertParameters @params = new DDSConvertParameters() { DataLength = length, MipMapCount = MipCount, Width = Width, Height = Height, IsPitchOrLinearSize = DDSIsPitchOrLinearSize, PixelFormatFlags = DDSPixelFormatFlags, FourCC = (DDSFourCCType)DDSFourCC, RGBBitCount = DDSRGBBitCount, RBitMask = DDSRBitMask, GBitMask = DDSGBitMask, BBitMask = DDSBBitMask, ABitMask = DDSABitMask, Caps = DDSCaps(container.Version), }; if (IsSwapBytes(container.Platform)) { using (ReverseStream reverse = new ReverseStream(source, source.Position, length, true)) { DDSConverter.ExportDDS(destination, reverse, @params); } } else { DDSConverter.ExportDDS(destination, source, @params); } }
private void ExportDDS(IExportContainer container, Stream destination, Stream source, long length) { DDSConvertParameters @params = new DDSConvertParameters() { DataLength = length, MipMapCount = MipCount, Width = Width, Height = Height, IsPitchOrLinearSize = DDSIsPitchOrLinearSize, PixelFormatFlags = DDSPixelFormatFlags, FourCC = (DDSFourCCType)DDSFourCC, RGBBitCount = DDSRGBBitCount, RBitMask = DDSRBitMask, GBitMask = DDSGBitMask, BBitMask = DDSBBitMask, ABitMask = DDSABitMask, Caps = DDSCaps(container.Version), }; EndianType endianess = IsSwapBytes(container.Platform) ? EndianType.BigEndian : EndianType.LittleEndian; using (EndianReader sourceReader = new EndianReader(source, endianess)) { DDSConverter.ExportDDS(sourceReader, destination, @params); } }
public void CopyTo(DDSConvertParameters dest) { dest.DataLength = DataLength; dest.MipMapCount = MipMapCount; dest.Width = Width; dest.Height = Height; dest.IsPitchOrLinearSize = IsPitchOrLinearSize; dest.PixelFormatFlags = PixelFormatFlags; dest.FourCC = FourCC; dest.RGBBitCount = RGBBitCount; dest.RBitMask = RBitMask; dest.GBitMask = GBitMask; dest.BBitMask = BBitMask; dest.ABitMask = ABitMask; dest.Caps = Caps; }
private Bitmap DDSToBitmap(IExportContainer container, Texture2D texture, byte[] data) { DDSConvertParameters @params = new DDSConvertParameters() { DataLength = data.LongLength, MipMapCount = texture.MipCount, Width = texture.Width, Height = texture.Height, IsPitchOrLinearSize = texture.DDSIsPitchOrLinearSize, PixelFormatFlags = texture.DDSPixelFormatFlags, FourCC = (DDSFourCCType)texture.DDSFourCC, RGBBitCount = texture.DDSRGBBitCount, RBitMask = texture.DDSRBitMask, GBitMask = texture.DDSGBitMask, BBitMask = texture.DDSBBitMask, ABitMask = texture.DDSABitMask, Caps = texture.DDSCaps(container.Version), }; int width = @params.Width; int height = @params.Height; int size = width * height * 4; byte[] buffer = new byte[size]; using (MemoryStream destination = new MemoryStream(buffer)) { using (MemoryStream source = new MemoryStream(data)) { EndianType endianess = texture.IsSwapBytes(container.Platform) ? EndianType.BigEndian : EndianType.LittleEndian; using (EndianReader sourceReader = new EndianReader(source, endianess)) { DecompressDDS(sourceReader, destination, @params); } } Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); Rectangle rect = new Rectangle(0, 0, width, height); BitmapData bitData = bitmap.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); IntPtr pointer = bitData.Scan0; Marshal.Copy(buffer, 0, pointer, size); bitmap.UnlockBits(bitData); return(bitmap); } }
private void DecompressDDS(BinaryReader reader, Stream destination, DDSConvertParameters @params) { if (@params.PixelFormatFlags.IsFourCC()) { switch (@params.FourCC) { case DDSFourCCType.DXT1: DDSDecompressor.DecompressDXT1(reader, destination, @params); break; case DDSFourCCType.DXT3: DDSDecompressor.DecompressDXT3(reader, destination, @params); break; case DDSFourCCType.DXT5: DDSDecompressor.DecompressDXT5(reader, destination, @params); break; default: throw new NotImplementedException(@params.FourCC.ToString()); } } else { if (@params.PixelFormatFlags.IsLuminace()) { throw new NotSupportedException("Luminace isn't supported"); } else { if (@params.PixelFormatFlags.IsAlphaPixels()) { DDSDecompressor.DecompressRGBA(reader, destination, @params); } else { DDSDecompressor.DecompressRGB(reader, destination, @params); } } } }
private byte[] ExportDDS(byte[] data, int offset, int length) { PrepareForDDSExport(ref data, ref offset, ref length); DDSConvertParameters @params = new DDSConvertParameters() { DataLength = length, MipMapCount = MipCount, Width = Width, Height = Height, IsPitchOrLinearSize = DDSIsPitchOrLinearSize, PixelFormatFlags = DDSPixelFormatFlags, FourCC = DDSFourCC, RGBBitCount = DDSRGBBitCount, RBitMask = DDSRBitMask, GBitMask = DDSGBitMask, BBitMask = DDSBBitMask, ABitMask = DDSABitMask, Caps = DDSCaps, }; return(DDSConverter.WrapToDDS(data, offset, @params)); }