October 2019 release of DirectX Tool Kit and DirectXTex

This commit is contained in:
Chuck Walbourn 2019-11-04 21:42:39 -08:00
Родитель dc28b2e474
Коммит e6ce05bacb
26 изменённых файлов: 1029 добавлений и 539 удалений

Просмотреть файл

@ -120,8 +120,8 @@ namespace DX
throw std::exception("GetLogicalProcessorInformation");
}
int count = length / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
for (int i = 0; i < count; ++i)
size_t count = length / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
for (size_t i = 0; i < count; ++i)
{
if (procInfo[i].Relationship == RelationProcessorCore)
{

Просмотреть файл

@ -25,7 +25,7 @@
#include <memory>
#include <stdint.h>
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
#if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/)
#include <string>
#endif
@ -44,7 +44,7 @@ namespace DirectX
virtual ~GamePad();
#if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/ ) || defined(_XBOX_ONE)
#if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/) || defined(_XBOX_ONE)
static const int MAX_PLAYER_COUNT = 8;
#else
static const int MAX_PLAYER_COUNT = 4;
@ -165,15 +165,17 @@ namespace DirectX
ARCADE_PAD = 19,
};
bool connected;
Type gamepadType;
bool connected;
Type gamepadType;
#if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/)
std::wstring id;
Capabilities() noexcept : connected(false), gamepadType(UNKNOWN) {}
std::wstring id;
#else
uint64_t id;
uint64_t id;
#endif
uint16_t vid;
uint16_t pid;
Capabilities() noexcept : connected(false), gamepadType(UNKNOWN), id{}, vid(0), pid(0) {}
bool __cdecl IsConnected() const { return connected; }
};

Просмотреть файл

@ -1,3 +1,4 @@
//--------------------------------------------------------------------------------------
// File: ScreenGrab.h
//
@ -24,9 +25,7 @@
#endif
#include <OCIdl.h>
#include <functional>
#include <stdint.h>
namespace DirectX
@ -42,5 +41,6 @@ namespace DirectX
_In_ REFGUID guidContainerFormat,
_In_z_ const wchar_t* fileName,
_In_opt_ const GUID* targetFormat = nullptr,
_In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = nullptr);
_In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = nullptr,
_In_ bool forceSRGB = false);
}

Просмотреть файл

@ -4,7 +4,7 @@ DirectXTK - the DirectX Tool Kit for DirectX 11
Copyright (c) Microsoft Corporation. All rights reserved.
August 21, 2019
October 17, 2019
This package contains the "DirectX Tool Kit", a collection of helper classes for
writing Direct3D 11 C++ code for Universal Windows Platform (UWP) apps for
@ -112,6 +112,11 @@ RELEASE NOTES
RELEASE HISTORY
---------------
October 17, 2019
Added optional forceSRGB parameter to SaveWICTextureToFile
GamePad updated to report VID/PID (when supported)
Minor code cleanup
August 21, 2019
Added xwbtool to CMake project
Minor code cleanup

Просмотреть файл

@ -228,6 +228,8 @@ public:
void GetCapabilities(int player, Capabilities& caps)
{
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
using namespace ABI::Windows::Foundation;
using namespace ABI::Windows::System;
using namespace ABI::Windows::Gaming::Input;
@ -246,6 +248,7 @@ public:
caps.connected = true;
caps.gamepadType = Capabilities::GAMEPAD;
caps.id.clear();
caps.vid = caps.pid = 0;
ComPtr<IGameController> ctrl;
HRESULT hr = mGamePad[player].As(&ctrl);
@ -255,13 +258,32 @@ public:
hr = ctrl->get_User(user.GetAddressOf());
if (SUCCEEDED(hr) && user != nullptr)
{
Wrappers::HString str;
HString str;
hr = user->get_NonRoamableId(str.GetAddressOf());
if (SUCCEEDED(hr))
{
caps.id = str.GetRawBuffer(nullptr);
}
}
// Requires the Windows 10 Creators Update SDK (15063)
#if defined(NTDDI_WIN10_RS2) && (NTDDI_VERSION >= NTDDI_WIN10_RS2)
ComPtr<IRawGameControllerStatics> rawStatics;
hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_Gaming_Input_RawGameController).Get(), rawStatics.GetAddressOf());
if (SUCCEEDED(hr))
{
ComPtr<IRawGameController> raw;
hr = rawStatics->FromGameController(ctrl.Get(), raw.GetAddressOf());
if (SUCCEEDED(hr) && raw)
{
if (FAILED(raw->get_HardwareVendorId(&caps.vid)))
caps.vid = 0;
if (FAILED(raw->get_HardwareProductId(&caps.pid)))
caps.pid = 0;
}
}
#endif // NTDDI_WIN10_RS2
}
return;
}
@ -691,6 +713,8 @@ public:
{
caps.connected = true;
caps.gamepadType = Capabilities::UNKNOWN;
caps.id = 0;
caps.vid = caps.pid = 0;
ComPtr<IController> ctrl;
HRESULT hr = mGamePad[player].As(&ctrl);
@ -719,8 +743,19 @@ public:
}
}
}
else
caps.id = 0;
#if _XDK_VER >= 0x42ED07E4 /* XDK Edition 180400 */
ComPtr<IController3> ctrl3;
hr = mGamePad[player].As(&ctrl3);
if (SUCCEEDED(hr) && ctrl3)
{
if (FAILED(ctrl3->get_HardwareVendorId(&caps.vid)))
caps.vid = 0;
if (FAILED(ctrl3->get_HardwareProductId(&caps.pid)))
caps.pid = 0;
}
#endif
return;
}
@ -1034,6 +1069,14 @@ public:
caps.gamepadType = Capabilities::Type(xcaps.SubType);
}
// Hard-coded VID/PID
caps.vid = 0x045E;
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
caps.pid = (xcaps.Flags & XINPUT_CAPS_WIRELESS) ? 0x0719 : 0;
#else
caps.pid = 0;
#endif
return;
}
}
@ -1280,7 +1323,7 @@ void GamePad::Resume()
}
#if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/ ) || defined(_XBOX_ONE)
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN10) || defined(_XBOX_ONE)
void GamePad::RegisterEvents(HANDLE ctrlChanged, HANDLE userChanged)
{
pImpl->mCtrlChanged = (!ctrlChanged) ? INVALID_HANDLE_VALUE : ctrlChanged;

Просмотреть файл

@ -350,7 +350,8 @@ HRESULT DirectX::SaveWICTextureToFile(
REFGUID guidContainerFormat,
const wchar_t* fileName,
const GUID* targetFormat,
std::function<void(IPropertyBag2*)> setCustomProps)
std::function<void(IPropertyBag2*)> setCustomProps,
bool forceSRGB)
{
if (!fileName)
return E_INVALIDARG;
@ -363,7 +364,7 @@ HRESULT DirectX::SaveWICTextureToFile(
// Determine source format's WIC equivalent
WICPixelFormatGUID pfGuid;
bool sRGB = false;
bool sRGB = forceSRGB;
switch (desc.Format)
{
case DXGI_FORMAT_R32G32B32A32_FLOAT: pfGuid = GUID_WICPixelFormat128bppRGBAFloat; break;
@ -610,8 +611,8 @@ HRESULT DirectX::SaveWICTextureToFile(
// Conversion required to write
ComPtr<IWICBitmap> source;
hr = pWIC->CreateBitmapFromMemory(desc.Width, desc.Height, pfGuid,
mapped.RowPitch, mapped.RowPitch * desc.Height,
static_cast<BYTE*>(mapped.pData), source.GetAddressOf());
mapped.RowPitch, mapped.RowPitch * desc.Height,
static_cast<BYTE*>(mapped.pData), source.GetAddressOf());
if (FAILED(hr))
{
pContext->Unmap(pStaging.Get(), 0);

Просмотреть файл

@ -494,6 +494,11 @@ namespace
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}
if (xboxext->tileMode == uint32_t(-1))
{
return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
}
// Bound sizes
if (mipCount > D3D11_REQ_MIP_LEVELS)
{

Просмотреть файл

@ -25,7 +25,7 @@
#include <memory>
#include <stdint.h>
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
#if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/)
#include <string>
#endif
@ -44,7 +44,7 @@ namespace DirectX
virtual ~GamePad();
#if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/ ) || defined(_XBOX_ONE)
#if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/) || defined(_XBOX_ONE)
static const int MAX_PLAYER_COUNT = 8;
#else
static const int MAX_PLAYER_COUNT = 4;
@ -165,15 +165,17 @@ namespace DirectX
ARCADE_PAD = 19,
};
bool connected;
Type gamepadType;
bool connected;
Type gamepadType;
#if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/)
std::wstring id;
Capabilities() noexcept : connected(false), gamepadType(UNKNOWN) {}
std::wstring id;
#else
uint64_t id;
uint64_t id;
#endif
uint16_t vid;
uint16_t pid;
Capabilities() noexcept : connected(false), gamepadType(UNKNOWN), id{}, vid(0), pid(0) {}
bool __cdecl IsConnected() const { return connected; }
};

Просмотреть файл

@ -43,5 +43,6 @@ namespace DirectX
D3D12_RESOURCE_STATES beforeState = D3D12_RESOURCE_STATE_RENDER_TARGET,
D3D12_RESOURCE_STATES afterState = D3D12_RESOURCE_STATE_RENDER_TARGET,
_In_opt_ const GUID* targetFormat = nullptr,
_In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = nullptr);
_In_opt_ std::function<void __cdecl(IPropertyBag2*)> setCustomProps = nullptr,
bool forceSRGB = false);
}

Просмотреть файл

@ -4,7 +4,7 @@ DirectXTK - the DirectX Tool Kit for DirectX 12
Copyright (c) Microsoft Corporation. All rights reserved.
August 21, 2019
October 17, 2019
This package contains the "DirectX Tool Kit", a collection of helper classes for
writing Direct3D 12 C++ code for Universal Windows Platform (UWP) apps, Win32
@ -128,6 +128,11 @@ RELEASE NOTES
RELEASE HISTORY
---------------
October 17, 2019
Added optional forceSRGB parameter to SaveWICTextureToFile
GamePad updated to report VID/PID (when supported)
Minor code cleanup
August 21, 2019
Updated D3DX12 internal copy to latest version
Code cleanup

Просмотреть файл

@ -228,6 +228,8 @@ public:
void GetCapabilities(int player, Capabilities& caps)
{
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
using namespace ABI::Windows::Foundation;
using namespace ABI::Windows::System;
using namespace ABI::Windows::Gaming::Input;
@ -246,6 +248,7 @@ public:
caps.connected = true;
caps.gamepadType = Capabilities::GAMEPAD;
caps.id.clear();
caps.vid = caps.pid = 0;
ComPtr<IGameController> ctrl;
HRESULT hr = mGamePad[player].As(&ctrl);
@ -255,13 +258,32 @@ public:
hr = ctrl->get_User(user.GetAddressOf());
if (SUCCEEDED(hr) && user != nullptr)
{
Wrappers::HString str;
HString str;
hr = user->get_NonRoamableId(str.GetAddressOf());
if (SUCCEEDED(hr))
{
caps.id = str.GetRawBuffer(nullptr);
}
}
// Requires the Windows 10 Creators Update SDK (15063)
#if defined(NTDDI_WIN10_RS2) && (NTDDI_VERSION >= NTDDI_WIN10_RS2)
ComPtr<IRawGameControllerStatics> rawStatics;
hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_Gaming_Input_RawGameController).Get(), rawStatics.GetAddressOf());
if (SUCCEEDED(hr))
{
ComPtr<IRawGameController> raw;
hr = rawStatics->FromGameController(ctrl.Get(), raw.GetAddressOf());
if (SUCCEEDED(hr) && raw)
{
if (FAILED(raw->get_HardwareVendorId(&caps.vid)))
caps.vid = 0;
if (FAILED(raw->get_HardwareProductId(&caps.pid)))
caps.pid = 0;
}
}
#endif // NTDDI_WIN10_RS2
}
return;
}
@ -691,6 +713,8 @@ public:
{
caps.connected = true;
caps.gamepadType = Capabilities::UNKNOWN;
caps.id = 0;
caps.vid = caps.pid = 0;
ComPtr<IController> ctrl;
HRESULT hr = mGamePad[player].As(&ctrl);
@ -719,8 +743,19 @@ public:
}
}
}
else
caps.id = 0;
#if _XDK_VER >= 0x42ED07E4 /* XDK Edition 180400 */
ComPtr<IController3> ctrl3;
hr = mGamePad[player].As(&ctrl3);
if (SUCCEEDED(hr) && ctrl3)
{
if (FAILED(ctrl3->get_HardwareVendorId(&caps.vid)))
caps.vid = 0;
if (FAILED(ctrl3->get_HardwareProductId(&caps.pid)))
caps.pid = 0;
}
#endif
return;
}
@ -1034,6 +1069,14 @@ public:
caps.gamepadType = Capabilities::Type(xcaps.SubType);
}
// Hard-coded VID/PID
caps.vid = 0x045E;
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
caps.pid = (xcaps.Flags & XINPUT_CAPS_WIRELESS) ? 0x0719 : 0;
#else
caps.pid = 0;
#endif
return;
}
}
@ -1280,7 +1323,7 @@ void GamePad::Resume()
}
#if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/ ) || defined(_XBOX_ONE)
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN10) || defined(_XBOX_ONE)
void GamePad::RegisterEvents(HANDLE ctrlChanged, HANDLE userChanged)
{
pImpl->mCtrlChanged = (!ctrlChanged) ? INVALID_HANDLE_VALUE : ctrlChanged;

Просмотреть файл

@ -12,8 +12,6 @@
#include "PlatformHelpers.h"
#include "LinearAllocator.h"
#include <atomic>
using namespace DirectX;
using Microsoft::WRL::ComPtr;
using ScopedLock = std::lock_guard<std::mutex>;

Просмотреть файл

@ -446,7 +446,8 @@ HRESULT DirectX::SaveWICTextureToFile(
D3D12_RESOURCE_STATES beforeState,
D3D12_RESOURCE_STATES afterState,
const GUID* targetFormat,
std::function<void(IPropertyBag2*)> setCustomProps)
std::function<void(IPropertyBag2*)> setCustomProps,
bool forceSRGB)
{
if (!fileName)
return E_INVALIDARG;
@ -492,7 +493,7 @@ HRESULT DirectX::SaveWICTextureToFile(
// Determine source format's WIC equivalent
WICPixelFormatGUID pfGuid;
bool sRGB = false;
bool sRGB = forceSRGB;
switch (desc.Format)
{
case DXGI_FORMAT_R32G32B32A32_FLOAT: pfGuid = GUID_WICPixelFormat128bppRGBAFloat; break;

Просмотреть файл

@ -300,7 +300,7 @@ namespace
switch (xboxext->resourceDimension)
{
case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
case D3D12_RESOURCE_DIMENSION_TEXTURE1D:
if ((header->flags & DDS_HEIGHT) && height != 1)
{
return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
@ -308,8 +308,8 @@ namespace
height = depth = 1;
break;
case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
if (xboxext->miscFlag & D3D11_RESOURCE_MISC_TEXTURECUBE)
case D3D12_RESOURCE_DIMENSION_TEXTURE2D:
if (xboxext->miscFlag & 0x4 /* RESOURCE_MISC_TEXTURECUBE */)
{
arraySize *= 6;
isCubeMap = true;
@ -317,7 +317,7 @@ namespace
depth = 1;
break;
case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
case D3D12_RESOURCE_DIMENSION_TEXTURE3D:
if (!(header->flags & DDS_HEADER_FLAGS_VOLUME))
{
return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
@ -333,6 +333,11 @@ namespace
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}
if (xboxext->tileMode == uint32_t(-1))
{
return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
}
// Bound sizes
if (mipCount > D3D11_REQ_MIP_LEVELS)
{
@ -341,38 +346,38 @@ namespace
switch (xboxext->resourceDimension)
{
case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
if ((arraySize > D3D11_REQ_TEXTURE1D_ARRAY_AXIS_DIMENSION) ||
(width > D3D11_REQ_TEXTURE1D_U_DIMENSION))
case D3D12_RESOURCE_DIMENSION_TEXTURE1D:
if ((arraySize > D3D12_REQ_TEXTURE1D_ARRAY_AXIS_DIMENSION) ||
(width > D3D12_REQ_TEXTURE1D_U_DIMENSION))
{
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}
break;
case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
case D3D12_RESOURCE_DIMENSION_TEXTURE2D:
if (isCubeMap)
{
// This is the right bound because we set arraySize to (NumCubes*6) above
if ((arraySize > D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION) ||
(width > D3D11_REQ_TEXTURECUBE_DIMENSION) ||
(height > D3D11_REQ_TEXTURECUBE_DIMENSION))
if ((arraySize > D3D12_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION) ||
(width > D3D12_REQ_TEXTURECUBE_DIMENSION) ||
(height > D3D12_REQ_TEXTURECUBE_DIMENSION))
{
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}
}
else if ((arraySize > D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION) ||
(width > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION) ||
(height > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION))
else if ((arraySize > D3D12_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION) ||
(width > D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION) ||
(height > D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION))
{
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}
break;
case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
case D3D12_RESOURCE_DIMENSION_TEXTURE3D:
if ((arraySize > 1) ||
(width > D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION) ||
(height > D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION) ||
(depth > D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION))
(width > D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION) ||
(height > D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION) ||
(depth > D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION))
{
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}

Просмотреть файл

@ -130,6 +130,7 @@
#include <DirectXCollision.h>
#include <algorithm>
#include <atomic>
#include <array>
#include <exception>
#include <future>

Просмотреть файл

@ -3235,7 +3235,10 @@ void D3DX_BC7::EmitBlock(const EncodeParams* pEP, size_t uShape, size_t uRotatio
_Use_decl_annotations_
void D3DX_BC7::FixEndpointPBits(const EncodeParams* pEP, const LDREndPntPair *pOrigEndpoints, LDREndPntPair *pFixedEndpoints)
{
assert(pEP);
const size_t uPartitions = ms_aInfo[pEP->uMode].uPartitions;
assert(uPartitions < BC7_MAX_REGIONS);
_Analysis_assume_(uPartitions < BC7_MAX_REGIONS);
pFixedEndpoints[0] = pOrigEndpoints[0];
pFixedEndpoints[1] = pOrigEndpoints[1];

Просмотреть файл

@ -382,8 +382,8 @@ namespace DirectX
_In_z_ const wchar_t* szFile,
_Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image);
HRESULT __cdecl SaveToTGAMemory(_In_ const Image& image, _Out_ Blob& blob);
HRESULT __cdecl SaveToTGAFile(_In_ const Image& image, _In_z_ const wchar_t* szFile);
HRESULT __cdecl SaveToTGAMemory(_In_ const Image& image, _Out_ Blob& blob, _In_opt_ const TexMetadata* metadata = nullptr);
HRESULT __cdecl SaveToTGAFile(_In_ const Image& image, _In_z_ const wchar_t* szFile, _In_opt_ const TexMetadata* metadata = nullptr);
// WIC operations
HRESULT __cdecl LoadFromWICMemory(

Просмотреть файл

@ -70,6 +70,9 @@ namespace
{ DXGI_FORMAT_BC4_UNORM, CONV_FLAGS_NONE, { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('A', 'T', 'I', '1'), 0, 0, 0, 0, 0 } },
{ DXGI_FORMAT_BC5_UNORM, CONV_FLAGS_NONE, { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('A', 'T', 'I', '2'), 0, 0, 0, 0, 0 } },
{ DXGI_FORMAT_BC6H_UF16, CONV_FLAGS_NONE, { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B', 'C', '6', 'H'), 0, 0, 0, 0, 0 } },
{ DXGI_FORMAT_BC7_UNORM, CONV_FLAGS_NONE, { sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B', 'C', '7', 'L'), 0, 0, 0, 0, 0 } },
{ DXGI_FORMAT_R8G8_B8G8_UNORM, CONV_FLAGS_NONE, DDSPF_R8G8_B8G8 }, // D3DFMT_R8G8_B8G8
{ DXGI_FORMAT_G8R8_G8B8_UNORM, CONV_FLAGS_NONE, DDSPF_G8R8_G8B8 }, // D3DFMT_G8R8_G8B8
@ -424,9 +427,6 @@ namespace
if (metadata.format == DXGI_FORMAT_UNKNOWN)
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
if (convFlags & CONV_FLAGS_PMALPHA)
metadata.miscFlags2 |= TEX_ALPHA_MODE_PREMULTIPLIED;
// Special flag for handling LUMINANCE legacy formats
if (flags & DDS_FLAGS_EXPAND_LUMINANCE)
{
@ -512,6 +512,16 @@ namespace
}
}
// Implicit alpha mode
if (convFlags & CONV_FLAGS_NOALPHA)
{
metadata.SetAlphaMode(TEX_ALPHA_MODE_OPAQUE);
}
else if (convFlags & CONV_FLAGS_PMALPHA)
{
metadata.SetAlphaMode(TEX_ALPHA_MODE_PREMULTIPLIED);
}
return S_OK;
}
}

Просмотреть файл

@ -282,6 +282,7 @@ namespace
metadata.depth = metadata.arraySize = metadata.mipLevels = 1;
metadata.format = DXGI_FORMAT_R32G32B32A32_FLOAT;
metadata.dimension = TEX_DIMENSION_TEXTURE2D;
metadata.SetAlphaMode(TEX_ALPHA_MODE_OPAQUE);
return S_OK;
}

Просмотреть файл

@ -23,6 +23,9 @@ using namespace DirectX;
namespace
{
const char g_Signature[] = "TRUEVISION-XFILE.";
// This is the official footer signature for the TGA 2.0 file format.
enum TGAImageType
{
TGA_NO_IMAGE = 0,
@ -42,6 +45,15 @@ namespace
TGA_FLAGS_INTERLEAVED_4WAY = 0x80, // Deprecated
};
enum TGAAttributesType : uint8_t
{
TGA_ATTRIBUTE_NONE = 0, // 0: no alpha data included
TGA_ATTRIBUTE_IGNORED = 1, // 1: undefined data, can be ignored
TGA_ATTRIBUTE_UNDEFINED = 2, // 2: uedefined data, should be retained
TGA_ATTRIBUTE_ALPHA = 3, // 3: useful alpha channel data
TGA_ATTRIBUTE_PREMULTIPLIED = 4, // 4: pre-multiplied alpha
};
#pragma pack(push,1)
struct TGA_HEADER
{
@ -59,13 +71,17 @@ namespace
uint8_t bDescriptor;
};
static_assert(sizeof(TGA_HEADER) == 18, "TGA 2.0 size mismatch");
struct TGA_FOOTER
{
uint16_t dwExtensionOffset;
uint16_t dwDeveloperOffset;
uint32_t dwExtensionOffset;
uint32_t dwDeveloperOffset;
char Signature[18];
};
static_assert(sizeof(TGA_FOOTER) == 26, "TGA 2.0 size mismatch");
struct TGA_EXTENSION
{
uint16_t wSize;
@ -94,6 +110,9 @@ namespace
uint32_t dwScanOffset;
uint8_t bAttributesType;
};
static_assert(sizeof(TGA_EXTENSION) == 495, "TGA 2.0 size mismatch");
#pragma pack(pop)
enum CONVERSION_FLAGS
@ -159,6 +178,7 @@ namespace
case 24:
metadata.format = DXGI_FORMAT_R8G8B8A8_UNORM;
metadata.SetAlphaMode(TEX_ALPHA_MODE_OPAQUE);
if (convFlags)
*convFlags |= CONV_FLAGS_EXPAND;
// We could use DXGI_FORMAT_B8G8R8X8_UNORM, but we prefer DXGI 1.0 formats
@ -280,6 +300,8 @@ namespace
auto sPtr = static_cast<const uint8_t*>(pSource);
const uint8_t* endPtr = sPtr + size;
bool opaquealpha = false;
switch (image->format)
{
//--------------------------------------------------------------------------- 8-bit
@ -349,7 +371,9 @@ namespace
//-------------------------------------------------------------------------- 16-bit
case DXGI_FORMAT_B5G5R5A1_UNORM:
{
bool nonzeroa = false;
uint32_t minalpha = 255;
uint32_t maxalpha = 0;
for (size_t y = 0; y < image->height; ++y)
{
size_t offset = ((convFlags & CONV_FLAGS_INVERTX) ? (image->width - 1) : 0);
@ -374,8 +398,11 @@ namespace
return E_FAIL;
auto t = static_cast<uint16_t>(uint32_t(*sPtr) | uint32_t(*(sPtr + 1u) << 8));
if (t & 0x8000)
nonzeroa = true;
uint32_t alpha = (t & 0x8000) ? 255 : 0;
minalpha = std::min(minalpha, alpha);
maxalpha = std::max(maxalpha, alpha);
sPtr += 2;
for (; j > 0; --j, ++x)
@ -406,8 +433,11 @@ namespace
return E_FAIL;
auto t = static_cast<uint16_t>(uint32_t(*sPtr) | uint32_t(*(sPtr + 1u) << 8));
if (t & 0x8000)
nonzeroa = true;
uint32_t alpha = (t & 0x8000) ? 255 : 0;
minalpha = std::min(minalpha, alpha);
maxalpha = std::max(maxalpha, alpha);
sPtr += 2;
*dPtr = t;
@ -421,19 +451,26 @@ namespace
}
// If there are no non-zero alpha channel entries, we'll assume alpha is not used and force it to opaque
if (!nonzeroa)
if (maxalpha == 0)
{
opaquealpha = true;
HRESULT hr = SetAlphaChannelToOpaque(image);
if (FAILED(hr))
return hr;
}
else if (minalpha == 255)
{
opaquealpha = true;
}
}
break;
//----------------------------------------------------------------------- 24/32-bit
case DXGI_FORMAT_R8G8B8A8_UNORM:
{
bool nonzeroa = false;
uint32_t minalpha = 255;
uint32_t maxalpha = 0;
for (size_t y = 0; y < image->height; ++y)
{
size_t offset = ((convFlags & CONV_FLAGS_INVERTX) ? (image->width - 1) : 0);
@ -465,7 +502,7 @@ namespace
t = uint32_t(*sPtr << 16) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2)) | 0xFF000000;
sPtr += 3;
nonzeroa = true;
minalpha = maxalpha = 255;
}
else
{
@ -475,10 +512,11 @@ namespace
return E_FAIL;
// BGRA -> RGBA
t = uint32_t(*sPtr << 16) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2)) | uint32_t(*(sPtr + 3) << 24);
uint32_t alpha = *(sPtr + 3);
t = uint32_t(*sPtr << 16) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2)) | uint32_t(alpha << 24);
if (*(sPtr + 3) > 0)
nonzeroa = true;
minalpha = std::min(minalpha, alpha);
maxalpha = std::max(maxalpha, alpha);
sPtr += 4;
}
@ -529,7 +567,7 @@ namespace
*dPtr = uint32_t(*sPtr << 16) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2)) | 0xFF000000;
sPtr += 3;
nonzeroa = true;
minalpha = maxalpha = 255;
}
else
{
@ -539,10 +577,11 @@ namespace
return E_FAIL;
// BGRA -> RGBA
*dPtr = uint32_t(*sPtr << 16) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2)) | uint32_t(*(sPtr + 3) << 24);
uint32_t alpha = *(sPtr + 3);
*dPtr = uint32_t(*sPtr << 16) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2)) | uint32_t(alpha << 24);
if (*(sPtr + 3) > 0)
nonzeroa = true;
minalpha = std::min(minalpha, alpha);
maxalpha = std::max(maxalpha, alpha);
sPtr += 4;
}
@ -557,12 +596,17 @@ namespace
}
// If there are no non-zero alpha channel entries, we'll assume alpha is not used and force it to opaque
if (!nonzeroa)
if (maxalpha == 0)
{
opaquealpha = true;
HRESULT hr = SetAlphaChannelToOpaque(image);
if (FAILED(hr))
return hr;
}
else if (minalpha == 255)
{
opaquealpha = true;
}
}
break;
@ -571,7 +615,7 @@ namespace
return E_FAIL;
}
return S_OK;
return opaquealpha ? S_FALSE : S_OK;
}
@ -606,6 +650,8 @@ namespace
auto sPtr = static_cast<const uint8_t*>(pSource);
const uint8_t* endPtr = sPtr + size;
bool opaquealpha = false;
switch (image->format)
{
//--------------------------------------------------------------------------- 8-bit
@ -637,7 +683,9 @@ namespace
//-------------------------------------------------------------------------- 16-bit
case DXGI_FORMAT_B5G5R5A1_UNORM:
{
bool nonzeroa = false;
uint32_t minalpha = 255;
uint32_t maxalpha = 0;
for (size_t y = 0; y < image->height; ++y)
{
size_t offset = ((convFlags & CONV_FLAGS_INVERTX) ? (image->width - 1) : 0);
@ -656,8 +704,9 @@ namespace
sPtr += 2;
*dPtr = t;
if (t & 0x8000)
nonzeroa = true;
uint32_t alpha = (t & 0x8000) ? 255 : 0;
minalpha = std::min(minalpha, alpha);
maxalpha = std::max(maxalpha, alpha);
if (convFlags & CONV_FLAGS_INVERTX)
--dPtr;
@ -667,19 +716,26 @@ namespace
}
// If there are no non-zero alpha channel entries, we'll assume alpha is not used and force it to opaque
if (!nonzeroa)
if (maxalpha == 0)
{
opaquealpha = true;
HRESULT hr = SetAlphaChannelToOpaque(image);
if (FAILED(hr))
return hr;
}
else if (minalpha == 255)
{
opaquealpha = true;
}
}
break;
//----------------------------------------------------------------------- 24/32-bit
case DXGI_FORMAT_R8G8B8A8_UNORM:
{
bool nonzeroa = false;
uint32_t minalpha = 255;
uint32_t maxalpha = 0;
for (size_t y = 0; y < image->height; ++y)
{
size_t offset = ((convFlags & CONV_FLAGS_INVERTX) ? (image->width - 1) : 0);
@ -701,7 +757,7 @@ namespace
*dPtr = uint32_t(*sPtr << 16) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2)) | 0xFF000000;
sPtr += 3;
nonzeroa = true;
minalpha = maxalpha = 255;
}
else
{
@ -711,10 +767,11 @@ namespace
return E_FAIL;
// BGRA -> RGBA
*dPtr = uint32_t(*sPtr << 16) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2)) | uint32_t(*(sPtr + 3) << 24);
uint32_t alpha = *(sPtr + 3);
*dPtr = uint32_t(*sPtr << 16) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2)) | uint32_t(alpha << 24);
if (*(sPtr + 3) > 0)
nonzeroa = true;
minalpha = std::min(minalpha, alpha);
maxalpha = std::max(maxalpha, alpha);
sPtr += 4;
}
@ -727,12 +784,17 @@ namespace
}
// If there are no non-zero alpha channel entries, we'll assume alpha is not used and force it to opaque
if (!nonzeroa)
if (maxalpha == 0)
{
opaquealpha = true;
HRESULT hr = SetAlphaChannelToOpaque(image);
if (FAILED(hr))
return hr;
}
else if (minalpha == 255)
{
opaquealpha = true;
}
}
break;
@ -741,7 +803,7 @@ namespace
return E_FAIL;
}
return S_OK;
return opaquealpha ? S_FALSE : S_OK;
}
@ -842,6 +904,82 @@ namespace
}
}
}
//-------------------------------------------------------------------------------------
// TGA 2.0 Extension helpers
//-------------------------------------------------------------------------------------
void SetExtension(TGA_EXTENSION *ext, const TexMetadata& metadata)
{
memset(ext, 0, sizeof(TGA_EXTENSION));
ext->wSize = sizeof(TGA_EXTENSION);
memcpy(ext->szSoftwareId, "DirectXTex", sizeof("DirectXTex"));
ext->wVersionNumber = DIRECTX_TEX_VERSION;
ext->bVersionLetter = ' ';
if (IsSRGB(metadata.format))
{
ext->wGammaNumerator = 22;
ext->wGammaDenominator = 10;
}
switch (metadata.GetAlphaMode())
{
case TEX_ALPHA_MODE_UNKNOWN:
ext->bAttributesType = HasAlpha(metadata.format) ? TGA_ATTRIBUTE_UNDEFINED : TGA_ATTRIBUTE_NONE;
break;
case TEX_ALPHA_MODE_STRAIGHT:
ext->bAttributesType = TGA_ATTRIBUTE_ALPHA;
break;
case TEX_ALPHA_MODE_PREMULTIPLIED:
ext->bAttributesType = TGA_ATTRIBUTE_PREMULTIPLIED;
break;
case TEX_ALPHA_MODE_OPAQUE:
ext->bAttributesType = TGA_ATTRIBUTE_IGNORED;
break;
case TEX_ALPHA_MODE_CUSTOM:
ext->bAttributesType = TGA_ATTRIBUTE_UNDEFINED;
break;
}
// Set file time stamp
{
time_t now = {};
time(&now);
tm info;
if (!gmtime_s(&info, &now))
{
ext->wStampMonth = static_cast<uint16_t>(info.tm_mon + 1);
ext->wStampDay = static_cast<uint16_t>(info.tm_mday);
ext->wStampYear = static_cast<uint16_t>(info.tm_year + 1900);
ext->wStampHour = static_cast<uint16_t>(info.tm_hour);
ext->wStampMinute = static_cast<uint16_t>(info.tm_min);
ext->wStampSecond = static_cast<uint16_t>(info.tm_sec);
}
}
}
TEX_ALPHA_MODE GetAlphaModeFromExtension(const TGA_EXTENSION *ext)
{
if (ext && ext->wSize == sizeof(TGA_EXTENSION))
{
switch (ext->bAttributesType)
{
case TGA_ATTRIBUTE_IGNORED: return TEX_ALPHA_MODE_OPAQUE;
case TGA_ATTRIBUTE_UNDEFINED: return TEX_ALPHA_MODE_CUSTOM;
case TGA_ATTRIBUTE_ALPHA: return TEX_ALPHA_MODE_STRAIGHT;
case TGA_ATTRIBUTE_PREMULTIPLIED: return TEX_ALPHA_MODE_PREMULTIPLIED;
}
}
return TEX_ALPHA_MODE_UNKNOWN;
}
}
@ -965,7 +1103,28 @@ HRESULT DirectX::LoadFromTGAMemory(
}
if (metadata)
{
memcpy(metadata, &mdata, sizeof(TexMetadata));
if (hr == S_FALSE)
{
metadata->SetAlphaMode(TEX_ALPHA_MODE_OPAQUE);
}
else if (size >= sizeof(TGA_FOOTER))
{
// Handle optional TGA 2.0 footer
auto footer = reinterpret_cast<const TGA_FOOTER*>(static_cast<const uint8_t*>(pSource) + size - sizeof(TGA_FOOTER));
if (memcmp(footer->Signature, g_Signature, sizeof(g_Signature)) == 0)
{
if (footer->dwExtensionOffset != 0
&& ((footer->dwExtensionOffset + sizeof(TGA_EXTENSION)) <= size))
{
auto ext = reinterpret_cast<const TGA_EXTENSION*>(static_cast<const uint8_t*>(pSource) + footer->dwExtensionOffset);
metadata->SetAlphaMode(GetAlphaModeFromExtension(ext));
}
}
}
}
return S_OK;
}
@ -1051,6 +1210,8 @@ HRESULT DirectX::LoadFromTGAFile(
assert(image.GetPixels());
bool opaquealpha = false;
if (!(convFlags & (CONV_FLAGS_RLE | CONV_FLAGS_EXPAND | CONV_FLAGS_INVERTX)) && (convFlags & CONV_FLAGS_INVERTY))
{
// This case we can read directly into the image buffer in place
@ -1101,7 +1262,8 @@ HRESULT DirectX::LoadFromTGAFile(
size_t rowPitch = img->rowPitch;
// Scan for non-zero alpha channel
bool nonzeroa = false;
uint32_t minalpha = 255;
uint32_t maxalpha = 0;
for (size_t h = 0; h < img->height; ++h)
{
@ -1109,22 +1271,27 @@ HRESULT DirectX::LoadFromTGAFile(
for (size_t x = 0; x < img->width; ++x)
{
if ((*sPtr) & 0xff000000)
{
nonzeroa = true;
break;
}
uint32_t alpha = ((*sPtr & 0xFF000000) >> 24);
minalpha = std::min(minalpha, alpha);
maxalpha = std::max(maxalpha, alpha);
++sPtr;
}
if (nonzeroa)
break;
pPixels += rowPitch;
}
DWORD tflags = (!nonzeroa) ? TEXP_SCANLINE_SETALPHA : TEXP_SCANLINE_NONE;
DWORD tflags = TEXP_SCANLINE_NONE;
if (maxalpha == 0)
{
opaquealpha = true;
tflags = TEXP_SCANLINE_SETALPHA;
}
else if (minalpha == 255)
{
opaquealpha = true;
}
// Swizzle scanlines
pPixels = img->pixels;
@ -1150,7 +1317,8 @@ HRESULT DirectX::LoadFromTGAFile(
}
// Scan for non-zero alpha channel
bool nonzeroa = false;
uint32_t minalpha = 255;
uint32_t maxalpha = 0;
const uint8_t *pPixels = img->pixels;
if (!pPixels)
@ -1167,24 +1335,21 @@ HRESULT DirectX::LoadFromTGAFile(
for (size_t x = 0; x < img->width; ++x)
{
if (*sPtr & 0x8000)
{
nonzeroa = true;
break;
}
uint32_t alpha = (*sPtr & 0x8000) ? 255 : 0;
minalpha = std::min(minalpha, alpha);
maxalpha = std::max(maxalpha, alpha);
++sPtr;
}
if (nonzeroa)
break;
pPixels += rowPitch;
}
// If there are no non-zero alpha channel entries, we'll assume alpha is not used and force it to opaque
if (!nonzeroa)
if (maxalpha == 0)
{
opaquealpha = true;
hr = SetAlphaChannelToOpaque(img);
if (FAILED(hr))
{
@ -1192,6 +1357,10 @@ HRESULT DirectX::LoadFromTGAFile(
return hr;
}
}
else if (minalpha == 255)
{
opaquealpha = true;
}
}
break;
@ -1234,10 +1403,59 @@ HRESULT DirectX::LoadFromTGAFile(
image.Release();
return hr;
}
if (hr == S_FALSE)
opaquealpha = true;
}
if (metadata)
{
memcpy(metadata, &mdata, sizeof(TexMetadata));
if (opaquealpha)
{
metadata->SetAlphaMode(TEX_ALPHA_MODE_OPAQUE);
}
else
{
// Handle optional TGA 2.0 footer
TGA_FOOTER footer = {};
if (SetFilePointer(hFile.get(), -static_cast<int>(sizeof(TGA_FOOTER)), nullptr, FILE_END) == INVALID_SET_FILE_POINTER)
{
return HRESULT_FROM_WIN32(GetLastError());
}
if (!ReadFile(hFile.get(), &footer, sizeof(TGA_FOOTER), &bytesRead, nullptr))
{
image.Release();
return HRESULT_FROM_WIN32(GetLastError());
}
if (bytesRead != sizeof(TGA_FOOTER))
{
image.Release();
return E_FAIL;
}
if (memcmp(footer.Signature, g_Signature, sizeof(g_Signature)) == 0)
{
if (footer.dwExtensionOffset != 0
&& ((footer.dwExtensionOffset + sizeof(TGA_EXTENSION)) <= fileInfo.EndOfFile.LowPart))
{
LARGE_INTEGER filePos = { { static_cast<DWORD>(footer.dwExtensionOffset), 0 } };
if (SetFilePointerEx(hFile.get(), filePos, nullptr, FILE_BEGIN))
{
TGA_EXTENSION ext = {};
if (ReadFile(hFile.get(), &ext, sizeof(TGA_EXTENSION), &bytesRead, nullptr)
&& bytesRead == sizeof(TGA_EXTENSION))
{
metadata->SetAlphaMode(GetAlphaModeFromExtension(&ext));
}
}
}
}
}
}
return S_OK;
}
@ -1247,7 +1465,7 @@ HRESULT DirectX::LoadFromTGAFile(
// Save a TGA file to memory
//-------------------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT DirectX::SaveToTGAMemory(const Image& image, Blob& blob)
HRESULT DirectX::SaveToTGAMemory(const Image& image, Blob& blob, const TexMetadata* metadata)
{
if (!image.pixels)
return E_POINTER;
@ -1274,13 +1492,18 @@ HRESULT DirectX::SaveToTGAMemory(const Image& image, Blob& blob)
return hr;
}
hr = blob.Initialize(sizeof(TGA_HEADER) + slicePitch);
hr = blob.Initialize(sizeof(TGA_HEADER)
+ slicePitch
+ (metadata ? sizeof(TGA_EXTENSION) : 0)
+ sizeof(TGA_FOOTER));
if (FAILED(hr))
return hr;
// Copy header
auto dPtr = static_cast<uint8_t*>(blob.GetBufferPointer());
assert(dPtr != nullptr);
auto destPtr = static_cast<uint8_t*>(blob.GetBufferPointer());
assert(destPtr != nullptr);
uint8_t* dPtr = destPtr;
memcpy_s(dPtr, blob.GetBufferSize(), &tga_header, sizeof(TGA_HEADER));
dPtr += sizeof(TGA_HEADER);
@ -1307,6 +1530,24 @@ HRESULT DirectX::SaveToTGAMemory(const Image& image, Blob& blob)
pPixels += image.rowPitch;
}
uint32_t extOffset = 0;
if (metadata)
{
// metadata is only used for writing the TGA 2.0 extension header
auto ext = reinterpret_cast<TGA_EXTENSION*>(dPtr);
SetExtension(ext, *metadata);
extOffset = static_cast<uint32_t>(dPtr - destPtr);
dPtr += sizeof(TGA_EXTENSION);
}
// Copy TGA 2.0 footer
auto footer = reinterpret_cast<TGA_FOOTER*>(dPtr);
footer->dwDeveloperOffset = 0;
footer->dwExtensionOffset = extOffset;
memcpy(footer->Signature, g_Signature, sizeof(g_Signature));
return S_OK;
}
@ -1315,7 +1556,7 @@ HRESULT DirectX::SaveToTGAMemory(const Image& image, Blob& blob)
// Save a TGA file to disk
//-------------------------------------------------------------------------------------
_Use_decl_annotations_
HRESULT DirectX::SaveToTGAFile(const Image& image, const wchar_t* szFile)
HRESULT DirectX::SaveToTGAFile(const Image& image, const wchar_t* szFile, const TexMetadata* metadata)
{
if (!szFile)
return E_INVALIDARG;
@ -1438,6 +1679,41 @@ HRESULT DirectX::SaveToTGAFile(const Image& image, const wchar_t* szFile)
if (bytesWritten != rowPitch)
return E_FAIL;
}
uint32_t extOffset = 0;
if (metadata)
{
// metadata is only used for writing the TGA 2.0 extension header
TGA_EXTENSION ext = {};
SetExtension(&ext, *metadata);
extOffset = SetFilePointer(hFile.get(), 0, nullptr, FILE_CURRENT);
if (extOffset == INVALID_SET_FILE_POINTER)
{
return HRESULT_FROM_WIN32(GetLastError());
}
if (!WriteFile(hFile.get(), &ext, sizeof(TGA_EXTENSION), &bytesWritten, nullptr))
{
return HRESULT_FROM_WIN32(GetLastError());
}
if (bytesWritten != sizeof(TGA_EXTENSION))
return E_FAIL;
}
// Write TGA 2.0 footer
TGA_FOOTER footer = {};
footer.dwExtensionOffset = extOffset;
memcpy(footer.Signature, g_Signature, sizeof(g_Signature));
if (!WriteFile(hFile.get(), &footer, sizeof(footer), &bytesWritten, nullptr))
{
return HRESULT_FROM_WIN32(GetLastError());
}
if (bytesWritten != sizeof(footer))
return E_FAIL;
}
delonfail.clear();

Просмотреть файл

@ -79,8 +79,9 @@ namespace
struct WICConvert
{
GUID source;
GUID target;
GUID source;
GUID target;
TEX_ALPHA_MODE alphaMode;
};
const WICConvert g_WICConvert[] =
@ -88,54 +89,54 @@ namespace
// Directly support the formats listed in XnaTexUtil::g_WICFormats, so no conversion required
// Note target GUID in this conversion table must be one of those directly supported formats.
{ GUID_WICPixelFormat1bppIndexed, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat2bppIndexed, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat4bppIndexed, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat8bppIndexed, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat1bppIndexed, GUID_WICPixelFormat32bppRGBA, TEX_ALPHA_MODE_UNKNOWN }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat2bppIndexed, GUID_WICPixelFormat32bppRGBA, TEX_ALPHA_MODE_UNKNOWN }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat4bppIndexed, GUID_WICPixelFormat32bppRGBA, TEX_ALPHA_MODE_UNKNOWN }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat8bppIndexed, GUID_WICPixelFormat32bppRGBA, TEX_ALPHA_MODE_UNKNOWN }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat2bppGray, GUID_WICPixelFormat8bppGray }, // DXGI_FORMAT_R8_UNORM
{ GUID_WICPixelFormat4bppGray, GUID_WICPixelFormat8bppGray }, // DXGI_FORMAT_R8_UNORM
{ GUID_WICPixelFormat2bppGray, GUID_WICPixelFormat8bppGray, TEX_ALPHA_MODE_UNKNOWN }, // DXGI_FORMAT_R8_UNORM
{ GUID_WICPixelFormat4bppGray, GUID_WICPixelFormat8bppGray, TEX_ALPHA_MODE_UNKNOWN }, // DXGI_FORMAT_R8_UNORM
{ GUID_WICPixelFormat16bppGrayFixedPoint, GUID_WICPixelFormat16bppGrayHalf }, // DXGI_FORMAT_R16_FLOAT
{ GUID_WICPixelFormat32bppGrayFixedPoint, GUID_WICPixelFormat32bppGrayFloat }, // DXGI_FORMAT_R32_FLOAT
{ GUID_WICPixelFormat16bppGrayFixedPoint, GUID_WICPixelFormat16bppGrayHalf, TEX_ALPHA_MODE_UNKNOWN }, // DXGI_FORMAT_R16_FLOAT
{ GUID_WICPixelFormat32bppGrayFixedPoint, GUID_WICPixelFormat32bppGrayFloat, TEX_ALPHA_MODE_UNKNOWN }, // DXGI_FORMAT_R32_FLOAT
{ GUID_WICPixelFormat16bppBGR555, GUID_WICPixelFormat16bppBGRA5551 }, // DXGI_FORMAT_B5G5R5A1_UNORM
{ GUID_WICPixelFormat32bppBGR101010, GUID_WICPixelFormat32bppRGBA1010102 }, // DXGI_FORMAT_R10G10B10A2_UNORM
{ GUID_WICPixelFormat16bppBGR555, GUID_WICPixelFormat16bppBGRA5551, TEX_ALPHA_MODE_OPAQUE }, // DXGI_FORMAT_B5G5R5A1_UNORM
{ GUID_WICPixelFormat32bppBGR101010, GUID_WICPixelFormat32bppRGBA1010102, TEX_ALPHA_MODE_OPAQUE }, // DXGI_FORMAT_R10G10B10A2_UNORM
{ GUID_WICPixelFormat24bppBGR, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat24bppRGB, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat32bppPBGRA, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat32bppPRGBA, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat24bppBGR, GUID_WICPixelFormat32bppRGBA, TEX_ALPHA_MODE_OPAQUE }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat24bppRGB, GUID_WICPixelFormat32bppRGBA, TEX_ALPHA_MODE_OPAQUE }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat32bppPBGRA, GUID_WICPixelFormat32bppRGBA, TEX_ALPHA_MODE_UNKNOWN }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat32bppPRGBA, GUID_WICPixelFormat32bppRGBA, TEX_ALPHA_MODE_UNKNOWN }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat48bppRGB, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat48bppBGR, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat64bppBGRA, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat64bppPRGBA, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat64bppPBGRA, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat48bppRGB, GUID_WICPixelFormat64bppRGBA, TEX_ALPHA_MODE_OPAQUE }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat48bppBGR, GUID_WICPixelFormat64bppRGBA, TEX_ALPHA_MODE_OPAQUE }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat64bppBGRA, GUID_WICPixelFormat64bppRGBA, TEX_ALPHA_MODE_UNKNOWN }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat64bppPRGBA, GUID_WICPixelFormat64bppRGBA, TEX_ALPHA_MODE_UNKNOWN }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat64bppPBGRA, GUID_WICPixelFormat64bppRGBA, TEX_ALPHA_MODE_UNKNOWN }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat48bppRGBFixedPoint, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat48bppBGRFixedPoint, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat64bppRGBAFixedPoint, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat64bppBGRAFixedPoint, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat64bppRGBFixedPoint, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat64bppRGBHalf, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat48bppRGBHalf, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat48bppRGBFixedPoint, GUID_WICPixelFormat64bppRGBAHalf, TEX_ALPHA_MODE_OPAQUE }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat48bppBGRFixedPoint, GUID_WICPixelFormat64bppRGBAHalf, TEX_ALPHA_MODE_OPAQUE }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat64bppRGBAFixedPoint, GUID_WICPixelFormat64bppRGBAHalf, TEX_ALPHA_MODE_UNKNOWN }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat64bppBGRAFixedPoint, GUID_WICPixelFormat64bppRGBAHalf, TEX_ALPHA_MODE_UNKNOWN }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat64bppRGBFixedPoint, GUID_WICPixelFormat64bppRGBAHalf, TEX_ALPHA_MODE_OPAQUE }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat64bppRGBHalf, GUID_WICPixelFormat64bppRGBAHalf, TEX_ALPHA_MODE_OPAQUE }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat48bppRGBHalf, GUID_WICPixelFormat64bppRGBAHalf, TEX_ALPHA_MODE_OPAQUE }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat128bppPRGBAFloat, GUID_WICPixelFormat128bppRGBAFloat }, // DXGI_FORMAT_R32G32B32A32_FLOAT
{ GUID_WICPixelFormat128bppRGBFloat, GUID_WICPixelFormat128bppRGBAFloat }, // DXGI_FORMAT_R32G32B32A32_FLOAT
{ GUID_WICPixelFormat128bppRGBAFixedPoint, GUID_WICPixelFormat128bppRGBAFloat }, // DXGI_FORMAT_R32G32B32A32_FLOAT
{ GUID_WICPixelFormat128bppRGBFixedPoint, GUID_WICPixelFormat128bppRGBAFloat }, // DXGI_FORMAT_R32G32B32A32_FLOAT
{ GUID_WICPixelFormat32bppRGBE, GUID_WICPixelFormat128bppRGBAFloat }, // DXGI_FORMAT_R32G32B32A32_FLOAT
{ GUID_WICPixelFormat128bppPRGBAFloat, GUID_WICPixelFormat128bppRGBAFloat, TEX_ALPHA_MODE_UNKNOWN }, // DXGI_FORMAT_R32G32B32A32_FLOAT
{ GUID_WICPixelFormat128bppRGBFloat, GUID_WICPixelFormat128bppRGBAFloat, TEX_ALPHA_MODE_OPAQUE }, // DXGI_FORMAT_R32G32B32A32_FLOAT
{ GUID_WICPixelFormat128bppRGBAFixedPoint, GUID_WICPixelFormat128bppRGBAFloat, TEX_ALPHA_MODE_UNKNOWN }, // DXGI_FORMAT_R32G32B32A32_FLOAT
{ GUID_WICPixelFormat128bppRGBFixedPoint, GUID_WICPixelFormat128bppRGBAFloat, TEX_ALPHA_MODE_OPAQUE }, // DXGI_FORMAT_R32G32B32A32_FLOAT
{ GUID_WICPixelFormat32bppRGBE, GUID_WICPixelFormat128bppRGBAFloat, TEX_ALPHA_MODE_OPAQUE }, // DXGI_FORMAT_R32G32B32A32_FLOAT
{ GUID_WICPixelFormat32bppCMYK, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat64bppCMYK, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat40bppCMYKAlpha, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat80bppCMYKAlpha, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat32bppCMYK, GUID_WICPixelFormat32bppRGBA, TEX_ALPHA_MODE_OPAQUE }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat64bppCMYK, GUID_WICPixelFormat64bppRGBA, TEX_ALPHA_MODE_OPAQUE }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat40bppCMYKAlpha, GUID_WICPixelFormat32bppRGBA, TEX_ALPHA_MODE_UNKNOWN }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat80bppCMYKAlpha, GUID_WICPixelFormat64bppRGBA, TEX_ALPHA_MODE_UNKNOWN }, // DXGI_FORMAT_R16G16B16A16_UNORM
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
{ GUID_WICPixelFormat32bppRGB, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat64bppRGB, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat64bppPRGBAHalf, GUID_WICPixelFormat64bppRGBAHalf }, // DXGI_FORMAT_R16G16B16A16_FLOAT
{ GUID_WICPixelFormat32bppRGB, GUID_WICPixelFormat32bppRGBA, TEX_ALPHA_MODE_OPAQUE }, // DXGI_FORMAT_R8G8B8A8_UNORM
{ GUID_WICPixelFormat64bppRGB, GUID_WICPixelFormat64bppRGBA, TEX_ALPHA_MODE_OPAQUE }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat64bppPRGBAHalf, GUID_WICPixelFormat64bppRGBAHalf, TEX_ALPHA_MODE_UNKNOWN }, // DXGI_FORMAT_R16G16B16A16_FLOAT
#endif
// We don't support n-channel formats
@ -148,11 +149,14 @@ namespace
_In_ const WICPixelFormatGUID& pixelFormat,
DWORD flags,
bool iswic2,
_Out_opt_ WICPixelFormatGUID* pConvert)
_Out_opt_ WICPixelFormatGUID* pConvert,
_Out_ TEX_ALPHA_MODE* alphaMode)
{
if (pConvert)
memset(pConvert, 0, sizeof(WICPixelFormatGUID));
*alphaMode = TEX_ALPHA_MODE_UNKNOWN;
DXGI_FORMAT format = _WICToDXGI(pixelFormat);
if (format == DXGI_FORMAT_UNKNOWN)
@ -174,6 +178,7 @@ namespace
if (pConvert)
memcpy_s(pConvert, sizeof(WICPixelFormatGUID), &GUID_WICPixelFormat128bppRGBAFloat, sizeof(GUID));
format = DXGI_FORMAT_R32G32B32A32_FLOAT;
*alphaMode = TEX_ALPHA_MODE_OPAQUE;
}
}
else
@ -187,6 +192,7 @@ namespace
format = _WICToDXGI(g_WICConvert[i].target);
assert(format != DXGI_FORMAT_UNKNOWN);
*alphaMode = g_WICConvert[i].alphaMode;
break;
}
}
@ -288,10 +294,13 @@ namespace
if (FAILED(hr))
return hr;
metadata.format = DetermineFormat(pixelFormat, flags, iswic2, pConvert);
TEX_ALPHA_MODE alphaMode;
metadata.format = DetermineFormat(pixelFormat, flags, iswic2, pConvert, &alphaMode);
if (metadata.format == DXGI_FORMAT_UNKNOWN)
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
metadata.SetAlphaMode(alphaMode);
if (!(flags & WIC_FLAGS_IGNORE_SRGB))
{
GUID containerFormat;

Просмотреть файл

@ -177,6 +177,11 @@ namespace
return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
}
if (static_cast<XG_TILE_MODE>(xboxext->tileMode) == XG_TILE_MODE_INVALID)
{
return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
}
static_assert(static_cast<int>(TEX_MISC2_ALPHA_MODE_MASK) == static_cast<int>(DDS_MISC_FLAGS2_ALPHA_MODE_MASK), "DDS header mismatch");
static_assert(static_cast<int>(TEX_ALPHA_MODE_UNKNOWN) == static_cast<int>(DDS_ALPHA_MODE_UNKNOWN), "DDS header mismatch");

Просмотреть файл

@ -12,7 +12,7 @@
#pragma once
// Off by default warnings
#pragma warning(disable : 4619 4616 4061 4265 4365 4571 4623 4625 4626 4628 4668 4710 4711 4746 4774 4820 4987 5026 5027 5031 5032 5039 5045)
#pragma warning(disable : 4619 4616 4061 4265 4365 4571 4623 4625 4626 4628 4668 4710 4711 4746 4774 4820 4987 5026 5027 5031 5032 5039 5045 26812)
// C4619/4616 #pragma warning warnings
// C4061 enumerator 'X' in switch of enum 'X' is not explicitly handled by a case label
// C4265 class has virtual functions, but destructor is not virtual
@ -34,6 +34,7 @@
// C5031/5032 push/pop mismatches in windows headers
// C5039 pointer or reference to potentially throwing function passed to extern C function under - EHc
// C5045 Spectre mitigation warning
// 26812: The enum type 'x' is unscoped. Prefer 'enum class' over 'enum' (Enum.3).
// Windows 8.1 SDK related Off by default warnings
#pragma warning(disable : 4471 4917 4986 5029)
@ -110,6 +111,7 @@
#include <vector>
#include <time.h>
#include <stdlib.h>
#include <search.h>

Просмотреть файл

@ -3,7 +3,7 @@ DIRECTX TEXTURE LIBRARY (DirectXTex)
Copyright (c) Microsoft Corporation. All rights reserved.
August 21, 2019
October 17, 2019
This package contains DirectXTex, a shared source library for reading and writing DDS
files, and performing various texture content processing operations including
@ -147,6 +147,14 @@ RELEASE NOTES
------------------------------------
RELEASE HISTORY
October 17, 2019
Codec readers updated to return TEX_ALPHA_MODE_OPAQUE if reader returned an alpha channnel due to conversion
Added DDS reader support for 'non-standard' BC6H/BC7 FourCC codes used by nVidia texture tools
TGA codec updated for TGA 2.0
Minor code review
Updated ScreenGrab module
texconv: Added -fixbc4x4switch
August 21, 2019
Updated D3DX12 internal copy to latest version
Added texassemble, texconv, and texdiag to CMake project

Просмотреть файл

@ -265,14 +265,18 @@ HRESULT DirectX::GetMetadataFromEXRFile(const wchar_t* szFile, TexMetadata& meta
#endif
hr = exc.hr();
}
#ifdef _DEBUG
catch (const std::exception& exc)
{
exc;
#ifdef _DEBUG
OutputDebugStringA(exc.what());
#endif
hr = E_FAIL;
}
#else
catch (const std::exception&)
{
hr = E_FAIL;
}
#endif
catch (...)
{
hr = E_UNEXPECTED;
@ -355,14 +359,18 @@ HRESULT DirectX::LoadFromEXRFile(const wchar_t* szFile, TexMetadata* metadata, S
#endif
hr = exc.hr();
}
#ifdef _DEBUG
catch (const std::exception& exc)
{
exc;
#ifdef _DEBUG
OutputDebugStringA(exc.what());
#endif
hr = E_FAIL;
}
#else
catch (const std::exception&)
{
hr = E_FAIL;
}
#endif
catch (...)
{
hr = E_UNEXPECTED;
@ -500,14 +508,18 @@ HRESULT DirectX::SaveToEXRFile(const Image& image, const wchar_t* szFile)
#endif
hr = exc.hr();
}
#ifdef _DEBUG
catch (const std::exception& exc)
{
exc;
#ifdef _DEBUG
OutputDebugStringA(exc.what());
#endif
hr = E_FAIL;
}
#else
catch (const std::exception&)
{
hr = E_FAIL;
}
#endif
catch (...)
{
hr = E_UNEXPECTED;

Разница между файлами не показана из-за своего большого размера Загрузить разницу