Skip to content

Commit

Permalink
Use fixed width integers for underlying enum types (#538)
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn authored Oct 24, 2024
1 parent cea630a commit 6e7801e
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 106 deletions.
13 changes: 8 additions & 5 deletions Auxiliary/DirectXTexXbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
#include <d3d11_1.h>
#endif

#include <cstdint>
#include <utility>

#define DIRECTX_TEX_XBOX_VERSION 150

namespace Xbox
Expand Down Expand Up @@ -95,28 +98,28 @@ 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(
_In_z_ const wchar_t* szFile, _Out_ DirectX::TexMetadata& metadata, _Out_ bool& isXbox,
_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);
Expand Down Expand Up @@ -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
14 changes: 7 additions & 7 deletions Auxiliary/DirectXTexXboxDDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -694,7 +694,7 @@ HRESULT Xbox::SaveToDDSMemory(const XboxImage& xbox, Blob& blob)
return hr;

// Copy header
auto pDestination = reinterpret_cast<uint8_t*>(blob.GetBufferPointer());
auto pDestination = blob.GetBufferPointer();
assert(pDestination);

hr = EncodeDDSHeader(xbox, pDestination, DDS_XBOX_HEADER_SIZE);
Expand Down
2 changes: 1 addition & 1 deletion DDSTextureLoader/DDSTextureLoader11.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion DDSTextureLoader/DDSTextureLoader12.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
65 changes: 34 additions & 31 deletions DirectXTex/DirectXTex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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,

Expand All @@ -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,

Expand Down Expand Up @@ -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(
Expand All @@ -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;
Expand All @@ -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(
Expand All @@ -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<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr);
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -471,16 +474,16 @@ namespace DirectX
// Shorten size without reallocation

private:
void* m_buffer;
size_t m_size;
uint8_t* m_buffer;
size_t m_size;
};

//---------------------------------------------------------------------------------
// Image I/O

// 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(
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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<void __cdecl(IWICMetadataQueryReader*)> getMQR = nullptr);
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,

Expand All @@ -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,

Expand Down Expand Up @@ -840,7 +843,7 @@ namespace DirectX
//---------------------------------------------------------------------------------
// Normal map operations

enum CNMAP_FLAGS : unsigned long
enum CNMAP_FLAGS : uint32_t
{
CNMAP_DEFAULT = 0,

Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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;

//---------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 6e7801e

Please sign in to comment.