public static DirectXTexBlob New()
        {
            try
            {
                DirectXTexBlob blob;
                var            hresult = DirectXTexDLL.DirectXTex_BlobNew(out blob);
                DirectXTexDLL.ThrowIfFailed(hresult);
                return(blob);
            }
            catch (EntryPointNotFoundException ex)
            {
                DirectXTexDLL.HandleEntryPointNotFound(ex);
            }

            return(new DirectXTexBlob());
        }
        public static DirectXTexScratchImage New()
        {
            try
            {
                DirectXTexScratchImage image;
                var hresult = DirectXTexDLL.DirectXTex_ScratchImageNew(out image);
                DirectXTexDLL.ThrowIfFailed(hresult);
                return(image);
            }
            catch (EntryPointNotFoundException ex)
            {
                DirectXTexDLL.HandleEntryPointNotFound(ex);
            }

            return(new DirectXTexScratchImage());
        }
Beispiel #3
0
        public static TexMetadata GetMetadataFromFile(string file
                                                      , DirectXTexFileType fileType = DirectXTexFileType.Unknown
                                                      , uint flags = 0)
        {
            Contract.Requires(!string.IsNullOrEmpty(file));

            if (!File.Exists(file))
            {
                throw new FileNotFoundException(file);
            }

            if (fileType == DirectXTexFileType.Unknown)
            {
                fileType = FileTypeFromFileExtension(file);
            }
            if (fileType == DirectXTexFileType.Unknown)
            {
                throw new NotSupportedException(file);
            }

            var result = TexMetadata.Empty;

            if (DirectXTexDLL.EntryPointsNotFound)
            {
                return(result);
            }

            try
            {
                var hresult = DirectXTexDLL.DirectXTex_GetMetadataFromFile(
                    fileType, out result, file, flags);
                DirectXTexDLL.ThrowIfFailed(hresult);
            }
            catch (EntryPointNotFoundException ex)
            {
                DirectXTexDLL.HandleEntryPointNotFound(ex);
            }

            return(result);
        }
Beispiel #4
0
        public static TexMetadata GetMetadataFromMemory(
            byte[] buffer, int startIndex, int length
            , DirectXTexFileType fileType
            , uint flags = 0)
        {
            Contract.Requires <ArgumentNullException>(buffer != null);
            Contract.Requires <ArgumentOutOfRangeException>(startIndex >= 0);
            Contract.Requires <ArgumentOutOfRangeException>(length >= 0);
            Contract.Requires <ArgumentOutOfRangeException>((startIndex + length) <= buffer.Length);

            var result = TexMetadata.Empty;

            if (DirectXTexDLL.EntryPointsNotFound)
            {
                return(result);
            }

            var bufferHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);

            try
            {
                var buf = bufferHandle.AddrOfPinnedObject();
                buf += startIndex;

                var hresult = DirectXTexDLL.DirectXTex_GetMetadataFromMemory(
                    fileType, out result, buf, (uint)length, flags);
                DirectXTexDLL.ThrowIfFailed(hresult);
            }
            catch (EntryPointNotFoundException ex)
            {
                DirectXTexDLL.HandleEntryPointNotFound(ex);
            }
            finally
            {
                bufferHandle.Free();
            }

            return(result);
        }