示例#1
0
        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;
                    }
                }
            }
        }
示例#2
0
        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);
            }
        }
示例#3
0
        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;
                    }
                }
            }
        }