Skip to content

Commit e3b30d0

Browse files
committed
Adds BytesPerBlock helper
1 parent 73aa2f3 commit e3b30d0

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

DirectXTex/DirectXTex.h

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ namespace DirectX
7272

7373
size_t __cdecl BitsPerColor(_In_ DXGI_FORMAT fmt) noexcept;
7474

75+
size_t __cdecl BytesPerBlock(_In_ DXGI_FORMAT fmt) noexcept;
76+
7577
enum FORMAT_TYPE
7678
{
7779
FORMAT_TYPE_TYPELESS,

DirectXTex/DirectXTexUtil.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,45 @@ size_t DirectX::BitsPerColor(DXGI_FORMAT fmt) noexcept
920920
}
921921

922922

923+
//-------------------------------------------------------------------------------------
924+
// Returns bytes per block for a given DXGI BC format, or 0 on failure
925+
//-------------------------------------------------------------------------------------
926+
_Use_decl_annotations_
927+
size_t DirectX::BytesPerBlock(DXGI_FORMAT fmt) noexcept
928+
{
929+
switch (fmt)
930+
{
931+
case DXGI_FORMAT_BC1_TYPELESS:
932+
case DXGI_FORMAT_BC1_UNORM:
933+
case DXGI_FORMAT_BC1_UNORM_SRGB:
934+
case DXGI_FORMAT_BC4_TYPELESS:
935+
case DXGI_FORMAT_BC4_UNORM:
936+
case DXGI_FORMAT_BC4_SNORM:
937+
return 8;
938+
939+
case DXGI_FORMAT_BC2_TYPELESS:
940+
case DXGI_FORMAT_BC2_UNORM:
941+
case DXGI_FORMAT_BC2_UNORM_SRGB:
942+
case DXGI_FORMAT_BC3_TYPELESS:
943+
case DXGI_FORMAT_BC3_UNORM:
944+
case DXGI_FORMAT_BC3_UNORM_SRGB:
945+
case DXGI_FORMAT_BC5_TYPELESS:
946+
case DXGI_FORMAT_BC5_UNORM:
947+
case DXGI_FORMAT_BC5_SNORM:
948+
case DXGI_FORMAT_BC6H_TYPELESS:
949+
case DXGI_FORMAT_BC6H_UF16:
950+
case DXGI_FORMAT_BC6H_SF16:
951+
case DXGI_FORMAT_BC7_TYPELESS:
952+
case DXGI_FORMAT_BC7_UNORM:
953+
case DXGI_FORMAT_BC7_UNORM_SRGB:
954+
return 16;
955+
956+
default:
957+
return 0;
958+
}
959+
}
960+
961+
923962
//-------------------------------------------------------------------------------------
924963
// Computes the image row pitch in bytes, and the slice ptich (size in bytes of the image)
925964
// based on DXGI format, width, and height

0 commit comments

Comments
 (0)