Skip to content

Commit

Permalink
Adds BytesPerBlock helper (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn authored Sep 20, 2024
1 parent 73aa2f3 commit 25ee5b4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions DirectXTex/DirectXTex.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ namespace DirectX

size_t __cdecl BitsPerColor(_In_ DXGI_FORMAT fmt) noexcept;

size_t __cdecl BytesPerBlock(_In_ DXGI_FORMAT fmt) noexcept;

enum FORMAT_TYPE
{
FORMAT_TYPE_TYPELESS,
Expand Down
39 changes: 39 additions & 0 deletions DirectXTex/DirectXTexUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,45 @@ size_t DirectX::BitsPerColor(DXGI_FORMAT fmt) noexcept
}


//-------------------------------------------------------------------------------------
// Returns bytes per block for a given DXGI BC format, or 0 on failure
//-------------------------------------------------------------------------------------
_Use_decl_annotations_
size_t DirectX::BytesPerBlock(DXGI_FORMAT fmt) noexcept
{
switch (fmt)
{
case DXGI_FORMAT_BC1_TYPELESS:
case DXGI_FORMAT_BC1_UNORM:
case DXGI_FORMAT_BC1_UNORM_SRGB:
case DXGI_FORMAT_BC4_TYPELESS:
case DXGI_FORMAT_BC4_UNORM:
case DXGI_FORMAT_BC4_SNORM:
return 8;

case DXGI_FORMAT_BC2_TYPELESS:
case DXGI_FORMAT_BC2_UNORM:
case DXGI_FORMAT_BC2_UNORM_SRGB:
case DXGI_FORMAT_BC3_TYPELESS:
case DXGI_FORMAT_BC3_UNORM:
case DXGI_FORMAT_BC3_UNORM_SRGB:
case DXGI_FORMAT_BC5_TYPELESS:
case DXGI_FORMAT_BC5_UNORM:
case DXGI_FORMAT_BC5_SNORM:
case DXGI_FORMAT_BC6H_TYPELESS:
case DXGI_FORMAT_BC6H_UF16:
case DXGI_FORMAT_BC6H_SF16:
case DXGI_FORMAT_BC7_TYPELESS:
case DXGI_FORMAT_BC7_UNORM:
case DXGI_FORMAT_BC7_UNORM_SRGB:
return 16;

default:
return 0;
}
}


//-------------------------------------------------------------------------------------
// Computes the image row pitch in bytes, and the slice ptich (size in bytes of the image)
// based on DXGI format, width, and height
Expand Down

0 comments on commit 25ee5b4

Please sign in to comment.