mirror of
https://github.com/microsoft/DirectXTex.git
synced 2025-07-09 19:50:13 +02:00
DirectXTex: Added WIC_FLAGS_IGNORE_SRGB to ignore the presense of sRGB metadata in WIC files
This commit is contained in:
parent
5f3b34beb5
commit
8bfc1b7de3
@ -192,6 +192,9 @@ namespace DirectX
|
|||||||
WIC_FLAGS_ALL_FRAMES = 0x10,
|
WIC_FLAGS_ALL_FRAMES = 0x10,
|
||||||
// Loads all images in a multi-frame file, converting/resizing to match the first frame as needed, defaults to 0th frame otherwise
|
// Loads all images in a multi-frame file, converting/resizing to match the first frame as needed, defaults to 0th frame otherwise
|
||||||
|
|
||||||
|
WIC_FLAGS_IGNORE_SRGB = 0x20,
|
||||||
|
// Ignores sRGB metadata if present in the file
|
||||||
|
|
||||||
WIC_FLAGS_DITHER = 0x10000,
|
WIC_FLAGS_DITHER = 0x10000,
|
||||||
// Use ordered 4x4 dithering for any required conversions
|
// Use ordered 4x4 dithering for any required conversions
|
||||||
|
|
||||||
|
@ -272,43 +272,46 @@ static HRESULT _DecodeMetadata( _In_ DWORD flags,
|
|||||||
if ( metadata.format == DXGI_FORMAT_UNKNOWN )
|
if ( metadata.format == DXGI_FORMAT_UNKNOWN )
|
||||||
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
|
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
|
||||||
|
|
||||||
GUID containerFormat;
|
if ( !( flags & WIC_FLAGS_IGNORE_SRGB ) )
|
||||||
hr = decoder->GetContainerFormat( &containerFormat );
|
|
||||||
if ( FAILED(hr) )
|
|
||||||
return hr;
|
|
||||||
|
|
||||||
ScopedObject<IWICMetadataQueryReader> metareader;
|
|
||||||
hr = frame->GetMetadataQueryReader( &metareader );
|
|
||||||
if ( SUCCEEDED(hr) )
|
|
||||||
{
|
{
|
||||||
// Check for sRGB colorspace metadata
|
GUID containerFormat;
|
||||||
bool sRGB = false;
|
hr = decoder->GetContainerFormat( &containerFormat );
|
||||||
|
if ( FAILED(hr) )
|
||||||
|
return hr;
|
||||||
|
|
||||||
PROPVARIANT value;
|
ScopedObject<IWICMetadataQueryReader> metareader;
|
||||||
PropVariantInit( &value );
|
hr = frame->GetMetadataQueryReader( &metareader );
|
||||||
|
if ( SUCCEEDED(hr) )
|
||||||
if ( memcmp( &containerFormat, &GUID_ContainerFormatPng, sizeof(GUID) ) == 0 )
|
|
||||||
{
|
{
|
||||||
// Check for sRGB chunk
|
// Check for sRGB colorspace metadata
|
||||||
if ( SUCCEEDED( metareader->GetMetadataByName( L"/sRGB/RenderingIntent", &value ) ) && value.vt == VT_UI1 )
|
bool sRGB = false;
|
||||||
|
|
||||||
|
PROPVARIANT value;
|
||||||
|
PropVariantInit( &value );
|
||||||
|
|
||||||
|
if ( memcmp( &containerFormat, &GUID_ContainerFormatPng, sizeof(GUID) ) == 0 )
|
||||||
|
{
|
||||||
|
// Check for sRGB chunk
|
||||||
|
if ( SUCCEEDED( metareader->GetMetadataByName( L"/sRGB/RenderingIntent", &value ) ) && value.vt == VT_UI1 )
|
||||||
|
{
|
||||||
|
sRGB = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ( SUCCEEDED( metareader->GetMetadataByName( L"System.Image.ColorSpace", &value ) ) && value.vt == VT_UI2 && value.uiVal == 1 )
|
||||||
{
|
{
|
||||||
sRGB = true;
|
sRGB = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PropVariantClear( &value );
|
||||||
|
|
||||||
|
if ( sRGB )
|
||||||
|
metadata.format = MakeSRGB( metadata.format );
|
||||||
}
|
}
|
||||||
else if ( SUCCEEDED( metareader->GetMetadataByName( L"System.Image.ColorSpace", &value ) ) && value.vt == VT_UI2 && value.uiVal == 1 )
|
else if ( hr == WINCODEC_ERR_UNSUPPORTEDOPERATION )
|
||||||
{
|
{
|
||||||
sRGB = true;
|
// Some formats just don't support metadata (BMP, ICO, etc.), so ignore this failure
|
||||||
|
hr = S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
PropVariantClear( &value );
|
|
||||||
|
|
||||||
if ( sRGB )
|
|
||||||
metadata.format = MakeSRGB( metadata.format );
|
|
||||||
}
|
|
||||||
else if ( hr == WINCODEC_ERR_UNSUPPORTEDOPERATION )
|
|
||||||
{
|
|
||||||
// Some formats just don't support metadata (BMP, ICO, etc.), so ignore this failure
|
|
||||||
hr = S_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return hr;
|
return hr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user