From 6e7801e324366dc22c9f21976177cce2ec2c9157 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Thu, 24 Oct 2024 11:44:33 -0700 Subject: [PATCH] Use fixed width integers for underlying enum types (#538) --- Auxiliary/DirectXTexXbox.h | 13 +++--- Auxiliary/DirectXTexXboxDDS.cpp | 14 +++--- DDSTextureLoader/DDSTextureLoader11.h | 2 +- DDSTextureLoader/DDSTextureLoader12.h | 2 +- DirectXTex/DirectXTex.h | 65 ++++++++++++++------------- DirectXTex/DirectXTex.inl | 38 ++++++++-------- DirectXTex/DirectXTexDDS.cpp | 14 +++--- DirectXTex/DirectXTexHDR.cpp | 18 ++++---- DirectXTex/DirectXTexMipmaps.cpp | 8 ++-- DirectXTex/DirectXTexResize.cpp | 2 +- DirectXTex/DirectXTexTGA.cpp | 14 +++--- DirectXTex/DirectXTexUtil.cpp | 4 +- DirectXTex/DirectXTexWIC.cpp | 18 ++++---- WICTextureLoader/WICTextureLoader11.h | 2 +- WICTextureLoader/WICTextureLoader12.h | 2 +- WICTextureLoader/WICTextureLoader9.h | 2 +- 16 files changed, 112 insertions(+), 106 deletions(-) diff --git a/Auxiliary/DirectXTexXbox.h b/Auxiliary/DirectXTexXbox.h index 4aa5f74..0829c8f 100644 --- a/Auxiliary/DirectXTexXbox.h +++ b/Auxiliary/DirectXTexXbox.h @@ -41,6 +41,9 @@ #include #endif +#include +#include + #define DIRECTX_TEX_XBOX_VERSION 150 namespace Xbox @@ -95,13 +98,13 @@ namespace Xbox // Image I/O HRESULT __cdecl GetMetadataFromDDSMemory( - _In_reads_bytes_(size) const void* pSource, _In_ size_t size, + _In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size, _Out_ DirectX::TexMetadata& metadata, _Out_ bool& isXbox); HRESULT __cdecl GetMetadataFromDDSFile( _In_z_ const wchar_t* szFile, _Out_ DirectX::TexMetadata& metadata, _Out_ bool& isXbox); HRESULT __cdecl GetMetadataFromDDSMemoryEx( - _In_reads_bytes_(size) const void* pSource, _In_ size_t size, + _In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size, _Out_ DirectX::TexMetadata& metadata, _Out_ bool& isXbox, _Out_opt_ DirectX::DDSMetaData* ddPixelFormat); HRESULT __cdecl GetMetadataFromDDSFileEx( @@ -109,14 +112,14 @@ namespace Xbox _Out_opt_ DirectX::DDSMetaData* ddPixelFormat); HRESULT __cdecl LoadFromDDSMemory( - _In_reads_bytes_(size) const void* pSource, _In_ size_t size, + _In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size, _Out_opt_ DirectX::TexMetadata* metadata, _Out_ XboxImage& image); HRESULT __cdecl LoadFromDDSFile( _In_z_ const wchar_t* szFile, _Out_opt_ DirectX::TexMetadata* metadata, _Out_ XboxImage& image); HRESULT __cdecl LoadFromDDSMemoryEx( - _In_reads_bytes_(size) const void* pSource, _In_ size_t size, + _In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size, _Out_opt_ DirectX::TexMetadata* metadata, _Out_opt_ DirectX::DDSMetaData* ddPixelFormat, _Out_ XboxImage& image); @@ -173,6 +176,6 @@ namespace Xbox // DDS helper functions HRESULT __cdecl EncodeDDSHeader( const XboxImage& xbox, - _Out_writes_bytes_(maxsize) void* pDestination, _In_ size_t maxsize) noexcept; + _Out_writes_bytes_(maxsize) uint8_t* pDestination, _In_ size_t maxsize) noexcept; } // namespace diff --git a/Auxiliary/DirectXTexXboxDDS.cpp b/Auxiliary/DirectXTexXboxDDS.cpp index 8158f08..0749519 100644 --- a/Auxiliary/DirectXTexXboxDDS.cpp +++ b/Auxiliary/DirectXTexXboxDDS.cpp @@ -27,7 +27,7 @@ namespace // Decodes DDS header using XBOX extended header (variant of DX10 header) //------------------------------------------------------------------------------------- HRESULT DecodeDDSHeader( - _In_reads_bytes_(size) const void* pSource, + _In_reads_bytes_(size) const uint8_t* pSource, size_t size, DirectX::TexMetadata& metadata, _Out_opt_ DDSMetaData* ddPixelFormat, @@ -229,7 +229,7 @@ namespace _Use_decl_annotations_ HRESULT Xbox::EncodeDDSHeader( const XboxImage& xbox, - void* pDestination, + uint8_t* pDestination, size_t maxsize) noexcept { if (!pDestination) @@ -383,7 +383,7 @@ HRESULT Xbox::EncodeDDSHeader( _Use_decl_annotations_ HRESULT Xbox::GetMetadataFromDDSMemory( - const void* pSource, + const uint8_t* pSource, size_t size, TexMetadata& metadata, bool& isXbox) @@ -393,7 +393,7 @@ HRESULT Xbox::GetMetadataFromDDSMemory( _Use_decl_annotations_ HRESULT Xbox::GetMetadataFromDDSMemoryEx( - const void* pSource, + const uint8_t* pSource, size_t size, TexMetadata& metadata, bool& isXbox, @@ -498,7 +498,7 @@ HRESULT Xbox::GetMetadataFromDDSFileEx( //------------------------------------------------------------------------------------- _Use_decl_annotations_ HRESULT Xbox::LoadFromDDSMemory( - const void* pSource, + const uint8_t* pSource, size_t size, TexMetadata* metadata, XboxImage& xbox) @@ -508,7 +508,7 @@ HRESULT Xbox::LoadFromDDSMemory( _Use_decl_annotations_ HRESULT Xbox::LoadFromDDSMemoryEx( - const void* pSource, + const uint8_t* pSource, size_t size, TexMetadata* metadata, DDSMetaData* ddPixelFormat, @@ -694,7 +694,7 @@ HRESULT Xbox::SaveToDDSMemory(const XboxImage& xbox, Blob& blob) return hr; // Copy header - auto pDestination = reinterpret_cast(blob.GetBufferPointer()); + auto pDestination = blob.GetBufferPointer(); assert(pDestination); hr = EncodeDDSHeader(xbox, pDestination, DDS_XBOX_HEADER_SIZE); diff --git a/DDSTextureLoader/DDSTextureLoader11.h b/DDSTextureLoader/DDSTextureLoader11.h index 09076e3..43cfbcb 100644 --- a/DDSTextureLoader/DDSTextureLoader11.h +++ b/DDSTextureLoader/DDSTextureLoader11.h @@ -53,7 +53,7 @@ namespace DirectX #pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec" #endif - DEFINE_ENUM_FLAG_OPERATORS(DDS_LOADER_FLAGS); + DEFINE_ENUM_FLAG_OPERATORS(DDS_LOADER_FLAGS) #ifdef __clang__ #pragma clang diagnostic pop diff --git a/DDSTextureLoader/DDSTextureLoader12.h b/DDSTextureLoader/DDSTextureLoader12.h index ee31fe5..6a1f0ed 100644 --- a/DDSTextureLoader/DDSTextureLoader12.h +++ b/DDSTextureLoader/DDSTextureLoader12.h @@ -70,7 +70,7 @@ namespace DirectX #pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec" #endif - DEFINE_ENUM_FLAG_OPERATORS(DDS_LOADER_FLAGS); + DEFINE_ENUM_FLAG_OPERATORS(DDS_LOADER_FLAGS) #ifdef __clang__ #pragma clang diagnostic pop diff --git a/DirectXTex/DirectXTex.h b/DirectXTex/DirectXTex.h index 901fc4c..61c7a01 100644 --- a/DirectXTex/DirectXTex.h +++ b/DirectXTex/DirectXTex.h @@ -86,7 +86,7 @@ namespace DirectX FORMAT_TYPE __cdecl FormatDataType(_In_ DXGI_FORMAT fmt) noexcept; - enum CP_FLAGS : unsigned long + enum CP_FLAGS : uint32_t { CP_FLAGS_NONE = 0x0, // Normal operation @@ -144,13 +144,13 @@ namespace DirectX TEX_DIMENSION_TEXTURE3D = 4, }; - enum TEX_MISC_FLAG : unsigned long + enum TEX_MISC_FLAG : uint32_t // Subset here matches D3D10_RESOURCE_MISC_FLAG and D3D11_RESOURCE_MISC_FLAG { TEX_MISC_TEXTURECUBE = 0x4L, }; - enum TEX_MISC_FLAG2 : unsigned long + enum TEX_MISC_FLAG2 : uint32_t { TEX_MISC2_ALPHA_MODE_MASK = 0x7L, }; @@ -210,7 +210,7 @@ namespace DirectX bool __cdecl IsDX10() const noexcept { return (fourCC == 0x30315844); } }; - enum DDS_FLAGS : unsigned long + enum DDS_FLAGS : uint32_t { DDS_FLAGS_NONE = 0x0, @@ -257,7 +257,7 @@ namespace DirectX // Enables the loader to read large dimension .dds files (i.e. greater than known hardware requirements) }; - enum TGA_FLAGS : unsigned long + enum TGA_FLAGS : uint32_t { TGA_FLAGS_NONE = 0x0, @@ -280,7 +280,7 @@ namespace DirectX // If no colorspace is specified in TGA 2.0 metadata, assume sRGB }; - enum WIC_FLAGS : unsigned long + enum WIC_FLAGS : uint32_t { WIC_FLAGS_NONE = 0x0, @@ -325,7 +325,7 @@ namespace DirectX }; HRESULT __cdecl GetMetadataFromDDSMemory( - _In_reads_bytes_(size) const void* pSource, _In_ size_t size, + _In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size, _In_ DDS_FLAGS flags, _Out_ TexMetadata& metadata) noexcept; HRESULT __cdecl GetMetadataFromDDSFile( @@ -334,7 +334,7 @@ namespace DirectX _Out_ TexMetadata& metadata) noexcept; HRESULT __cdecl GetMetadataFromDDSMemoryEx( - _In_reads_bytes_(size) const void* pSource, _In_ size_t size, + _In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size, _In_ DDS_FLAGS flags, _Out_ TexMetadata& metadata, _Out_opt_ DDSMetaData* ddPixelFormat) noexcept; @@ -345,14 +345,14 @@ namespace DirectX _Out_opt_ DDSMetaData* ddPixelFormat) noexcept; HRESULT __cdecl GetMetadataFromHDRMemory( - _In_reads_bytes_(size) const void* pSource, _In_ size_t size, + _In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size, _Out_ TexMetadata& metadata) noexcept; HRESULT __cdecl GetMetadataFromHDRFile( _In_z_ const wchar_t* szFile, _Out_ TexMetadata& metadata) noexcept; HRESULT __cdecl GetMetadataFromTGAMemory( - _In_reads_bytes_(size) const void* pSource, _In_ size_t size, + _In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size, _In_ TGA_FLAGS flags, _Out_ TexMetadata& metadata) noexcept; HRESULT __cdecl GetMetadataFromTGAFile( @@ -362,7 +362,7 @@ namespace DirectX #ifdef _WIN32 HRESULT __cdecl GetMetadataFromWICMemory( - _In_reads_bytes_(size) const void* pSource, _In_ size_t size, + _In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size, _In_ WIC_FLAGS flags, _Out_ TexMetadata& metadata, _In_ std::function getMQR = nullptr); @@ -376,7 +376,7 @@ namespace DirectX // Compatability helpers HRESULT __cdecl GetMetadataFromTGAMemory( - _In_reads_bytes_(size) const void* pSource, _In_ size_t size, + _In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size, _Out_ TexMetadata& metadata) noexcept; HRESULT __cdecl GetMetadataFromTGAFile( _In_z_ const wchar_t* szFile, @@ -461,7 +461,10 @@ namespace DirectX void __cdecl Release() noexcept; - void *__cdecl GetBufferPointer() const noexcept { return m_buffer; } + uint8_t* __cdecl GetBufferPointer() const noexcept { return m_buffer; } + + const uint8_t* __cdecl GetConstBufferPointer() const noexcept { return m_buffer; } + size_t __cdecl GetBufferSize() const noexcept { return m_size; } HRESULT __cdecl Resize(size_t size) noexcept; @@ -471,8 +474,8 @@ namespace DirectX // Shorten size without reallocation private: - void* m_buffer; - size_t m_size; + uint8_t* m_buffer; + size_t m_size; }; //--------------------------------------------------------------------------------- @@ -480,7 +483,7 @@ namespace DirectX // DDS operations HRESULT __cdecl LoadFromDDSMemory( - _In_reads_bytes_(size) const void* pSource, _In_ size_t size, + _In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size, _In_ DDS_FLAGS flags, _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image) noexcept; HRESULT __cdecl LoadFromDDSFile( @@ -489,7 +492,7 @@ namespace DirectX _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image) noexcept; HRESULT __cdecl LoadFromDDSMemoryEx( - _In_reads_bytes_(size) const void* pSource, _In_ size_t size, + _In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size, _In_ DDS_FLAGS flags, _Out_opt_ TexMetadata* metadata, _Out_opt_ DDSMetaData* ddPixelFormat, @@ -517,7 +520,7 @@ namespace DirectX // HDR operations HRESULT __cdecl LoadFromHDRMemory( - _In_reads_bytes_(size) const void* pSource, _In_ size_t size, + _In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size, _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image) noexcept; HRESULT __cdecl LoadFromHDRFile( _In_z_ const wchar_t* szFile, @@ -528,7 +531,7 @@ namespace DirectX // TGA operations HRESULT __cdecl LoadFromTGAMemory( - _In_reads_bytes_(size) const void* pSource, _In_ size_t size, + _In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size, _In_ TGA_FLAGS flags, _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image) noexcept; HRESULT __cdecl LoadFromTGAFile( @@ -546,7 +549,7 @@ namespace DirectX // WIC operations #ifdef _WIN32 HRESULT __cdecl LoadFromWICMemory( - _In_reads_bytes_(size) const void* pSource, _In_ size_t size, + _In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size, _In_ WIC_FLAGS flags, _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image, _In_ std::function getMQR = nullptr); @@ -578,7 +581,7 @@ namespace DirectX // Compatability helpers HRESULT __cdecl LoadFromTGAMemory( - _In_reads_bytes_(size) const void* pSource, _In_ size_t size, + _In_reads_bytes_(size) const uint8_t* pSource, _In_ size_t size, _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image) noexcept; HRESULT __cdecl LoadFromTGAFile( _In_z_ const wchar_t* szFile, @@ -590,7 +593,7 @@ namespace DirectX //--------------------------------------------------------------------------------- // Texture conversion, resizing, mipmap generation, and block compression - enum TEX_FR_FLAGS : unsigned long + enum TEX_FR_FLAGS : uint32_t { TEX_FR_ROTATE0 = 0x0, TEX_FR_ROTATE90 = 0x1, @@ -608,7 +611,7 @@ namespace DirectX // Flip and/or rotate image #endif - enum TEX_FILTER_FLAGS : unsigned long + enum TEX_FILTER_FLAGS : uint32_t { TEX_FILTER_DEFAULT = 0, @@ -662,9 +665,9 @@ namespace DirectX // Forces use of the WIC path even when logic would have picked a non-WIC path when both are an option }; - constexpr unsigned long TEX_FILTER_DITHER_MASK = 0xF0000; - constexpr unsigned long TEX_FILTER_MODE_MASK = 0xF00000; - constexpr unsigned long TEX_FILTER_SRGB_MASK = 0xF000000; + constexpr uint32_t TEX_FILTER_DITHER_MASK = 0xF0000; + constexpr uint32_t TEX_FILTER_MODE_MASK = 0xF00000; + constexpr uint32_t TEX_FILTER_SRGB_MASK = 0xF000000; HRESULT __cdecl Resize( _In_ const Image& srcImage, _In_ size_t width, _In_ size_t height, @@ -731,7 +734,7 @@ namespace DirectX _In_ float alphaReference, _Inout_ ScratchImage& mipChain) noexcept; - enum TEX_PMALPHA_FLAGS : unsigned long + enum TEX_PMALPHA_FLAGS : uint32_t { TEX_PMALPHA_DEFAULT = 0, @@ -754,7 +757,7 @@ namespace DirectX _In_ TEX_PMALPHA_FLAGS flags, _Out_ ScratchImage& result) noexcept; // Converts to/from a premultiplied alpha version of the texture - enum TEX_COMPRESS_FLAGS : unsigned long + enum TEX_COMPRESS_FLAGS : uint32_t { TEX_COMPRESS_DEFAULT = 0, @@ -840,7 +843,7 @@ namespace DirectX //--------------------------------------------------------------------------------- // Normal map operations - enum CNMAP_FLAGS : unsigned long + enum CNMAP_FLAGS : uint32_t { CNMAP_DEFAULT = 0, @@ -889,7 +892,7 @@ namespace DirectX _In_ const Image& srcImage, _In_ const Rect& srcRect, _In_ const Image& dstImage, _In_ TEX_FILTER_FLAGS filter, _In_ size_t xOffset, _In_ size_t yOffset) noexcept; - enum CMSE_FLAGS : unsigned long + enum CMSE_FLAGS : uint32_t { CMSE_DEFAULT = 0, @@ -953,7 +956,7 @@ namespace DirectX // DDS helper functions HRESULT __cdecl EncodeDDSHeader( _In_ const TexMetadata& metadata, DDS_FLAGS flags, - _Out_writes_bytes_to_opt_(maxsize, required) void* pDestination, _In_ size_t maxsize, + _Out_writes_bytes_to_opt_(maxsize, required) uint8_t* pDestination, _In_ size_t maxsize, _Out_ size_t& required) noexcept; //--------------------------------------------------------------------------------- diff --git a/DirectXTex/DirectXTex.inl b/DirectXTex/DirectXTex.inl index 0b8be4c..49745ae 100644 --- a/DirectXTex/DirectXTex.inl +++ b/DirectXTex/DirectXTex.inl @@ -14,29 +14,29 @@ //===================================================================================== // Bitmask flags enumerator operators //===================================================================================== -DEFINE_ENUM_FLAG_OPERATORS(CP_FLAGS); -DEFINE_ENUM_FLAG_OPERATORS(DDS_FLAGS); -DEFINE_ENUM_FLAG_OPERATORS(TGA_FLAGS); -DEFINE_ENUM_FLAG_OPERATORS(WIC_FLAGS); -DEFINE_ENUM_FLAG_OPERATORS(TEX_FR_FLAGS); -DEFINE_ENUM_FLAG_OPERATORS(TEX_FILTER_FLAGS); -DEFINE_ENUM_FLAG_OPERATORS(TEX_PMALPHA_FLAGS); -DEFINE_ENUM_FLAG_OPERATORS(TEX_COMPRESS_FLAGS); -DEFINE_ENUM_FLAG_OPERATORS(CNMAP_FLAGS); -DEFINE_ENUM_FLAG_OPERATORS(CMSE_FLAGS); -DEFINE_ENUM_FLAG_OPERATORS(CREATETEX_FLAGS); +DEFINE_ENUM_FLAG_OPERATORS(CP_FLAGS) +DEFINE_ENUM_FLAG_OPERATORS(DDS_FLAGS) +DEFINE_ENUM_FLAG_OPERATORS(TGA_FLAGS) +DEFINE_ENUM_FLAG_OPERATORS(WIC_FLAGS) +DEFINE_ENUM_FLAG_OPERATORS(TEX_FR_FLAGS) +DEFINE_ENUM_FLAG_OPERATORS(TEX_FILTER_FLAGS) +DEFINE_ENUM_FLAG_OPERATORS(TEX_PMALPHA_FLAGS) +DEFINE_ENUM_FLAG_OPERATORS(TEX_COMPRESS_FLAGS) +DEFINE_ENUM_FLAG_OPERATORS(CNMAP_FLAGS) +DEFINE_ENUM_FLAG_OPERATORS(CMSE_FLAGS) +DEFINE_ENUM_FLAG_OPERATORS(CREATETEX_FLAGS) // WIC_FILTER modes match TEX_FILTER modes -constexpr WIC_FLAGS operator|(WIC_FLAGS a, TEX_FILTER_FLAGS b) { return static_cast(static_cast(a) | static_cast(b & TEX_FILTER_MODE_MASK)); } -constexpr WIC_FLAGS operator|(TEX_FILTER_FLAGS a, WIC_FLAGS b) { return static_cast(static_cast(a & TEX_FILTER_MODE_MASK) | static_cast(b)); } +constexpr WIC_FLAGS operator|(WIC_FLAGS a, TEX_FILTER_FLAGS b) { return static_cast(static_cast(a) | static_cast(b & TEX_FILTER_MODE_MASK)); } +constexpr WIC_FLAGS operator|(TEX_FILTER_FLAGS a, WIC_FLAGS b) { return static_cast(static_cast(a & TEX_FILTER_MODE_MASK) | static_cast(b)); } // TEX_PMALPHA_SRGB match TEX_FILTER_SRGB -constexpr TEX_PMALPHA_FLAGS operator|(TEX_PMALPHA_FLAGS a, TEX_FILTER_FLAGS b) { return static_cast(static_cast(a) | static_cast(b & TEX_FILTER_SRGB_MASK)); } -constexpr TEX_PMALPHA_FLAGS operator|(TEX_FILTER_FLAGS a, TEX_PMALPHA_FLAGS b) { return static_cast(static_cast(a & TEX_FILTER_SRGB_MASK) | static_cast(b)); } +constexpr TEX_PMALPHA_FLAGS operator|(TEX_PMALPHA_FLAGS a, TEX_FILTER_FLAGS b) { return static_cast(static_cast(a) | static_cast(b & TEX_FILTER_SRGB_MASK)); } +constexpr TEX_PMALPHA_FLAGS operator|(TEX_FILTER_FLAGS a, TEX_PMALPHA_FLAGS b) { return static_cast(static_cast(a & TEX_FILTER_SRGB_MASK) | static_cast(b)); } // TEX_COMPRESS_SRGB match TEX_FILTER_SRGB -constexpr TEX_COMPRESS_FLAGS operator|(TEX_COMPRESS_FLAGS a, TEX_FILTER_FLAGS b) { return static_cast(static_cast(a) | static_cast(b & TEX_FILTER_SRGB_MASK)); } -constexpr TEX_COMPRESS_FLAGS operator|(TEX_FILTER_FLAGS a, TEX_COMPRESS_FLAGS b) { return static_cast(static_cast(a & TEX_FILTER_SRGB_MASK) | static_cast(b)); } +constexpr TEX_COMPRESS_FLAGS operator|(TEX_COMPRESS_FLAGS a, TEX_FILTER_FLAGS b) { return static_cast(static_cast(a) | static_cast(b & TEX_FILTER_SRGB_MASK)); } +constexpr TEX_COMPRESS_FLAGS operator|(TEX_FILTER_FLAGS a, TEX_COMPRESS_FLAGS b) { return static_cast(static_cast(a & TEX_FILTER_SRGB_MASK) | static_cast(b)); } //===================================================================================== @@ -156,7 +156,7 @@ inline HRESULT __cdecl SaveToDDSFile(const Image& image, DDS_FLAGS flags, const // Compatability helpers //===================================================================================== _Use_decl_annotations_ -inline HRESULT __cdecl GetMetadataFromTGAMemory(const void* pSource, size_t size, TexMetadata& metadata) noexcept +inline HRESULT __cdecl GetMetadataFromTGAMemory(const uint8_t* pSource, size_t size, TexMetadata& metadata) noexcept { return GetMetadataFromTGAMemory(pSource, size, TGA_FLAGS_NONE, metadata); } @@ -168,7 +168,7 @@ inline HRESULT __cdecl GetMetadataFromTGAFile(const wchar_t* szFile, TexMetadata } _Use_decl_annotations_ -inline HRESULT __cdecl LoadFromTGAMemory(const void* pSource, size_t size, TexMetadata* metadata, ScratchImage& image) noexcept +inline HRESULT __cdecl LoadFromTGAMemory(const uint8_t* pSource, size_t size, TexMetadata* metadata, ScratchImage& image) noexcept { return LoadFromTGAMemory(pSource, size, TGA_FLAGS_NONE, metadata, image); } diff --git a/DirectXTex/DirectXTexDDS.cpp b/DirectXTex/DirectXTexDDS.cpp index 91a1f9b..c471da3 100644 --- a/DirectXTex/DirectXTexDDS.cpp +++ b/DirectXTex/DirectXTexDDS.cpp @@ -675,7 +675,7 @@ _Use_decl_annotations_ HRESULT DirectX::EncodeDDSHeader( const TexMetadata& metadata, DDS_FLAGS flags, - void* pDestination, + uint8_t* pDestination, size_t maxsize, size_t& required) noexcept { @@ -851,7 +851,7 @@ HRESULT DirectX::EncodeDDSHeader( if (maxsize < required) return E_NOT_SUFFICIENT_BUFFER; - *static_cast(pDestination) = DDS_MAGIC; + *reinterpret_cast(pDestination) = DDS_MAGIC; auto header = reinterpret_cast(static_cast(pDestination) + sizeof(uint32_t)); assert(header); @@ -1835,7 +1835,7 @@ namespace _Use_decl_annotations_ HRESULT DirectX::GetMetadataFromDDSMemory( - const void* pSource, + const uint8_t* pSource, size_t size, DDS_FLAGS flags, TexMetadata& metadata) noexcept @@ -1845,7 +1845,7 @@ HRESULT DirectX::GetMetadataFromDDSMemory( _Use_decl_annotations_ HRESULT DirectX::GetMetadataFromDDSMemoryEx( - const void* pSource, + const uint8_t* pSource, size_t size, DDS_FLAGS flags, TexMetadata& metadata, @@ -1957,7 +1957,7 @@ HRESULT DirectX::GetMetadataFromDDSFileEx( //------------------------------------------------------------------------------------- _Use_decl_annotations_ HRESULT DirectX::LoadFromDDSMemory( - const void* pSource, + const uint8_t* pSource, size_t size, DDS_FLAGS flags, TexMetadata* metadata, @@ -1968,7 +1968,7 @@ HRESULT DirectX::LoadFromDDSMemory( _Use_decl_annotations_ HRESULT DirectX::LoadFromDDSMemoryEx( - const void* pSource, + const uint8_t* pSource, size_t size, DDS_FLAGS flags, TexMetadata* metadata, @@ -2355,7 +2355,7 @@ HRESULT DirectX::SaveToDDSMemory( if (FAILED(hr)) return hr; - auto pDestination = static_cast(blob.GetBufferPointer()); + auto pDestination = blob.GetBufferPointer(); assert(pDestination); hr = EncodeDDSHeader(metadata, flags, pDestination, blob.GetBufferSize(), required); diff --git a/DirectXTex/DirectXTexHDR.cpp b/DirectXTex/DirectXTexHDR.cpp index 78f66b0..7c8bd08 100644 --- a/DirectXTex/DirectXTexHDR.cpp +++ b/DirectXTex/DirectXTexHDR.cpp @@ -94,7 +94,7 @@ namespace // Decodes HDR header //------------------------------------------------------------------------------------- HRESULT DecodeHDRHeader( - _In_reads_bytes_(size) const void* pSource, + _In_reads_bytes_(size) const uint8_t* pSource, size_t size, _Out_ TexMetadata& metadata, size_t& offset, @@ -121,7 +121,7 @@ namespace // Process first part of header bool formatFound = false; - auto info = static_cast(pSource); + auto info = reinterpret_cast(pSource); while (size > 0) { if (*info == '\n') @@ -310,7 +310,7 @@ namespace return E_FAIL; } - offset = size_t(info - static_cast(pSource)); + offset = size_t(info - reinterpret_cast(pSource)); metadata.width = width; metadata.height = height; @@ -600,7 +600,7 @@ namespace // Obtain metadata from HDR file in memory/on disk //------------------------------------------------------------------------------------- _Use_decl_annotations_ -HRESULT DirectX::GetMetadataFromHDRMemory(const void* pSource, size_t size, TexMetadata& metadata) noexcept +HRESULT DirectX::GetMetadataFromHDRMemory(const uint8_t* pSource, size_t size, TexMetadata& metadata) noexcept { if (!pSource || size == 0) return E_INVALIDARG; @@ -696,7 +696,7 @@ HRESULT DirectX::GetMetadataFromHDRFile(const wchar_t* szFile, TexMetadata& meta // Load a HDR file in memory //------------------------------------------------------------------------------------- _Use_decl_annotations_ -HRESULT DirectX::LoadFromHDRMemory(const void* pSource, size_t size, TexMetadata* metadata, ScratchImage& image) noexcept +HRESULT DirectX::LoadFromHDRMemory(const uint8_t* pSource, size_t size, TexMetadata* metadata, ScratchImage& image) noexcept { if (!pSource || size == 0) return E_INVALIDARG; @@ -1045,7 +1045,7 @@ HRESULT DirectX::SaveToHDRMemory(const Image& image, Blob& blob) noexcept return hr; // Copy header - auto dPtr = static_cast(blob.GetBufferPointer()); + auto dPtr = blob.GetBufferPointer(); assert(dPtr != nullptr); memcpy(dPtr, header, headerLen); dPtr += headerLen; @@ -1097,7 +1097,7 @@ HRESULT DirectX::SaveToHDRMemory(const Image& image, Blob& blob) noexcept } #endif - hr = blob.Trim(size_t(dPtr - static_cast(blob.GetBufferPointer()))); + hr = blob.Trim(size_t(dPtr - blob.GetConstBufferPointer())); if (FAILED(hr)) { blob.Release(); @@ -1184,7 +1184,7 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce #ifdef _WIN32 auto const bytesToWrite = static_cast(blob.GetBufferSize()); DWORD bytesWritten; - if (!WriteFile(hFile.get(), blob.GetBufferPointer(), bytesToWrite, &bytesWritten, nullptr)) + if (!WriteFile(hFile.get(), blob.GetConstBufferPointer(), bytesToWrite, &bytesWritten, nullptr)) { return HRESULT_FROM_WIN32(GetLastError()); } @@ -1194,7 +1194,7 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce return E_FAIL; } #else - outFile.write(reinterpret_cast(blob.GetBufferPointer()), + outFile.write(reinterpret_cast(blob.GetConstBufferPointer()), static_cast(blob.GetBufferSize())); if (!outFile) diff --git a/DirectXTex/DirectXTexMipmaps.cpp b/DirectXTex/DirectXTexMipmaps.cpp index 29ec19f..38cd03d 100644 --- a/DirectXTex/DirectXTexMipmaps.cpp +++ b/DirectXTex/DirectXTexMipmaps.cpp @@ -2955,7 +2955,7 @@ HRESULT DirectX::GenerateMipMaps( mdata.mipLevels = levels; mdata.format = baseImage.format; - unsigned long filter_select = (filter & TEX_FILTER_MODE_MASK); + uint32_t filter_select = (filter & TEX_FILTER_MODE_MASK); if (!filter_select) { // Default filter choice @@ -3170,7 +3170,7 @@ HRESULT DirectX::GenerateMipMaps( TexMetadata mdata2 = metadata; mdata2.mipLevels = levels; - unsigned long filter_select = (filter & TEX_FILTER_MODE_MASK); + uint32_t filter_select = (filter & TEX_FILTER_MODE_MASK); if (!filter_select) { // Default filter choice @@ -3300,7 +3300,7 @@ HRESULT DirectX::GenerateMipMaps3D( HRESULT hr = E_UNEXPECTED; - unsigned long filter_select = (filter & TEX_FILTER_MODE_MASK); + uint32_t filter_select = (filter & TEX_FILTER_MODE_MASK); if (!filter_select) { // Default filter choice @@ -3419,7 +3419,7 @@ HRESULT DirectX::GenerateMipMaps3D( static_assert(TEX_FILTER_POINT == 0x100000, "TEX_FILTER_ flag values don't match TEX_FILTER_MODE_MASK"); - unsigned long filter_select = (filter & TEX_FILTER_MODE_MASK); + uint32_t filter_select = (filter & TEX_FILTER_MODE_MASK); if (!filter_select) { // Default filter choice diff --git a/DirectXTex/DirectXTexResize.cpp b/DirectXTex/DirectXTexResize.cpp index 831235b..5f25b8e 100644 --- a/DirectXTex/DirectXTexResize.cpp +++ b/DirectXTex/DirectXTexResize.cpp @@ -811,7 +811,7 @@ namespace static_assert(TEX_FILTER_POINT == 0x100000, "TEX_FILTER_ flag values don't match TEX_FILTER_MASK"); - unsigned long filter_select = filter & TEX_FILTER_MODE_MASK; + uint32_t filter_select = filter & TEX_FILTER_MODE_MASK; if (!filter_select) { // Default filter choice diff --git a/DirectXTex/DirectXTexTGA.cpp b/DirectXTex/DirectXTexTGA.cpp index 8a49d5e..b758a4f 100644 --- a/DirectXTex/DirectXTexTGA.cpp +++ b/DirectXTex/DirectXTexTGA.cpp @@ -139,7 +139,7 @@ namespace // Decodes TGA header //------------------------------------------------------------------------------------- HRESULT DecodeTGAHeader( - _In_reads_bytes_(size) const void* pSource, + _In_reads_bytes_(size) const uint8_t* pSource, size_t size, TGA_FLAGS flags, _Out_ TexMetadata& metadata, @@ -156,7 +156,7 @@ namespace return HRESULT_E_INVALID_DATA; } - auto pHeader = static_cast(pSource); + auto pHeader = reinterpret_cast(pSource); if (pHeader->bDescriptor & (TGA_FLAGS_INTERLEAVED_2WAY | TGA_FLAGS_INTERLEAVED_4WAY)) { @@ -1447,7 +1447,7 @@ namespace //------------------------------------------------------------------------------------- _Use_decl_annotations_ HRESULT DirectX::GetMetadataFromTGAMemory( - const void* pSource, + const uint8_t* pSource, size_t size, TGA_FLAGS flags, TexMetadata& metadata) noexcept @@ -1641,7 +1641,7 @@ HRESULT DirectX::GetMetadataFromTGAFile(const wchar_t* szFile, TGA_FLAGS flags, //------------------------------------------------------------------------------------- _Use_decl_annotations_ HRESULT DirectX::LoadFromTGAMemory( - const void* pSource, + const uint8_t* pSource, size_t size, TGA_FLAGS flags, TexMetadata* metadata, @@ -2279,7 +2279,7 @@ HRESULT DirectX::SaveToTGAMemory( return hr; // Copy header - auto destPtr = static_cast(blob.GetBufferPointer()); + auto destPtr = blob.GetBufferPointer(); assert(destPtr != nullptr); uint8_t* dPtr = destPtr; @@ -2396,7 +2396,7 @@ HRESULT DirectX::SaveToTGAFile( #ifdef _WIN32 const DWORD bytesToWrite = static_cast(blob.GetBufferSize()); DWORD bytesWritten; - if (!WriteFile(hFile.get(), blob.GetBufferPointer(), bytesToWrite, &bytesWritten, nullptr)) + if (!WriteFile(hFile.get(), blob.GetConstBufferPointer(), bytesToWrite, &bytesWritten, nullptr)) { return HRESULT_FROM_WIN32(GetLastError()); } @@ -2406,7 +2406,7 @@ HRESULT DirectX::SaveToTGAFile( return E_FAIL; } #else - outFile.write(reinterpret_cast(blob.GetBufferPointer()), + outFile.write(reinterpret_cast(blob.GetConstBufferPointer()), static_cast(blob.GetBufferSize())); if (!outFile) diff --git a/DirectXTex/DirectXTexUtil.cpp b/DirectXTex/DirectXTexUtil.cpp index c78df2e..fd14984 100644 --- a/DirectXTex/DirectXTexUtil.cpp +++ b/DirectXTex/DirectXTexUtil.cpp @@ -1688,7 +1688,7 @@ HRESULT Blob::Initialize(size_t size) noexcept Release(); - m_buffer = _aligned_malloc(size, 16); + m_buffer = reinterpret_cast(_aligned_malloc(size, 16)); if (!m_buffer) { Release(); @@ -1724,7 +1724,7 @@ HRESULT Blob::Resize(size_t size) noexcept if (!m_buffer || !m_size) return E_UNEXPECTED; - void *tbuffer = _aligned_malloc(size, 16); + auto tbuffer = reinterpret_cast(_aligned_malloc(size, 16)); if (!tbuffer) return E_OUTOFMEMORY; diff --git a/DirectXTex/DirectXTexWIC.cpp b/DirectXTex/DirectXTexWIC.cpp index 958663d..63caf1b 100644 --- a/DirectXTex/DirectXTexWIC.cpp +++ b/DirectXTex/DirectXTexWIC.cpp @@ -208,7 +208,7 @@ namespace m_streamEOF(0), mRefCount(1) { - assert(mBlob.GetBufferPointer() && mBlob.GetBufferSize() > 0); + assert(mBlob.GetConstBufferPointer() && mBlob.GetBufferSize() > 0); } public: @@ -254,7 +254,7 @@ namespace HRESULT STDMETHODCALLTYPE Read(void* pv, ULONG cb, ULONG* pcbRead) override { size_t maxRead = m_streamEOF - m_streamPosition; - auto ptr = static_cast(mBlob.GetBufferPointer()); + auto ptr = mBlob.GetBufferPointer(); if (cb > maxRead) { const uint64_t pos = uint64_t(m_streamPosition) + uint64_t(maxRead); @@ -324,7 +324,7 @@ namespace if (pos > UINT32_MAX) return HRESULT_E_ARITHMETIC_OVERFLOW; - auto ptr = static_cast(mBlob.GetBufferPointer()); + auto ptr = mBlob.GetBufferPointer(); memcpy(&ptr[m_streamPosition], pv, cb); m_streamPosition = static_cast(pos); @@ -347,7 +347,7 @@ namespace if (blobSize >= size.LowPart) { - auto ptr = static_cast(mBlob.GetBufferPointer()); + auto ptr = mBlob.GetBufferPointer(); if (m_streamEOF < size.LowPart) { memset(&ptr[m_streamEOF], 0, size.LowPart - m_streamEOF); @@ -367,7 +367,7 @@ namespace if (FAILED(hr)) return hr; - auto ptr = static_cast(mBlob.GetBufferPointer()); + auto ptr = mBlob.GetBufferPointer(); if (m_streamEOF < size.LowPart) { memset(&ptr[m_streamEOF], 0, size.LowPart - m_streamEOF); @@ -1221,7 +1221,7 @@ namespace //------------------------------------------------------------------------------------- _Use_decl_annotations_ HRESULT DirectX::GetMetadataFromWICMemory( - const void* pSource, + const uint8_t* pSource, size_t size, WIC_FLAGS flags, TexMetadata& metadata, @@ -1244,7 +1244,7 @@ HRESULT DirectX::GetMetadataFromWICMemory( if (FAILED(hr)) return hr; - hr = stream->InitializeFromMemory(static_cast(const_cast(pSource)), + hr = stream->InitializeFromMemory(static_cast(const_cast(pSource)), static_cast(size)); if (FAILED(hr)) return hr; @@ -1312,7 +1312,7 @@ HRESULT DirectX::GetMetadataFromWICFile( //------------------------------------------------------------------------------------- _Use_decl_annotations_ HRESULT DirectX::LoadFromWICMemory( - const void* pSource, + const uint8_t* pSource, size_t size, WIC_FLAGS flags, TexMetadata* metadata, @@ -1338,7 +1338,7 @@ HRESULT DirectX::LoadFromWICMemory( if (FAILED(hr)) return hr; - hr = stream->InitializeFromMemory(static_cast(const_cast(pSource)), static_cast(size)); + hr = stream->InitializeFromMemory(static_cast(const_cast(pSource)), static_cast(size)); if (FAILED(hr)) return hr; diff --git a/WICTextureLoader/WICTextureLoader11.h b/WICTextureLoader/WICTextureLoader11.h index 151da38..b73093c 100644 --- a/WICTextureLoader/WICTextureLoader11.h +++ b/WICTextureLoader/WICTextureLoader11.h @@ -51,7 +51,7 @@ namespace DirectX #pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec" #endif - DEFINE_ENUM_FLAG_OPERATORS(WIC_LOADER_FLAGS); + DEFINE_ENUM_FLAG_OPERATORS(WIC_LOADER_FLAGS) #ifdef __clang__ #pragma clang diagnostic pop diff --git a/WICTextureLoader/WICTextureLoader12.h b/WICTextureLoader/WICTextureLoader12.h index 54d8b8a..5ed394b 100644 --- a/WICTextureLoader/WICTextureLoader12.h +++ b/WICTextureLoader/WICTextureLoader12.h @@ -65,7 +65,7 @@ namespace DirectX #pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec" #endif - DEFINE_ENUM_FLAG_OPERATORS(WIC_LOADER_FLAGS); + DEFINE_ENUM_FLAG_OPERATORS(WIC_LOADER_FLAGS) #ifdef __clang__ #pragma clang diagnostic pop diff --git a/WICTextureLoader/WICTextureLoader9.h b/WICTextureLoader/WICTextureLoader9.h index cee2ef6..2ccf653 100644 --- a/WICTextureLoader/WICTextureLoader9.h +++ b/WICTextureLoader/WICTextureLoader9.h @@ -47,7 +47,7 @@ namespace DirectX #pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec" #endif - DEFINE_ENUM_FLAG_OPERATORS(WIC_LOADER_FLAGS); + DEFINE_ENUM_FLAG_OPERATORS(WIC_LOADER_FLAGS) #ifdef __clang__ #pragma clang diagnostic pop