crossxtex/DirectXTex/DirectXTex.inl

125 lines
3.5 KiB
Plaintext
Raw Normal View History

2016-08-22 18:26:36 +00:00
//-------------------------------------------------------------------------------------
// DirectXTex.inl
//
// DirectX Texture Library
//
// Copyright (c) Microsoft Corporation. All rights reserved.
2018-02-24 06:24:46 +00:00
// Licensed under the MIT License.
2016-08-22 18:26:36 +00:00
//
// http://go.microsoft.com/fwlink/?LinkId=248926
//-------------------------------------------------------------------------------------
#pragma once
//=====================================================================================
// DXGI Format Utilities
//=====================================================================================
_Use_decl_annotations_
2020-02-26 23:55:05 +00:00
constexpr inline bool __cdecl IsValid(DXGI_FORMAT fmt) noexcept
2016-08-22 18:26:36 +00:00
{
2018-03-16 19:52:21 +00:00
return (static_cast<size_t>(fmt) >= 1 && static_cast<size_t>(fmt) <= 190);
2016-08-22 18:26:36 +00:00
}
_Use_decl_annotations_
2019-12-12 03:52:48 +00:00
inline bool __cdecl IsCompressed(DXGI_FORMAT fmt) noexcept
2016-08-22 18:26:36 +00:00
{
2018-03-16 19:52:21 +00:00
switch (fmt)
2016-08-22 18:26:36 +00:00
{
2018-03-16 19:52:21 +00:00
case DXGI_FORMAT_BC1_TYPELESS:
case DXGI_FORMAT_BC1_UNORM:
case DXGI_FORMAT_BC1_UNORM_SRGB:
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_BC4_TYPELESS:
case DXGI_FORMAT_BC4_UNORM:
case DXGI_FORMAT_BC4_SNORM:
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 true;
2016-08-22 18:26:36 +00:00
2018-03-16 19:52:21 +00:00
default:
return false;
2016-08-22 18:26:36 +00:00
}
}
_Use_decl_annotations_
2019-12-12 03:52:48 +00:00
inline bool __cdecl IsPalettized(DXGI_FORMAT fmt) noexcept
2016-08-22 18:26:36 +00:00
{
2018-03-16 19:52:21 +00:00
switch (fmt)
2016-08-22 18:26:36 +00:00
{
2018-03-16 19:52:21 +00:00
case DXGI_FORMAT_AI44:
case DXGI_FORMAT_IA44:
case DXGI_FORMAT_P8:
case DXGI_FORMAT_A8P8:
return true;
2016-08-22 18:26:36 +00:00
2018-03-16 19:52:21 +00:00
default:
return false;
2016-08-22 18:26:36 +00:00
}
}
_Use_decl_annotations_
2019-12-12 03:52:48 +00:00
inline bool __cdecl IsSRGB(DXGI_FORMAT fmt) noexcept
2016-08-22 18:26:36 +00:00
{
2018-03-16 19:52:21 +00:00
switch (fmt)
2016-08-22 18:26:36 +00:00
{
2018-03-16 19:52:21 +00:00
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
case DXGI_FORMAT_BC1_UNORM_SRGB:
case DXGI_FORMAT_BC2_UNORM_SRGB:
case DXGI_FORMAT_BC3_UNORM_SRGB:
case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
case DXGI_FORMAT_BC7_UNORM_SRGB:
return true;
2016-08-22 18:26:36 +00:00
2018-03-16 19:52:21 +00:00
default:
return false;
2016-08-22 18:26:36 +00:00
}
}
//=====================================================================================
// Image I/O
//=====================================================================================
_Use_decl_annotations_
2019-12-13 08:01:17 +00:00
inline HRESULT __cdecl SaveToDDSMemory(const Image& image, DWORD flags, Blob& blob) noexcept
2016-08-22 18:26:36 +00:00
{
TexMetadata mdata = {};
mdata.width = image.width;
mdata.height = image.height;
mdata.depth = 1;
mdata.arraySize = 1;
mdata.mipLevels = 1;
mdata.format = image.format;
mdata.dimension = TEX_DIMENSION_TEXTURE2D;
2018-03-16 19:52:21 +00:00
return SaveToDDSMemory(&image, 1, mdata, flags, blob);
2016-08-22 18:26:36 +00:00
}
_Use_decl_annotations_
2019-12-13 08:01:17 +00:00
inline HRESULT __cdecl SaveToDDSFile(const Image& image, DWORD flags, const wchar_t* szFile) noexcept
2016-08-22 18:26:36 +00:00
{
TexMetadata mdata = {};
mdata.width = image.width;
mdata.height = image.height;
mdata.depth = 1;
mdata.arraySize = 1;
mdata.mipLevels = 1;
mdata.format = image.format;
mdata.dimension = TEX_DIMENSION_TEXTURE2D;
2018-03-16 19:52:21 +00:00
return SaveToDDSFile(&image, 1, mdata, flags, szFile);
2016-08-22 18:26:36 +00:00
}