Code review feedback

This commit is contained in:
Chuck Walbourn 2016-09-01 01:33:23 -07:00
parent 9da4aec77a
commit 25dbe0e547
13 changed files with 223 additions and 246 deletions

View File

@ -183,10 +183,8 @@ HRESULT GPUCompressBC::Prepare( size_t width, size_t height, DXGI_FORMAT format,
if ( !width || !height || alphaWeight < 0.f )
return E_INVALIDARG;
#ifdef _M_X64
if ( (width > 0xFFFFFFFF) || (height > 0xFFFFFFFF) )
if ( (width > UINT32_MAX) || (height > UINT32_MAX) )
return E_INVALIDARG;
#endif
m_width = width;
m_height = height;

View File

@ -4531,10 +4531,8 @@ HRESULT Convert( const Image& srcImage, DXGI_FORMAT format, DWORD filter, float
|| IsTypeless(srcImage.format) || IsTypeless(format) )
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
#ifdef _M_X64
if ( (srcImage.width > 0xFFFFFFFF) || (srcImage.height > 0xFFFFFFFF) )
if ( (srcImage.width > UINT32_MAX) || (srcImage.height > UINT32_MAX) )
return E_INVALIDARG;
#endif
HRESULT hr = image.Initialize2D( format, srcImage.width, srcImage.height, 1, 1 );
if ( FAILED(hr) )
@ -4583,10 +4581,8 @@ HRESULT Convert( const Image* srcImages, size_t nimages, const TexMetadata& meta
|| IsTypeless(metadata.format) || IsTypeless(format) )
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
#ifdef _M_X64
if ( (metadata.width > 0xFFFFFFFF) || (metadata.height > 0xFFFFFFFF) )
if ( (metadata.width > UINT32_MAX) || (metadata.height > UINT32_MAX) )
return E_INVALIDARG;
#endif
TexMetadata mdata2 = metadata;
mdata2.format = format;
@ -4623,10 +4619,8 @@ HRESULT Convert( const Image* srcImages, size_t nimages, const TexMetadata& meta
return E_FAIL;
}
#ifdef _M_X64
if ( (src.width > 0xFFFFFFFF) || (src.height > 0xFFFFFFFF) )
if ( (src.width > UINT32_MAX) || (src.height > UINT32_MAX) )
return E_FAIL;
#endif
const Image& dst = dest[ index ];
assert( dst.format == format );
@ -4672,10 +4666,8 @@ HRESULT Convert( const Image* srcImages, size_t nimages, const TexMetadata& meta
return E_FAIL;
}
#ifdef _M_X64
if ( (src.width > 0xFFFFFFFF) || (src.height > 0xFFFFFFFF) )
if ( (src.width > UINT32_MAX) || (src.height > UINT32_MAX) )
return E_FAIL;
#endif
const Image& dst = dest[ index ];
assert( dst.format == format );
@ -4732,10 +4724,8 @@ HRESULT ConvertToSinglePlane( const Image& srcImage, ScratchImage& image )
if ( format == DXGI_FORMAT_UNKNOWN )
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
#ifdef _M_X64
if ( (srcImage.width > 0xFFFFFFFF) || (srcImage.height > 0xFFFFFFFF) )
if ( (srcImage.width > UINT32_MAX) || (srcImage.height > UINT32_MAX) )
return E_INVALIDARG;
#endif
HRESULT hr = image.Initialize2D( format, srcImage.width, srcImage.height, 1, 1 );
if ( FAILED(hr) )
@ -4779,10 +4769,8 @@ HRESULT ConvertToSinglePlane( const Image* srcImages, size_t nimages, const TexM
if ( format == DXGI_FORMAT_UNKNOWN )
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
#ifdef _M_X64
if ( (metadata.width > 0xFFFFFFFF) || (metadata.height > 0xFFFFFFFF) )
if ( (metadata.width > UINT32_MAX) || (metadata.height > UINT32_MAX) )
return E_INVALIDARG;
#endif
TexMetadata mdata2 = metadata;
mdata2.format = format;
@ -4812,10 +4800,8 @@ HRESULT ConvertToSinglePlane( const Image* srcImages, size_t nimages, const TexM
return E_FAIL;
}
#ifdef _M_X64
if ( (src.width > 0xFFFFFFFF) || (src.height > 0xFFFFFFFF) )
if ( (src.width > UINT32_MAX) || (src.height > UINT32_MAX) )
return E_FAIL;
#endif
const Image& dst = dest[ index ];
assert( dst.format == format );

View File

@ -405,11 +405,9 @@ HRESULT CreateTextureEx( ID3D11Device* pDevice, const Image* srcImages, size_t n
if ( !metadata.mipLevels || !metadata.arraySize )
return E_INVALIDARG;
#ifdef _M_X64
if ( (metadata.width > 0xFFFFFFFF) || (metadata.height > 0xFFFFFFFF)
|| (metadata.mipLevels > 0xFFFFFFFF) || (metadata.arraySize > 0xFFFFFFFF) )
if ( (metadata.width > UINT32_MAX) || (metadata.height > UINT32_MAX)
|| (metadata.mipLevels > UINT32_MAX) || (metadata.arraySize > UINT32_MAX) )
return E_INVALIDARG;
#endif
std::unique_ptr<D3D11_SUBRESOURCE_DATA[]> initData( new (std::nothrow) D3D11_SUBRESOURCE_DATA[ metadata.mipLevels * metadata.arraySize ] );
if ( !initData )
@ -422,10 +420,8 @@ HRESULT CreateTextureEx( ID3D11Device* pDevice, const Image* srcImages, size_t n
if ( !metadata.depth )
return E_INVALIDARG;
#ifdef _M_X64
if ( metadata.depth > 0xFFFFFFFF )
if ( metadata.depth > UINT32_MAX )
return E_INVALIDARG;
#endif
if ( metadata.arraySize > 1 )
// Direct3D 11 doesn't support arrays of 3D textures

View File

@ -575,10 +575,8 @@ HRESULT _EncodeDDSHeader( const TexMetadata& metadata, DWORD flags,
{
header->dwFlags |= DDS_HEADER_FLAGS_MIPMAP;
#ifdef _M_X64
if ( metadata.mipLevels > 0xFFFFFFFF )
if ( metadata.mipLevels > UINT32_MAX )
return E_INVALIDARG;
#endif
header->dwMipMapCount = static_cast<uint32_t>( metadata.mipLevels );
@ -589,21 +587,17 @@ HRESULT _EncodeDDSHeader( const TexMetadata& metadata, DWORD flags,
switch( metadata.dimension )
{
case TEX_DIMENSION_TEXTURE1D:
#ifdef _M_X64
if ( metadata.width > 0xFFFFFFFF )
if ( metadata.width > UINT32_MAX )
return E_INVALIDARG;
#endif
header->dwWidth = static_cast<uint32_t>( metadata.width );
header->dwHeight = header->dwDepth = 1;
break;
case TEX_DIMENSION_TEXTURE2D:
#ifdef _M_X64
if ( metadata.height > 0xFFFFFFFF
|| metadata.width > 0xFFFFFFFF)
if ( metadata.height > UINT32_MAX
|| metadata.width > UINT32_MAX )
return E_INVALIDARG;
#endif
header->dwHeight = static_cast<uint32_t>( metadata.height );
header->dwWidth = static_cast<uint32_t>( metadata.width );
@ -617,12 +611,10 @@ HRESULT _EncodeDDSHeader( const TexMetadata& metadata, DWORD flags,
break;
case TEX_DIMENSION_TEXTURE3D:
#ifdef _M_X64
if ( metadata.height > 0xFFFFFFFF
|| metadata.width > 0xFFFFFFFF
|| metadata.depth > 0xFFFFFFFF )
if ( metadata.height > UINT32_MAX
|| metadata.width > UINT32_MAX
|| metadata.depth > UINT32_MAX )
return E_INVALIDARG;
#endif
header->dwFlags |= DDS_HEADER_FLAGS_VOLUME;
header->dwCaps2 |= DDS_FLAGS_VOLUME;
@ -638,11 +630,9 @@ HRESULT _EncodeDDSHeader( const TexMetadata& metadata, DWORD flags,
size_t rowPitch, slicePitch;
ComputePitch( metadata.format, metadata.width, metadata.height, rowPitch, slicePitch, CP_FLAGS_NONE );
#ifdef _M_X64
if ( slicePitch > 0xFFFFFFFF
|| rowPitch > 0xFFFFFFFF )
if ( slicePitch > UINT32_MAX
|| rowPitch > UINT32_MAX )
return E_FAIL;
#endif
if ( IsCompressed( metadata.format ) )
{
@ -666,10 +656,8 @@ HRESULT _EncodeDDSHeader( const TexMetadata& metadata, DWORD flags,
ext->dxgiFormat = metadata.format;
ext->resourceDimension = metadata.dimension;
#ifdef _M_X64
if ( metadata.arraySize > 0xFFFFFFFF )
if ( metadata.arraySize > UINT32_MAX )
return E_INVALIDARG;
#endif
static_assert( TEX_MISC_TEXTURECUBE == DDS_RESOURCE_MISC_TEXTURECUBE, "DDS header mismatch");

View File

@ -138,10 +138,8 @@ HRESULT FlipRotate( const Image& srcImage, DWORD flags, ScratchImage& image )
if ( !flags )
return E_INVALIDARG;
#ifdef _M_X64
if ( (srcImage.width > 0xFFFFFFFF) || (srcImage.height > 0xFFFFFFFF) )
if ( (srcImage.width > UINT32_MAX) || (srcImage.height > UINT32_MAX) )
return E_INVALIDARG;
#endif
if ( IsCompressed( srcImage.format ) )
{
@ -283,10 +281,8 @@ HRESULT FlipRotate( const Image* srcImages, size_t nimages, const TexMetadata& m
return E_FAIL;
}
#ifdef _M_X64
if ( (src.width > 0xFFFFFFFF) || (src.height > 0xFFFFFFFF) )
if ( (src.width > UINT32_MAX) || (src.height > UINT32_MAX) )
return E_FAIL;
#endif
const Image& dst = dest[ index ];
assert( dst.format == metadata.format );

View File

@ -120,10 +120,8 @@ HRESULT PremultiplyAlpha( const Image& srcImage, DWORD flags, ScratchImage& imag
|| !HasAlpha(srcImage.format) )
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
#ifdef _M_X64
if ( (srcImage.width > 0xFFFFFFFF) || (srcImage.height > 0xFFFFFFFF) )
if ( (srcImage.width > UINT32_MAX) || (srcImage.height > UINT32_MAX) )
return E_INVALIDARG;
#endif
HRESULT hr = image.Initialize2D( srcImage.format, srcImage.width, srcImage.height, 1, 1 );
if ( FAILED(hr) )
@ -163,10 +161,8 @@ HRESULT PremultiplyAlpha( const Image* srcImages, size_t nimages, const TexMetad
|| !HasAlpha(metadata.format) )
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
#ifdef _M_X64
if ( (metadata.width > 0xFFFFFFFF) || (metadata.height > 0xFFFFFFFF) )
if ( (metadata.width > UINT32_MAX) || (metadata.height > UINT32_MAX) )
return E_INVALIDARG;
#endif
if ( metadata.IsPMAlpha() )
{
@ -202,10 +198,9 @@ HRESULT PremultiplyAlpha( const Image* srcImages, size_t nimages, const TexMetad
return E_FAIL;
}
#ifdef _M_X64
if ( (src.width > 0xFFFFFFFF) || (src.height > 0xFFFFFFFF) )
if ( (src.width > UINT32_MAX) || (src.height > UINT32_MAX) )
return E_FAIL;
#endif
const Image& dst = dest[ index ];
assert( dst.format == metadata.format );

View File

@ -833,13 +833,11 @@ HRESULT Resize( const Image& srcImage, size_t width, size_t height, DWORD filter
if ( width == 0 || height == 0 )
return E_INVALIDARG;
#ifdef _M_X64
if ( (srcImage.width > 0xFFFFFFFF) || (srcImage.height > 0xFFFFFFFF) )
if ( (srcImage.width > UINT32_MAX) || (srcImage.height > UINT32_MAX) )
return E_INVALIDARG;
if ( (width > 0xFFFFFFFF) || (height > 0xFFFFFFFF) )
if ( (width > UINT32_MAX) || (height > UINT32_MAX) )
return E_INVALIDARG;
#endif
if ( !srcImage.pixels )
return E_POINTER;
@ -897,10 +895,8 @@ HRESULT Resize( const Image* srcImages, size_t nimages, const TexMetadata& metad
if ( !srcImages || !nimages || width == 0 || height == 0 )
return E_INVALIDARG;
#ifdef _M_X64
if ( (width > 0xFFFFFFFF) || (height > 0xFFFFFFFF) )
if ( (width > UINT32_MAX) || (height > UINT32_MAX) )
return E_INVALIDARG;
#endif
TexMetadata mdata2 = metadata;
mdata2.width = width;
@ -944,13 +940,11 @@ HRESULT Resize( const Image* srcImages, size_t nimages, const TexMetadata& metad
return E_FAIL;
}
#ifdef _M_X64
if ( (srcimg->width > 0xFFFFFFFF) || (srcimg->height > 0xFFFFFFFF) )
if ( (srcimg->width > UINT32_MAX) || (srcimg->height > UINT32_MAX) )
{
result.Release();
return E_FAIL;
}
#endif
if ( usewic )
{
@ -1005,13 +999,11 @@ HRESULT Resize( const Image* srcImages, size_t nimages, const TexMetadata& metad
return E_FAIL;
}
#ifdef _M_X64
if ( (srcimg->width > 0xFFFFFFFF) || (srcimg->height > 0xFFFFFFFF) )
if ( (srcimg->width > UINT32_MAX) || (srcimg->height > UINT32_MAX) )
{
result.Release();
return E_FAIL;
}
#endif
if ( usewic )
{

View File

@ -237,53 +237,59 @@ IWICImagingFactory* GetWICFactory(bool& iswic2)
return g_Factory;
}
static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT;
InitOnceExecuteOnce(&s_initOnce,
[](PINIT_ONCE, PVOID, PVOID *) -> BOOL
{
#if(_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory2,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory2),
(LPVOID*)&g_Factory
);
if (SUCCEEDED(hr))
{
// WIC2 is available on Windows 8 and Windows 7 SP1 with KB 2670838 installed
g_WIC2 = true;
}
else
{
g_WIC2 = false;
hr = CoCreateInstance(
CLSID_WICImagingFactory1,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&g_Factory)
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory2,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory2),
(LPVOID*)&g_Factory
);
if (FAILED(hr))
{
g_Factory = nullptr;
return nullptr;
}
}
if (SUCCEEDED(hr))
{
// WIC2 is available on Windows 8 and Windows 7 SP1 with KB 2670838 installed
g_WIC2 = true;
}
else
{
g_WIC2 = false;
hr = CoCreateInstance(
CLSID_WICImagingFactory1,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&g_Factory)
);
if (FAILED(hr))
{
g_Factory = nullptr;
return FALSE;
}
}
#else
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&g_Factory)
);
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&g_Factory)
);
g_WIC2 = false;
g_WIC2 = false;
if (FAILED(hr))
{
g_Factory = nullptr;
return nullptr;
}
if (FAILED(hr))
{
g_Factory = nullptr;
return FALSE;
}
#endif
return TRUE;
}, nullptr, nullptr);
iswic2 = g_WIC2;
return g_Factory;

View File

@ -645,10 +645,8 @@ static HRESULT _EncodeImage( _In_ const Image& image, _In_ DWORD flags, _In_ REF
if ( FAILED(hr) )
return hr;
#ifdef _M_X64
if ( (image.width > 0xFFFFFFFF) || (image.height > 0xFFFFFFFF) )
if ( (image.width > UINT32_MAX) || (image.height > UINT32_MAX) )
return E_INVALIDARG;
#endif
hr = frame->SetSize( static_cast<UINT>( image.width ), static_cast<UINT>( image.height ) );
if ( FAILED(hr) )
@ -862,10 +860,8 @@ HRESULT GetMetadataFromWICMemory( LPCVOID pSource, size_t size, DWORD flags, Tex
if ( !pSource || size == 0 )
return E_INVALIDARG;
#ifdef _M_X64
if ( size > 0xFFFFFFFF )
if ( size > UINT32_MAX )
return HRESULT_FROM_WIN32( ERROR_FILE_TOO_LARGE );
#endif
bool iswic2 = false;
IWICImagingFactory* pWIC = GetWICFactory(iswic2);
@ -946,10 +942,8 @@ HRESULT LoadFromWICMemory( LPCVOID pSource, size_t size, DWORD flags, TexMetadat
if ( !pSource || size == 0 )
return E_INVALIDARG;
#ifdef _M_X64
if ( size > 0xFFFFFFFF )
if ( size > UINT32_MAX )
return HRESULT_FROM_WIN32( ERROR_FILE_TOO_LARGE );
#endif
bool iswic2 = false;
IWICImagingFactory* pWIC = GetWICFactory(iswic2);

View File

@ -706,49 +706,56 @@ namespace
if ( s_Factory )
return s_Factory;
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory2,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory2),
(LPVOID*)&s_Factory
);
static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT;
if ( SUCCEEDED(hr) )
{
// WIC2 is available on Windows 8 and Windows 7 SP1 with KB 2670838 installed
g_WIC2 = true;
}
else
{
hr = CoCreateInstance(
CLSID_WICImagingFactory1,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&s_Factory)
);
if ( FAILED(hr) )
InitOnceExecuteOnce(&s_initOnce,
[](PINIT_ONCE, PVOID, PVOID *) -> BOOL
{
s_Factory = nullptr;
return nullptr;
}
}
#else
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&s_Factory)
);
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory2,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory2),
(LPVOID*)&s_Factory
);
if ( FAILED(hr) )
{
s_Factory = nullptr;
return nullptr;
}
#endif
if ( SUCCEEDED(hr) )
{
// WIC2 is available on Windows 10, Windows 8.x, and Windows 7 SP1 with KB 2670838 installed
g_WIC2 = true;
}
else
{
hr = CoCreateInstance(
CLSID_WICImagingFactory1,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&s_Factory)
);
if ( FAILED(hr) )
{
s_Factory = nullptr;
return FALSE;
}
}
#else
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&s_Factory)
);
if ( FAILED(hr) )
{
s_Factory = nullptr;
return FALSE;
}
#endif
return TRUE;
}, nullptr, nullptr);
return s_Factory;
}

View File

@ -786,16 +786,24 @@ namespace
if (s_Factory)
return s_Factory;
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory2,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&s_Factory));
if (FAILED(hr))
{
s_Factory = nullptr;
return nullptr;
}
static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT;
InitOnceExecuteOnce(&s_initOnce,
[](PINIT_ONCE, PVOID, PVOID *) -> BOOL
{
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory2,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&s_Factory));
if (FAILED(hr))
{
s_Factory = nullptr;
return FALSE;
}
return TRUE;
}, nullptr, nullptr);
return s_Factory;
}
} // anonymous namespace

View File

@ -68,7 +68,7 @@ namespace
DXGI_FORMAT format;
};
const WICTranslate g_WICFormats[] =
const WICTranslate g_WICFormats[] =
{
{ GUID_WICPixelFormat128bppRGBAFloat, DXGI_FORMAT_R32G32B32A32_FLOAT },
@ -103,7 +103,7 @@ namespace
GUID target;
};
const WICConvert g_WICConvert[] =
const WICConvert g_WICConvert[] =
{
// Note target GUID in this conversion table must be one of those directly supported formats (above).
@ -154,11 +154,11 @@ namespace
{ GUID_WICPixelFormat40bppCMYKAlpha, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
{ GUID_WICPixelFormat80bppCMYKAlpha, GUID_WICPixelFormat64bppRGBA }, // DXGI_FORMAT_R16G16B16A16_UNORM
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
#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
#endif
#endif
// We don't support n-channel formats
};
@ -173,49 +173,56 @@ namespace
if ( s_Factory )
return s_Factory;
#if(_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory2,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory2),
(LPVOID*)&s_Factory
);
static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT;
if ( SUCCEEDED(hr) )
{
// WIC2 is available on Windows 8 and Windows 7 SP1 with KB 2670838 installed
g_WIC2 = true;
}
else
{
hr = CoCreateInstance(
CLSID_WICImagingFactory1,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&s_Factory)
);
if ( FAILED(hr) )
InitOnceExecuteOnce(&s_initOnce,
[](PINIT_ONCE, PVOID, PVOID *) -> BOOL
{
s_Factory = nullptr;
return nullptr;
}
}
#else
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&s_Factory)
);
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory2,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory2),
(LPVOID*)&s_Factory
);
if ( FAILED(hr) )
{
s_Factory = nullptr;
return nullptr;
}
#endif
if ( SUCCEEDED(hr) )
{
// WIC2 is available on Windows 10, Windows 8.x, and Windows 7 SP1 with KB 2670838 installed
g_WIC2 = true;
}
else
{
hr = CoCreateInstance(
CLSID_WICImagingFactory1,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&s_Factory)
);
if ( FAILED(hr) )
{
s_Factory = nullptr;
return FALSE;
}
}
#else
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&s_Factory)
);
if ( FAILED(hr) )
{
s_Factory = nullptr;
return FALSE;
}
#endif
return TRUE;
}, nullptr, nullptr);
return s_Factory;
}
@ -229,13 +236,13 @@ namespace
return g_WICFormats[i].format;
}
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
if ( g_WIC2 )
{
if ( memcmp( &GUID_WICPixelFormat96bppRGBFloat, &guid, sizeof(GUID) ) == 0 )
return DXGI_FORMAT_R32G32B32_FLOAT;
}
#endif
#endif
return DXGI_FORMAT_UNKNOWN;
}
@ -391,14 +398,14 @@ namespace
{
if ( memcmp( &GUID_WICPixelFormat96bppRGBFixedPoint, &pixelFormat, sizeof(WICPixelFormatGUID) ) == 0 )
{
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
if ( g_WIC2 )
{
memcpy( &convertGUID, &GUID_WICPixelFormat96bppRGBFloat, sizeof(WICPixelFormatGUID) );
format = DXGI_FORMAT_R32G32B32_FLOAT;
}
else
#endif
#endif
{
memcpy( &convertGUID, &GUID_WICPixelFormat128bppRGBAFloat, sizeof(WICPixelFormatGUID) );
format = DXGI_FORMAT_R32G32B32A32_FLOAT;
@ -428,7 +435,7 @@ namespace
bpp = _WICBitsPerPixel( pixelFormat );
}
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
if ( (format == DXGI_FORMAT_R32G32B32_FLOAT) && d3dContext != 0 && textureView != 0 )
{
// Special case test for optional device support for autogen mipchains for R32G32B32_FLOAT
@ -442,7 +449,7 @@ namespace
bpp = 128;
}
}
#endif
#endif
if ( !bpp )
return E_FAIL;
@ -753,10 +760,8 @@ HRESULT DirectX::CreateWICTextureFromMemoryEx( ID3D11Device* d3dDevice,
if ( !wicDataSize )
return E_FAIL;
#ifdef _M_AMD64
if ( wicDataSize > 0xFFFFFFFF )
if ( wicDataSize > UINT32_MAX )
return HRESULT_FROM_WIN32( ERROR_FILE_TOO_LARGE );
#endif
IWICImagingFactory* pWIC = _GetWIC();
if ( !pWIC )

View File

@ -154,16 +154,24 @@ namespace
if (s_Factory)
return s_Factory;
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory2,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&s_Factory));
if (FAILED(hr))
{
s_Factory = nullptr;
return nullptr;
}
static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT;
InitOnceExecuteOnce(&s_initOnce,
[](PINIT_ONCE, PVOID, PVOID *) -> BOOL
{
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory2,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&s_Factory));
if (FAILED(hr))
{
s_Factory = nullptr;
return FALSE;
}
return TRUE;
}, nullptr, nullptr);
return s_Factory;
}
@ -581,10 +589,8 @@ HRESULT DirectX::LoadWICTextureFromMemoryEx(
if ( !wicDataSize )
return E_FAIL;
#ifdef _M_AMD64
if ( wicDataSize > 0xFFFFFFFF )
if ( wicDataSize > UINT32_MAX )
return HRESULT_FROM_WIN32( ERROR_FILE_TOO_LARGE );
#endif
auto pWIC = _GetWIC();
if ( !pWIC )