private static unsafe void LoadDdsFile(Stream stream, ref DDSLoadInfo info) { byte[] buffer = new byte[stream.Length]; stream.ProperRead(buffer, 0, buffer.Length); int hr; fixed(byte *pBytes = buffer) { if (IntPtr.Size == 8) { hr = DdsIO_x64.Load(pBytes, new UIntPtr((ulong)buffer.Length), ref info); } else { hr = DdsIO_x86.Load(pBytes, new UIntPtr((ulong)buffer.Length), ref info); } } if (FAILED(hr)) { switch (hr) { case HResult.InvalidData: throw new FormatException("The DDS file is invalid."); case HResult.NotSupported: throw new FormatException("The file is not a supported DDS format."); default: Marshal.ThrowExceptionForHR(hr); break; } } }
public static unsafe void Save( DDSSaveInfo info, TextureCollection textures, Stream output, DdsProgressCallback progressCallback) { StreamIOCallbacks streamIO = new StreamIOCallbacks(output); IOCallbacks callbacks = new IOCallbacks { Read = streamIO.Read, Write = streamIO.Write, Seek = streamIO.Seek, GetSize = streamIO.GetSize }; DDSBitmapData[] bitmapData = CreateBitmapDataArray(textures, info.arraySize, info.mipLevels); int hr; unsafe { fixed(DDSBitmapData *pBitmapData = bitmapData) { if (IntPtr.Size == 8) { hr = DdsIO_x64.Save(info, pBitmapData, (uint)bitmapData.Length, callbacks, progressCallback); } else { hr = DdsIO_x86.Save(info, pBitmapData, (uint)bitmapData.Length, callbacks, progressCallback); } } } GC.KeepAlive(streamIO); GC.KeepAlive(callbacks); GC.KeepAlive(progressCallback); if (FAILED(hr)) { if (streamIO.CallbackExceptionInfo != null) { streamIO.CallbackExceptionInfo.Throw(); } else { switch (hr) { case HResult.CanceledError: throw new OperationCanceledException(); default: Marshal.ThrowExceptionForHR(hr); break; } } } }
private static void SaveDdsFile( Surface surface, DdsFileFormat format, DdsErrorMetric errorMetric, BC7CompressionMode compressionMode, bool cubeMap, bool generateMipmaps, MipMapSampling mipMapSampling, Stream output, DdsProgressCallback progressCallback) { DDSSaveInfo info = new DDSSaveInfo { scan0 = surface.Scan0.Pointer, width = surface.Width, height = surface.Height, stride = surface.Stride, format = format, errorMetric = errorMetric, compressionMode = compressionMode, cubeMap = cubeMap && IsCrossedCubeMapSize(surface), generateMipmaps = generateMipmaps, mipmapSampling = mipMapSampling }; StreamIOCallbacks streamIO = new StreamIOCallbacks(output); IOCallbacks callbacks = new IOCallbacks { Read = streamIO.Read, Write = streamIO.Write, Seek = streamIO.Seek, GetSize = streamIO.GetSize }; int hr; if (IntPtr.Size == 8) { hr = DdsIO_x64.Save(ref info, callbacks, progressCallback); } else { hr = DdsIO_x86.Save(ref info, callbacks, progressCallback); } GC.KeepAlive(streamIO); GC.KeepAlive(callbacks); GC.KeepAlive(progressCallback); if (FAILED(hr)) { Marshal.ThrowExceptionForHR(hr); } }
private static void FreeLoadInfo(ref DDSLoadInfo info) { if (IntPtr.Size == 8) { DdsIO_x64.FreeLoadInfo(ref info); } else { DdsIO_x86.FreeLoadInfo(ref info); } }
public static unsafe DdsImage Load(Stream stream) { StreamIOCallbacks streamIO = new StreamIOCallbacks(stream); IOCallbacks callbacks = new IOCallbacks { Read = streamIO.Read, Write = streamIO.Write, Seek = streamIO.Seek, GetSize = streamIO.GetSize }; int hr; DDSLoadInfo info = new DDSLoadInfo(); if (IntPtr.Size == 8) { hr = DdsIO_x64.Load(callbacks, ref info); } else { hr = DdsIO_x86.Load(callbacks, ref info); } GC.KeepAlive(streamIO); GC.KeepAlive(callbacks); if (FAILED(hr)) { if (streamIO.CallbackExceptionInfo != null) { streamIO.CallbackExceptionInfo.Throw(); } else { switch (hr) { case HResult.InvalidData: throw new FormatException("The DDS file is invalid."); case HResult.NotSupported: throw new FormatException("The file is not a supported DDS format."); default: Marshal.ThrowExceptionForHR(hr); break; } } } return(DdsImageFactory(info)); }
public void Dispose() { if (!this.disposed) { this.disposed = true; if (IntPtr.Size == 8) { DdsIO_x64.FreeLoadInfo(ref this.info); } else { DdsIO_x86.FreeLoadInfo(ref this.info); } } }
private static void LoadDdsFile(Stream stream, ref DDSLoadInfo info) { StreamIOCallbacks streamIO = new StreamIOCallbacks(stream); IOCallbacks callbacks = new IOCallbacks { Read = streamIO.Read, Write = streamIO.Write, Seek = streamIO.Seek, GetSize = streamIO.GetSize }; int hr; if (IntPtr.Size == 8) { hr = DdsIO_x64.Load(callbacks, ref info); } else { hr = DdsIO_x86.Load(callbacks, ref info); } GC.KeepAlive(streamIO); GC.KeepAlive(callbacks); if (FAILED(hr)) { switch (hr) { case HResult.InvalidData: throw new FormatException("The DDS file is invalid."); case HResult.NotSupported: throw new FormatException("The file is not a supported DDS format."); default: Marshal.ThrowExceptionForHR(hr); break; } } }
private static unsafe void SaveDdsFile( Surface surface, DdsFileFormat format, DdsErrorMetric errorMetric, BC7CompressionMode compressionMode, bool generateMipmaps, MipMapSampling mipMapSampling, DdsWriteImageCallback writeImageCallback, DdsProgressCallback progressCallback) { DDSSaveInfo info = new DDSSaveInfo { width = surface.Width, height = surface.Height, stride = surface.Stride, format = format, errorMetric = errorMetric, compressionMode = compressionMode, generateMipmaps = generateMipmaps, mipmapSampling = mipMapSampling, scan0 = surface.Scan0.Pointer }; int hr; if (IntPtr.Size == 8) { hr = DdsIO_x64.Save(ref info, writeImageCallback, progressCallback); } else { hr = DdsIO_x86.Save(ref info, writeImageCallback, progressCallback); } if (FAILED(hr)) { Marshal.ThrowExceptionForHR(hr); } }
public static unsafe void Save( DDSSaveInfo info, TextureCollection textures, Stream output, DdsProgressCallback progressCallback) { StreamIOCallbacks streamIO = new StreamIOCallbacks(output); IOCallbacks callbacks = new IOCallbacks { Read = streamIO.Read, Write = streamIO.Write, Seek = streamIO.Seek, GetSize = streamIO.GetSize }; DDSBitmapData[] bitmapData = CreateBitmapDataArray(textures, info.arraySize, info.mipLevels); int hr; unsafe { fixed(DDSBitmapData *pBitmapData = bitmapData) { #if NET47 if (IntPtr.Size == 8) #else if (RuntimeInformation.ProcessArchitecture == Architecture.X64) #endif { hr = DdsIO_x64.Save(info, pBitmapData, (uint)bitmapData.Length, callbacks, progressCallback); } #if NET47 else if (IntPtr.Size == 4) #else else if (RuntimeInformation.ProcessArchitecture == Architecture.X86) #endif { hr = DdsIO_x86.Save(info, pBitmapData, (uint)bitmapData.Length, callbacks, progressCallback); } else { throw new PlatformNotSupportedException(); } } } GC.KeepAlive(streamIO); GC.KeepAlive(callbacks); GC.KeepAlive(progressCallback); if (FAILED(hr)) { if (streamIO.CallbackExceptionInfo != null) { streamIO.CallbackExceptionInfo.Throw(); } else { switch (hr) { case HResult.CanceledError: throw new OperationCanceledException(); case HResult.UnknownDdsSaveFormat: throw new InvalidOperationException("The DDSFileFormat value does not map to a DXGI format."); default: Marshal.ThrowExceptionForHR(hr); break; } } } }
public static unsafe DdsImage Load(Stream stream) { StreamIOCallbacks streamIO = new StreamIOCallbacks(stream); IOCallbacks callbacks = new IOCallbacks { Read = streamIO.Read, Write = streamIO.Write, Seek = streamIO.Seek, GetSize = streamIO.GetSize }; int hr; DDSLoadInfo info = new DDSLoadInfo(); #if NET47 if (IntPtr.Size == 8) #else if (RuntimeInformation.ProcessArchitecture == Architecture.X64) #endif { hr = DdsIO_x64.Load(callbacks, ref info); } #if NET47 else if (IntPtr.Size == 4) #else else if (RuntimeInformation.ProcessArchitecture == Architecture.X86) #endif { hr = DdsIO_x86.Load(callbacks, ref info); } else { throw new PlatformNotSupportedException(); } GC.KeepAlive(streamIO); GC.KeepAlive(callbacks); if (FAILED(hr)) { if (streamIO.CallbackExceptionInfo != null) { streamIO.CallbackExceptionInfo.Throw(); } else { switch (hr) { case HResult.InvalidData: throw new FormatException("The DDS file is invalid."); case HResult.NotSupported: throw new FormatException("The file is not a supported DDS format."); default: Marshal.ThrowExceptionForHR(hr); break; } } } return(new DdsImage(info)); }