mirror of
https://github.com/microsoft/DirectXTex.git
synced 2026-02-04 12:16:14 +01:00
DDSTextureLoader/WICTextureLoader: Fixed forceSRGB logic (DirectxTK Codeplex issue 851)
Integrated some code review feedback
This commit is contained in:
@@ -508,7 +508,9 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice,
|
||||
size_t rowPitch = ( twidth * bpp + 7 ) / 8;
|
||||
size_t imageSize = rowPitch * theight;
|
||||
|
||||
std::unique_ptr<uint8_t[]> temp( new uint8_t[ imageSize ] );
|
||||
std::unique_ptr<uint8_t[]> temp( new (std::nothrow) uint8_t[ imageSize ] );
|
||||
if (!temp)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
// Load image data
|
||||
if ( memcmp( &convertGUID, &pixelFormat, sizeof(GUID) ) == 0
|
||||
@@ -603,7 +605,7 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice,
|
||||
desc.Height = theight;
|
||||
desc.MipLevels = (autogen) ? 0 : 1;
|
||||
desc.ArraySize = 1;
|
||||
desc.Format = format;
|
||||
desc.Format = (forceSRGB) ? MakeSRGB( format ) : format;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.SampleDesc.Quality = 0;
|
||||
desc.Usage = usage;
|
||||
@@ -633,12 +635,7 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice,
|
||||
{
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc;
|
||||
memset( &SRVDesc, 0, sizeof( SRVDesc ) );
|
||||
if ( forceSRGB )
|
||||
{
|
||||
SRVDesc.Format = MakeSRGB( format );
|
||||
}
|
||||
else
|
||||
SRVDesc.Format = format;
|
||||
SRVDesc.Format = desc.Format;
|
||||
|
||||
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
||||
SRVDesc.Texture2D.MipLevels = (autogen) ? -1 : 1;
|
||||
@@ -701,15 +698,20 @@ HRESULT DirectX::CreateWICTextureFromMemoryEx( ID3D11Device* d3dDevice,
|
||||
ID3D11Resource** texture,
|
||||
ID3D11ShaderResourceView** textureView )
|
||||
{
|
||||
if (!d3dDevice || !wicData || (!texture && !textureView))
|
||||
if ( texture )
|
||||
{
|
||||
return E_INVALIDARG;
|
||||
*texture = nullptr;
|
||||
}
|
||||
if ( textureView )
|
||||
{
|
||||
*textureView = nullptr;
|
||||
}
|
||||
|
||||
if (!d3dDevice || !wicData || (!texture && !textureView))
|
||||
return E_INVALIDARG;
|
||||
|
||||
if ( !wicDataSize )
|
||||
{
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
#ifdef _M_AMD64
|
||||
if ( wicDataSize > 0xFFFFFFFF )
|
||||
@@ -787,10 +789,17 @@ HRESULT DirectX::CreateWICTextureFromFileEx( ID3D11Device* d3dDevice,
|
||||
ID3D11Resource** texture,
|
||||
ID3D11ShaderResourceView** textureView )
|
||||
{
|
||||
if (!d3dDevice || !fileName || (!texture && !textureView))
|
||||
if ( texture )
|
||||
{
|
||||
return E_INVALIDARG;
|
||||
*texture = nullptr;
|
||||
}
|
||||
if ( textureView )
|
||||
{
|
||||
*textureView = nullptr;
|
||||
}
|
||||
|
||||
if (!d3dDevice || !fileName || (!texture && !textureView))
|
||||
return E_INVALIDARG;
|
||||
|
||||
IWICImagingFactory* pWIC = _GetWIC();
|
||||
if ( !pWIC )
|
||||
|
||||
Reference in New Issue
Block a user