Exemplo n.º 1
0
        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;
                }
            }
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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;
                }
            }
        }
Exemplo n.º 4
0
        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));
        }